5 ways to find files in linux in Linux

Posted on March 5th, 2008 in Basics by admin

Video to Come Soon

Get the Flash Player to see this player.

First off lets check to see if findutils and findutils-locate are installed.  You can check by performing a:

rpm -qa | grep findutil (in Ubuntu/Debian you can check synaptic to see if they’re installed).

It should produce results such as this:

# rpm -qa | grep findutils
findutils-4.2.31-24
findutils-locate-4.2.31-24

If no results come up or only one of the packages install the one(s) you need as follows:

  1. su
  2. zypper in findutils findutils-locate (or in Ubunt/Debian install via apt-get, or in Fedora with Yum)

find : To search for files on the command line you can use the command “find”. The following is a sysntax for the “find” command:find path criteria action“path” - the section of the files system to search (the specific directories and all the subdirectories). 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”

locate : The command “loate” is an alternative to the command “find -name”. The command find must search through the selected part ofthe 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.

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.

which : The command which 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 differant directories and you want to know which version is executed when entered without specifying a path.

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

Post a comment