Hack 18. Find Command Examples
find is frequently used command to find files in the UNIX filesystem based on numerous conditions. Let us review some practice examples of find command.
The following command looks for all the files under /etc directory with mail in the filename.
- # find /etc -name "*mail*"
How to find all the files greater than certain size?
The following command will list all the files that were modified more than 60 days ago under the current directory.
How to find files that are modified in the last x number of days?
The following command will list all the files that were modified in the last two days under the current directory.
- # find / -type f -name *.tar.gz -size +100M -exec ls -l {} \;
- # find / -type f -name *.tar.gz -size +100M -exec rm -f {} \;
How to archive all the files that are not modified in the last x number of days?
The following command finds all the files not modified in the last 60 days under /home/jsmith directory and creates an archive files under /tmp in the format of ddmmyyyy_archive.tar.
On a side note, you can perform lot of file related activities (including finding files) using midnight commander GUI, a powerful text based file manager for Unix.