Tag: *nix

Recursively Delete Files With Names Matching String

Share

I previously wrote about recursive grep.

Every now and then you need to delete files with a name that contains a string starting from the current directory and all files below. One way to do this on some Unix-like systems is to use something like...

find . -name \*.pyc -ok rm {} \;

The -ok will prompt you before deleting each file which is the safer but slower way to do it. If you're very sure about the file names you want to delete and don't want to be prompted then use -exec in place of -ok.

find . -name \*.pyc -exec rm {} \;

See also Recursively delete certain files.

Comments (0)       
Tags: *nix, code, file, find, match, name, recurse, reference, rm, software, unix-like

Recursive Grep

Share

Every now and then you need to know which files contain a string starting from the current directory and all files below. One way to do this on some Unix-like systems is to use something like...

find . -exec grep -l 'phrase to find in your files' {} \;

Comments (0)       
Tags: *nix, code, find, grep, recurse, reference, software, unix-like