Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Linux (Ubuntu), how do you move all the files and directories to the parent directory?

share|improve this question
add comment

7 Answers

up vote 15 down vote accepted
find . -maxdepth 1 -exec mv {} .. \;

this will move hidden files as well.

You will get the message:

mv: cannot move `.' to `../.': Device or resource busy

when it tries to move . (current directory) but that won't cause any harm.

share|improve this answer
    
It will move all files from all subdirectories to the parent of the current directory, too. I'd use -maxdepth 1 to be sure. –  ℝaphink Dec 27 '09 at 17:36
    
it says find: missing argument to `-exec' –  nekbaba Dec 27 '09 at 17:37
    
@raphink, good call! sorry about that,try now :) –  John T Dec 27 '09 at 17:37
    
Now it says: mv: cannot move ./scripts' to ../scripts': Directory not empty –  nekbaba Dec 27 '09 at 17:43
1  
You must have a directory called scripts in your parent directory AND in your current directory. You will have to rename this one before you move it. –  ℝaphink Dec 27 '09 at 17:44
add comment

Type this in the shell:

mv *.* ..

That moves ALL the files one level up.

The character * is a wildcard. So *.deb will move all the .deb files, and for example Zeitgeist.* will move Zeitgeist.avi and Zeitgeist.srt one folder up.

And, of course, .. indicates the parent directory.

share|improve this answer
1  
this didn't work with the dirs! or the hidden files –  nekbaba Dec 27 '09 at 17:34
    
It works with dirs, at least for me. –  maaartinus Jan 25 '11 at 21:21
    
You want * not *.* to include directories –  Chris S Apr 19 '13 at 19:58
add comment

Assuming all your hidden files begin with dot followed by a letter or a number (which they should), you could use

mv * .[A-Za-z0-9]* ..

The .[A-Za-z0-9]* part is to make sure you don't try to move . or .. along, which would fail.

share|improve this answer
add comment

In bash you can use shopt -s dotglob to make * match all files and move them simply by

shopt -s dotglob; mv * ..

This is not the best solution since the setting is permanent for the shell until you change it by

shopt -u dotglob

but I think it's good to know.

share|improve this answer
1  
Call it in a subshell: (shopt -s dotglob && mv * ..). That way, the option is only local to that subshell. –  queueoverflow Jan 26 '13 at 20:25
add comment

It's simple to move all files and folders to the parent directory in Linux.

Go to that folder and use this command:

mv * /the full path

For example, if your files and folders are as follows:

/home/abcuser/test/1.txt 
                   2.txt
                   3.jpg
                   4.php
                   1folder
                   2folder

Go to that folder via cd:

cd /home/abcuser/test
mv * /home/abcuser

All your files and folders will move to the abcuser folder (parent directory).

share|improve this answer
2  
Thanks @Gareth, was about to the same. Abhishek, please don't post any unrelated links, where's the sense in that? Also, check your formatting please. Additionally, /the full path does not work in Linux, you have to escape spaces with /the\ full\ path. –  slhck Nov 3 '11 at 11:47
add comment

A method which causes no errors and works every time:

ls -1A . | while read -r file                                                    
do                                                                                  
    mv "./${file}" ..                                                            
done
share|improve this answer
add comment

I came here because I'm new to this subject as well. For some reason the above didn't do the trick for me. What I did to move all files from a dir to its parent dir was:

cd to/the/dir
mv * ../
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.