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
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 4
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 5
There is no need to change directories. Just include * at the end of path:
mv /my/folder/child/* /my/folder/
Above only moves non hidden files. To move only hidden files use .*
mv /my/folder/child/.* /my/folder/
Above two can be combined in to one command:
mv /my/folder/child/{.,}* /my/folder/
Also see: How to move all files including hidden files into parent directory via *
Related videos on Youtube
slhck
Updated on September 17, 2022Comments
-
slhck over 1 year
In Linux (Ubuntu), how do you move all the files and directories to the parent directory?
-
Admin over 5 yearsthe question with by far the most complete answer i found: unix.stackexchange.com/q/6393/93768
-
-
Dwayne over 14 yearsthis didn't work with the dirs! or the hidden files
-
ya-ivanov over 14 yearsIt will move all files from all subdirectories to the parent of the current directory, too. I'd use
-maxdepth 1
to be sure. -
sharmajee499 over 14 yearsNow it says: mv: cannot move
./scripts' to
../scripts': Directory not empty -
ya-ivanov over 14 yearsYou 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.
-
slhck over 12 yearsThanks @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
. -
Chris S about 11 yearsYou want
*
not*.*
to include directories -
Wavesailor over 8 yearsThis does not move hidden file though
-
crafter about 8 yearsIt worked but you left one one very important bit of information - you must run this from the subdirectory. Also this will not delete the subdirectory itself so you must back up one directory and do a rmdir on the subdirectory.
-
DavidPostill about 8 yearsWelcome to Super User! This duplicates another answer and adds no new content. Please don't post an answer unless you actually have something new to contribute.
-
BlackBurn027 over 7 yearsIts a nice documentary
-
Daniel Howard over 6 yearsGood answer - it's simple, includes hidden files and doesn't cause an error about copying '.' and '..'
-
Gelldur over 6 years1 liner:
(cd ${ANDROID_NDK_HOME}/android-ndk-r14b/ && mv * ../)
-
Scott - Слава Україні over 5 yearsThanks for contributing an answer. While this might work in simple scenarios, piping
find
intowhile read
is a bad way to usefind
, and better answers have already been posted. -
Lily almost 4 yearsyou save my day.Thanks
-
Adam Ryczkowski over 3 yearsI found this superior:
find . -mindepth 1 -maxdepth 1 -exec mv -t .. -- {} +
(taken from unix.stackexchange.com/q/6393/93768). No error messages and actually working in my bash script. -
deed02392 over 2 yearsIs this for GNU find?
-
Martin Thoma over 2 years
zsh: argument list too long: mv
;bash: /usr/bin/mv: Argument list too long
. Aparently it doesn't work for 80k files