Useful find Commands

Recursive, multi-file find and replace with grep and xargs for performance:

Source: http://www.jonasblog.com/2006/05/search-and-replace-in-all-files-within-a-directory-recursively.html

[sourcecode language=’bash’]grep -rl ‘what_to_find’ ./ | xargs sed -i ‘s/what_to_find/what_to_replace_with/g'[/sourcecode]

PutĀ  a not in front of that expression:

[sourcecode language=’bash’]find ./ ! -type d[/sourcecode]

Escape wildcards to avoid the shell expanding them:

If you just quote it; “*.avi” you can often run into trouble.

[sourcecode language=’bash’]find ./ -name \*.avi[/sourcecode]

Prune empty directories

[sourcecode language=’bash’]find ./ -depth -type d -empty -exec rmdir -v {} \;[/sourcecode]

Source: http://duramecho.com/ComputerPrograms/DeleteEmptyDirectories/index.html

One Reply to “Useful find Commands”

Leave a Reply

Your email address will not be published. Required fields are marked *