Skip to main content

Move files and folders to parent directory

Code Snippets

The following command will move all files & directories, including hidden files in the current directory to the parent directory.

For example. If you are in /home/user/test and you run this command, it will move all files and directories in /home/user/test to /home/user

bash
find . -maxdepth 1 -exec mv {} .. \;

It will throw an error when it tries to move . (current directory) but this will not be an issue:

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

Example

Execute

bash
$ find . -maxdepth 1 -exec mv {} .. \;
mv: cannot move '.' to '../.': Device or resource busy
$ cd ..
BeforeAfter
bash
$ pwd
/home/aiden/tmp/subfolder
$ tree
.
├── file3
└── folder1
├── file1
└── folder2
└── file2

3 directories, 3 files
bash
$ pwd 
/home/aiden/tmp
$ tree
.
├── file3
├── folder1
│   ├── file1
│   └── folder2
│   └── file2
└── subfolder

5 directories, 2 files