Locate: Lookups are based on the database of the file system. The database is updated by the updatedb program. updatedb is created by the cron daemon and runs periodically. You can also generate it manually with the updatedb command. This search is a non-real-time fuzzy match. locate is faster than find which searches the entire hard disk, but the downside is that the files my not be found by locate if they have been recently created or renamed, or some files has just been deleted could be found before the database updated.

You can tell it to only find files and directories whose names (rather than full paths) include the pattern with the -b option

To avoid finding recently deleted files, use -e.

apt-get install mlocate
locate <filename> 

Whereis: The principle of whereis is similar to locate in that it is also retrieved through the database. The database is updated once a week by default.

whereis [-bmsu] [ -SBM dir ... -f ] <filename>
# Parameters Description: 
# -b Locates the binary executable file.
# -m Locates the man page files.
# -s Locates the source code file.
# -u Searches for files other than executables, source files and help files in the default path.
# -B<directory> Looks for binary files only in the set directory. 
# -M<directory> Find only man page files in the set directory 
# -S<directory> To find only the original code file in the set directory. 
# -f Does not display the path name before the file name.  

Find: real-time, accurate and supports many search criteria. However, find needs a traversal of the hard disk and is therefore very resource intensive and inefficient.

find <path> <find_criteria> <action_after_find>
: '
Criteria:
 -name "FILENAME": exact match for the file name
 -iname "FILENAME": matches the file name, case insensitive
 -regex PATTERN: find files based on regular expressions
 -user USERNAME: search based on the owner of the file
 -group GROUPNAME: search based on the group of the file
 -uid UID: search based on the UID of the file
 -gid GID: search based on the GID of the file
 -nouser: no owner
 -nogroup: no group
 -type: specify the file type
 -size: specify the file size
 
 -atime n: list the files fetched in n*24 hours 
 -ctime n: list files or directories that have been changed or added in n*24 hours 
 -mtime n: list files or directories that have been modified in n*24 hours 
 -amin n: n*minutes
 -mmin n
 -cmin n
 -newer file: list files that are newer than file
 
Actions:
 -print: display (default)
 -print0: display without line feed
 -ls: similar to ls -l
 -ok COMMAND {} \: each operation requires user confirmation. 
                   e.g.: find -atime +5 -ok mv {} {}.old \
 -exec COMMAND {} \: does not require user confirmation.
                   e.g.: find -atime +2 -exec mv {} {}.old \
        ({} filename placeholder)
 -path PATH : specify path
 -prune : delete

' 

Which finds the binary executable of the program (if it is in your PATH). man which explains more clearly:
which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in a strictly POSIX-conformant shell. It does this by searching the PATH for executable files matching the names of the arguments. It does not follow symbolic links.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *