Ways To Search For Files Using The Terminal

image_pdfimage_print

Today we will look at some of the common ways to search for files in Linux using the Terminal.

1) find : To search for files on the command line you can use the command “find”. The following is syntax for the “find” command:

find path criteria action

“path” – The section of the files system to search (the specific directories and all the sub directories). If nothing is specified the file system below the current directory is used.

“criteria” – The file properties.

“action” – Options that influence conditions or control the search as a whole, ie,
“–print”

 

 

2007-11-22-153941_1280x800_scrot

 

2) locate : The command “locate” is an alternative to the command “find -name”. The command find must search through the selected part of the file system, a process that can be quite slow. On the other hand, locate searches through a database previously created for this purpose (/var/lib/locatedb), making it much faster. The database is automatically created and updated daily. But change made after the update has been performed are not taken into account by locate, unless the database is updated manually using the command updatedb.

 

2007-11-22-154054_1280x800_scrot

 

3) whereis : The command “whereis” returns the binaries (option -b), manual pages (option -m), and the source code (option -s) of the specific command. If no options is used all the information is returned, if the information is available. This command is faster than “find” but is less thorough.

2007-11-22-154226_1280x800_scrot

 

4) which : The “which” command searches all paths listed in the variable PATH for the specific command and returns the full path of the command. the command is specifically useful if several version of a command exist in different directories and you want to know which version is executed when entered without specifying a path.

2007-11-22-154254_1280x800_scrot

 

5) type : The “type” command can be used to find out what kind of command is executed when command is entered – a shell built in command or an external command. The option -a delivers all instances of a command bearing this name in the file system.

2007-11-22-154354_1280x800_scrot