How To: Linux / Unix Move Directory Up One Level

I would like to move a directory one level up into the root directory. I have all my html files located in /home/apache2/www/html directory, and I would like to move /home/apache2/www/html to one level up at /home/apache2/www/. How can I accomplish this over the ssh session?

You need to use the mv command that moves one or more files or directories from one place to another. You must have have write permission for the directories which the file will move between. The syntax is as follows to move /home/apache2/www/html directory up one level at /home/apache2/www/ directory.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix CLI
Est. reading time 1m

Linux / Unix Move Directory Up One Level with the mv Command

Open a command-line terminal (select Applications > Accessories > Terminal), and then type (for remote system use ssh for login):
$ mv /home/apache2/www/html/ /home/apache2/www/
$ mv /home/apache2/www/html/ ..
Please note that Unix / Linux uses the special name .. to refer to the parent directory of a particular directory.

Linux / Unix Move Directory Up One Level Examples

In this example move /usb/archives/data/ directory to up one level using the mv command as follows:
$ cd /usb/archives/data/
$ mv -v data/ ..

Sample outputs:

Fig.01: mv Unix / Linux Command

Fig.01: mv Unix / Linux Command


  • -v : Cause mv to be verbose, showing files after they are moved.

How Do I Move Multiple Directories Up One Level?

The syntax is as follows to moves each file named by a source operand to a destination file in the existing directory named by the directory operand:
$ mv dir1 dir2 ..
In this example move both /home/vivek/projects/foo/ /home/vivek/projects/bar/ directories up one level:
$ mv /home/vivek/projects/foo /home/vivek/projects/bar ..
Now both bar and foo moved to the /home/vivek/projects/ directory. You can move files using the same syntax. In this example move movie-cd1.avi movie-cd2.avi files up one level:
$ mv /home/vivek/Downloads/movie-cd1.avi /home/vivek/Downloads/movie-cd2.avi ..

How Do I Move All Directories Up One Level?

Use the following syntax to move all directories and files in /home/vivek/data/sales/ to /home/vivek/data/:
$ mv -v /home/vivek/data/sales/ ..
$ cd /home/vivek/data/sales/
$ mv -v sales/ ..

How Do I Move All *.pl or *.c Files Up One Level?

Use the following syntax to move all *.pl (perl files) or *.c (C program files) up one level:
$ mv -v /home/vivek/projects/*.pl ..
$ mv -v /home/vivek/projects/*.c ..


You just learned how to move directory directory up one level using the mv command. For more info read the mv command man page by typing the following man command:
$ man mv

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • normutt Oct 4, 2013 @ 16:26

    Thanks again for on-spot help when I needed it!

  • Rafal Dec 25, 2014 @ 3:24

    Hi, I think these lines:

    $ cd /usb/archives/data/
    $ mv -v data/ ..

    should be changed to:

    $ cd /usb/archives/
    $ mv -v data/ ..

    and these lines:

    $ cd /home/vivek/data/sales/
    $ mv -v sales/ ..


    $ cd /home/vivek/data/
    $ mv -v sales/ ..


  • Rob Sep 1, 2017 @ 7:40

    Corollary: if it happens that your directory has the same name as its parent directory, an error is raised when mv dir/ .. is executed.
    In this case, a simple prior directory rename step is necessary. After the real move operation, the name can be restored again.

    This situation typically occurs when you copy a directory from elswhere accidentally one level lower than an existing target directory with the same name.

  • Tikyda Nov 26, 2017 @ 21:53

    Thanks a lot for sharing this information.

  • Jeronym K Jan 18, 2021 @ 9:14

    I needed to write into existing directories without overwriting existing

    target="." # this makes ../
    while read -r -u12  filename; do
            echo mkdir "$target$(dirname $filename)/"
            echo mv -b "$filename" "$target$(dirname $filename)/"
    done 12<<< $(find . -type f)

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum