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

290,507

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 *

Share:
290,507

Related videos on Youtube

slhck
Author by

slhck

Updated on September 17, 2022

Comments

  • slhck
    slhck over 1 year

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

  • Dwayne
    Dwayne over 14 years
    this didn't work with the dirs! or the hidden files
  • ya-ivanov
    ya-ivanov over 14 years
    It will move all files from all subdirectories to the parent of the current directory, too. I'd use -maxdepth 1 to be sure.
  • sharmajee499
    sharmajee499 over 14 years
    Now it says: mv: cannot move ./scripts' to ../scripts': Directory not empty
  • ya-ivanov
    ya-ivanov over 14 years
    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.
  • slhck
    slhck over 12 years
    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.
  • Chris S
    Chris S about 11 years
    You want * not *.* to include directories
  • Wavesailor
    Wavesailor over 8 years
    This does not move hidden file though
  • crafter
    crafter about 8 years
    It 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
    DavidPostill about 8 years
    Welcome 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
    BlackBurn027 over 7 years
    Its a nice documentary
  • Daniel Howard
    Daniel Howard over 6 years
    Good answer - it's simple, includes hidden files and doesn't cause an error about copying '.' and '..'
  • Gelldur
    Gelldur over 6 years
    1 liner: (cd ${ANDROID_NDK_HOME}/android-ndk-r14b/ && mv * ../)
  • Scott - Слава Україні
    Scott - Слава Україні over 5 years
    Thanks for contributing an answer. While this might work in simple scenarios, piping find into while read is a bad way to use find, and better answers have already been posted.
  • Lily
    Lily almost 4 years
    you save my day.Thanks
  • Adam Ryczkowski
    Adam Ryczkowski over 3 years
    I 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
    deed02392 over 2 years
    Is this for GNU find?
  • Martin Thoma
    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