Saturday 4 May 2013

Find Command




Find
Find files using name
-find / -xdev -iname "*.ldif"
-i= ignore case
-/= find all directory under /
-xdev= dont search mounted direcoties,dont include other filesystem
Find all of the files which have been modified within the last 10 days
-find * -mtime -10
Find list of all pdf files that were accessed in last 60 days
-find / -iname *.pdf -atime -60
File with size over 1GB
-find / -size +1024000k -exec du -h '{}' \; -print
Find 10 largest files in /
-find / -xdev -type f -exec ls -s {} \; |sort -n -r |head -10
-s=size
-n= numeric value
-r= reverse
Find files/directory which has full permission
-find / -perm -777 -type f -exec ls -l {} \;
-perm= for permission
-f= for file
-d= for directory
Find files that are owned by user user1
-find / -xdev -user user1
Find tatal how many files are there in the machine.
-find / -xdev |wc -l

==========================================================
To delete all .LOG files older than 7 days
    -find /data01/logs -name "*.LOG" -mtime +7 -exec ls -lrt {} \; >> /data01/logs/filetodelete.txt
    -find /data01/logs -name "*.LOG" -mtime +7 -exec rm -f {} \;

==========================================================

2 comments: