Locate
Locate searches a database (index) of all the files on the local system. You must update this database using the command: updatedb before running locate
Example:
updatedb
locate shadow.bak
Locate, by default, assumes a wildcard string. E.g. if you search for passwd, it actually looks for *passwd*. if you want it to just search for the whole word then use: locate ‘/passwd’. This will still find passwd.1 and passwd.2 but won’t find this_file_has_passwd_ entries.txt for example.
Which
The which command searches only the directories defined in the $PATH environment variable.
Example:
which passwd
Find
Find recursively searches a given path
Example:
find / -name passwd*
Here the path is / (root) and the name of the file is passwd with wildcard following it.
find can also be used to search for file properties like: size, date, ownership. It can also take a parameter which will execute a command for each
find / -name passwd.* -exec file {}; – this command finds files with the passwd.* pattern and then executes the file command on them, giving useful file information.
Leave a Reply