How to find stuff in Linux

You’ll often find yourself looking for things. Here are some useful tips for just that. There are some commands that have proven useful for finding things in Linux.

find is a popular command line tool that searches for files in the directory hierarchy. The command searches the current directory and recursively searches subdirectories for the supplied criteria.

The -name argument allows you to find specific patterns of information. Of note, find is case sensitive so use -iname to avoid missing what you are looking for.

find . -name file

locate is a very fast way of searching for files on disk rather than searching for file paths on the system. By default, locate does not check if files still exist in the respective database. To update the database that locate searches is updated with the updatedb command. Locate a file on the Strategic Security Ubuntu VM. Using locate without any options will bring up results that contain the keyword.

Let’s locate the file r00kies. This file will need to be created for this example using the touch command. Use the touch command to create 3 different files with r00kies in the name. Make sure to update the database after these files are created using sudo updatedb.

This shows us 3 files, but we only wanted the r00kies files. Let’s use the -b option to search exactly what we want. The backslash disables the implicit replacement of “r00kies” by “*mydata*” so you end up with only what we are looking for.

locate -b ‘\r00kies’

whereis searches for binary files, source files, and man pages. This is useful when determining a file is executed from. To only show the executable only, use the -b option.

whereis firefox
whereis -b firefox

which command helps in returning the absolute path of the executable that is called. This makes creating shortcuts a bit easier. By default which only shows the first matching executable. To display all results use the -a option. Only the current user’s PATH variable are searched.

which firefox

Reference(s):

http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/

http://www.howtogeek.com/112674/how-to-find-files-and-folders-in-linux-using-the-command-line/

Try Certified Ethical Hacker for FREE!!!https://infosecaddicts.com/course/certified-ethical-hacker-v10/

Avatar

This post was written by Ruben Dario Caravajal Herrera