Development

Quick Tip - How to recursively move files and directories to the parent folder in Linux

Umur Alpay
07 April 2023

Let's say you want to move the contents of the child folder to the parent folder in a folder structure like /var/www/parent-folder/child-folder. First, you need to cd to that directory and then type

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

This code block will move the contents, including the hidden files of the child folder, to the parent folder and leave the child folder empty. As a result, you will get a message like this.

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

Bonus tip:

If you remove "-maxdepth 1" from the command, it will move all files from all subdirectories to the parent of the current directory.


Follow me on Instagram, Facebook, or Twitter if you like to keep posted about tutorials, tips, and experiences from my side.

You can support me from Patreon, Github Sponsors, Ko-fi, or Buy me a coffee