How to move items in bulk out of nested folders in MacOS.

Say you have a folder containing 100 subfolders, each containing 100 files.

Here’s how to move all 10,000 files in bulk into the main folder.

Step 1

Go to the parent folder of the nested folders. Press Alt, right click on the folder, and select “Copy [folder name] as a Pathname”.

Next, open Terminal and enter the command below. Replace the highlighted path with the copied path of the parent folder, then press Enter.

cd /path/to/your/parent_folder

Step 2

Copy and paste this command, and then press Enter.

find . -type f -exec mv {} . \;

It may take a while depending on the number of nested folders. Once completed, you should see all the moved files in the parent folder.

Step 2 (Alternative)

If you want to append the name of the nested folders to the front of individual file names, copy and paste this command instead, then press Enter.

find . -type f -exec sh -c 'file="{}"; parent_dir=$(dirname "$file"); first_folder=$(echo "$parent_dir" | cut -d/ -f2); mv "$file" "./${first_folder}_$(basename "$file")"' \;

Step 3

Now, you might be left with empty nested folders. Run this command again to delete them in one fell swoop.

find . -type d -empty -delete

Warning

Do not run any of the commands above twice, as you would risk deleting the moved files.

Previous
Previous

How to bulk rename files into ordered numbers in MacOS.

Next
Next

How to count the number of times a keyword appears in an Airtable cell.