0% found this document useful (0 votes)
7 views3 pages

PE09-Search Tools

This document provides a practical exercise for students to learn Linux search tools such as find, which, locate, and whereis. It includes step-by-step instructions for using these commands to locate files, identify file types, and understand the system's command paths. The exercise emphasizes practical applications of these tools in navigating the Linux file system.

Uploaded by

ramiplan2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

PE09-Search Tools

This document provides a practical exercise for students to learn Linux search tools such as find, which, locate, and whereis. It includes step-by-step instructions for using these commands to locate files, identify file types, and understand the system's command paths. The exercise emphasizes practical applications of these tools in navigating the Linux file system.

Uploaded by

ramiplan2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 09 - 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.

1 – Use find to look for files named resolv.conf.


find / -name resolv.conf 2> /dev/null

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.

2 – Identify a file type of a specified file.


file /etc/resolv.conf
File identifies /etc/resov.conf has a symbolic link to /run/system/resolv/stub-
resolv.conf

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

You might have multiple copies of executables on your computer in various


directories. But if the file is not executed with a complete absolute or relative path
you don’t know for sure which of those copies is being run. The which command
can be used to figure out which one of those files executes when you type the
command. Which resolves the location of a file based on the path. With this
command we know that if we run the init command it will find it in /usr/sbin.

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.

8 – Use type on tail.


type tail Rerun the hash command to see the updated
list.

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.

9 – Use type on cat with the -a option.


type -a cat

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

10 – Use type on ip with the -a option.


type -a ip Rerun the hash command to see the updated list.

Page 3 of 3
PE09-Search Tools

You might also like