How do I move files and directories to the parent folder in Linux?

Solution 1:

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.

Solution 2:

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

Solution 3:

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 Zeitgeist.* will move Zeitgeist.avi and Zeitgeist.srt one folder up, since, of course, .. indicates the parent directory.

To move everything including folders, etc, just use * instead of *.*

Solution 4:

It can't be more simple than:

mv * ../

To also move hidden files:

mv /path/subfolder/{.,}* /path/ 

mv is a command to move files, * means all files and folders and ../ is the path to the parent directory.

Solution 5:

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.