Need to find a specific file or files of a certain type within the command line on ubunutu. The find command can help, and is very verstile when looking for files on your systems. Detailed below are a few helpful ways to using the find command.
The default syntax of find is:
find [path] [expression]
where path is the path used as root for searching pattern and expression the expression we want the file to match.
Finding a file based on filename
If your looking for a specific file you can run
sudo find / -name fstab
This will show all instances of the fstab file and the location
If your looking for all fies of a particular type you can use
find /home -name '*.txt'
If you want to search for multiple types of file
find /home -name '*.txt' -o -name '*.doc'
Case insensitive searches can be achieved by using the -iname switch:
find /home -iname '*.txt' -o -iname '*.doc'
Finding file will specific sizes
If your looking for a file with a specific size, such as large video files you can narrow down the search by adding extra criteria.
The below command will find an mpg file over 700MB
find /home/ -name '*.mpg' -a -size +700M
Finding files Modifed recently.
What about a file modifed recently? – This will find a file updated in the last 15 days.
find /home/ -name '*.avi' -a -size +700M -mtime -15