Bash – Remove All Of A File Type From a Directory And Its Children

This past week I move migrating my Google Photos to my newly setup Amazon Photos. So I downloaded all of my Photos from Google Photos. One problem, when I downloaded, I got sub directories in sub directories and had a bunch of JSON files included. Since I’m only moving Image Files, I didn’t need the JSON files. So, I had to find a way to delete them without having to go into each directory and removing 1 at a time.

On the command line, how do you recursively remove all files of a certain type?

To remove JSON files from all directories within my main directory, I used the following command.

find . -name "*.json" -type f | xargs rm -f

This will find all files that match a name and then run the rm -f command on each one.

Leave a comment

Leave a Reply