≡ Menu

HowTo: Linux / Unix Move Directory Up One Level

I would like to move a directory one level up into the root directory. I’ve all html files located in /home/apache2/www/html directory, and I’d 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 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. 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. 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 ..
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 ..

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 2 comments… add one }
  • normutt October 4, 2013, 4:26 pm

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

  • Rafal December 25, 2014, 3:24 am

    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/ ..


Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , , , , ,