tirsdag den 28. oktober 2008

Recursice Linux commands

Recurse through directories and delete files with a specific text inside the name
find . | grep FILENAMETOSEARCHFOR | xargs rm -r

Recurse through dirs, find files with a certain textstring in the filename and delete them
find . | grep TEXTSTRINGINFILENAME | xargs rm -r

Find all files that has a certain textstring inside the file
find . | xargs grep TEXTSTRINGINSIDEFILE

Recurse though directories and delete all empty directories
find -depth -type d -empty -exec rmdir {} \;

Recurse through directories and force removal of duplicate files
yes 1 | fdupes -rd .

Recurse and list subdirectories (pipe the command to wc -l if you want to count the number of subdirectories)
find directoryname -mindepth 2 -type d

Remember to backup before you execute commands that recurse and delete!

Ingen kommentarer: