Monday, January 20, 2014

Find and delete files by name on a *nix file system


Here's a quick one liner that will find files by name in the current and all sub-directories and delete them. Tailor it to suit your needs:

find . -name '.DS_Store' | while read pth; do echo "pth=$pth"; rm $pth; done

Hope that helps!

UPDATE Alternate version:
Ran into an excuse to use this today:

find . -name '.DS_Store' -exec rm -f {} \;

The -exec tells the find command to run the following command foreach result it finds. The {} is the placeholder for the found path. The \; bit is the escaped terminator (;) for the command to be executed.

No comments:

Post a Comment