PE09-Search Tools
PE09-Search Tools
This Practical Exercise will take students through the use of Linux search
tools like find, which, locate and whereis to help them find utilities and files
within the Linux file system.
Find goes through the entire filesystem starting at the / (root) directory searching
for files that match the pattern specified. In this case it is searching for any files
with the name "resolv.conf". The technique shown here of using 2> /dev/null is
both a common and useful method of preventing you from seeing error messages
you do not care about. Try the command again by pressing up arrow and deleting
"2> /dev/null" from the command and pressing enter. You can see it is much
easier to read without the errors.
file /usr/lib/openssh/ssh-keysign
File identifies this file as a Linux ELF 64-bit file. ELF is the "Executable and
Linkable Format" and is the name given to any binary executable on a Linux
System.
touch newfile
file newfile
File identifies this file as an empty file.
Page 1 of 3
PE09-Search Tools
3 – Use which to determine the location of the init executable.
which init
4 – Use whereis to find files related to the init & tail executable.
whereis init whereis tail
Whereis finds files that are related to a specific command and shows the full path
of their location in the system. This will usually include configuration files, man
pages, and other files the program uses when executing.
5 – Use hash to see what $PATH commands the shell already knows.
hash
The hash command is showing you similar information to which. It tells you the
full path of the file that was found in the path. It also tells you how many times
that command has been run in the current shell under the column called “hits”.
Notice that the word tail is not currently in the list of commands.
6 – Use type on the various commands to see how the system identifies them.
type tail
type cat
type ls
type cd
Page 2 of 3
PE09-Search Tools
7 – Use tail on /var/log/syslog.
tail /var/log/syslog
When you execute the tail command it is found in the /usr/bin path and its location
is then stored in the table used by the hash command.
Now the type command shows that the tail command 'is hashed'. When you run
the 'hash' command it will show up in the list of commands that have been
executed.
The -a option of type command can also be used to display the location of a file.
Initially this looks like it is not doing anything different however type -a will show
you all of the commands in the path and their location
Page 3 of 3
PE09-Search Tools