The following are a few examples showing how to perform some common tasks using the “find” tool. I will add more as time goes on.
Basic syntax: find pathname... expression
#If you want to find files that are 7 days old, use the -mtime option
find . -mtime 7 -print
(Assuming today is 23-Dec, the command will show the files that are only dated 16-Dec.)
#An alternate way is to specify the range of periods
find . -mtime +6 -mtime -8 -print
find . -mtime +6 -mtime -8 -exec ls -lt {} \;
#Find files based on 7 days ago (atime means last accessed time)
find / -atime 7 -ls
#List old files and delete them (mtime means last modified/creation time of a file)
find -mtime +60 -exec rm -f {} \;
#Find core files in the directory and remove them
find . -name "core" -exec rm -f {} \;
Note:-
When using with “-exec” command, it should be used together with {} and ; (semicolon), where {} is used as a variable whose name is the file “find” found.
As for ; (semicolon), it represents the end of command which must be punctuated by a quoted or escaped ; (semicolon).
*** df -h (human readable)
du -sh * | sort –nr
du -hsx * | sort -rh | head -10
du -sh * | sort –nr
du -hsx * | sort -rh | head -10
No comments:
Post a Comment