Find-examples

From PTAGISWiki

Jump to: navigation, search

Remove all log files older than 20 days: find /insight/var/archive -mtime +20 -type f -exec rm {} \;

Find all files changed in the last week: find / -mtime -7 -print > /tmp/filelist.weekly

Find all files in /tmp that aren't directories, accessed more than three days ago and exec an ls -l on them: find /tmp \! -type d -atime -3 -exec ls -l {} \;

Find all files in the /etc tree that contain the word "loadkeys": find /etc -type f | xargs grep loadkeys

Find all root-owned setuid files: find / -xdev -perm +4000 -user 0 -ls

Find all files in /tmp that aren't directories, accessed more than three days ago and exec an ls -l on them: find /tmp \! -type d -atime -3 -exec ls -l {} \;

Run collection script on all machines listed in the current directory: dir -1 | xargs -l1 collect

Find all files in the current directory that may contain quotes or special characters and display the first line of each: find . -type f | xargs -l1 -0 head -1

Do a find and replace on all text in all files in all subdirectories: find . -type f | xargs perl -p -i -e "s/oldtext/newtext/g";

Determine the size (in bytes) of all files in the current directory tree: find . -type f -xdev -printf "%s + p\n" | dc | tail -1

For each file ending in 'dat' in the current directory, look for an occurence of that file name in a file called cvsindex.xml. Display the count of the number of occurences in cvsindex.xml: ls *dat | xargs -i grep -c {} cvsindex.xml

Find files between a range of times find . -newer MCJ05137.103 -a ! -newer MCJ05137.105

Grep through all files in a directory tree: find . -type f -exec fgrep -l "support@ptagis.org" {} \;

Personal tools