How to find files in Linux
Linux commands to find files: find and locate.
These commands will not find text within a file.
find – Searches the directory tree rooted at each given file name by evaluating the given expression from left to right.
Syntax: find [path...] [expression]
[path...] – If no path is given, the current directory is used.
Examples:
find /tmp -name core -print
Find files named core in or below the directory /tmp.
find /tmp -name core -type f -print | xargs /binrm -f
Find files named core in or below the directory /tmp and delete them.
find $HOME -mtime 0
Search for files in your home directory which have been modified in the last 24 hours.
find . -perm 664
Search for files which have R/W permission for their owner and group but other users have read only permission.
locate - reads databases prepared by updatedb.
Default database searched /var/Lib/mlocate/mlocate.db
To update database, run “updatedb”
Syntax: locate [Option]… Pattern…
Examples:
locate -b ‘\TheDude’
Searches the file name TheDude in the local machine, exact file name.
locate yum.repo
Searches the location of yum.repo* in the local machine.