whereis
This powerful tool will help you locate binary, source, and manual page files for various commands in the Linux system.
Let’s start by using whereis to find information about the ls command:
whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
This output provides two pieces of information:
/usr/bin/ls: This is the location of the ls binary executable. When you type ls in the terminal, this is the actual program that runs.
/usr/share/man/man1/ls.1.gz: This is the location of the manual page for ls. Manual pages contain detailed information about how to use commands.
The whereis command searches for files in a restricted set of locations, including standard binary directories, library directories, and man page directories. This makes it faster than searching the entire file system.
If you’re curious about what these paths mean:
/usr/bin is a common location for user commands.
/usr/share/man is where manual pages are typically stored.
man1 indicates this is a user command manual (as opposed to system calls or library functions).
The .gz extension means the file is compressed to save space.
Finding Binary Files
Your team lead asks you to locate the binary file for the grep command. The -b option of whereis is perfect for this task as it specifically searches for binary files.
Try the following command:
whereis -b grep
grep: /usr/bin/grep
This output shows the location of the grep binary file. Binary files are the executable programs that run when you type a command. In this case, when you use the grep command, you’re actually running the program located at /usr/bin/grep
If you try to find binary non existing on the system you should get only this output:
whereis -b nonexistent
nonexistent:
This is useful when you’re unsure if a particular command is installed on your system.
Locating Manual Pages
Manual pages are essential for understanding how to use various commands.
Use the -m option with whereis to locate manual pages:
whereis -m ssh
ssh: /usr/share/man/man1/ssh.1.gz
This output shows the location of the manual page for the ssh command. The .gz extension indicates that the file is compressed to save space.
To view the contents of a manual page, you would typically use the man command.
Combining Options
to find both the binary and the manual page for the python3 command in one go.
You can combine the -b and -m options to achieve this:
whereis -bm python3
python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3 /usr/share/man/man1/python3.1.gz
This output provides a wealth of information:
/usr/bin/python3: The location of the Python 3 binary (the executable program)
/usr/lib/python3: The directory containing Python 3 libraries (reusable code used by Python programs)
/etc/python3: A directory containing Python 3 configuration files
/usr/share/python3: A directory containing shared Python 3 data
/usr/share/man/man1/python3.1.gz: The location of the Python 3 manual page
Exploring Source Files
o check if the source files for the bash shell are available on the system. Source files can be useful for understanding how a program works or for compiling custom versions.
Use the -s option to search for source files:
whereis -s bash
The output might be empty, as source files are not typically installed by default on most systems. If you do see output, it would indicate the location of bash source files on your system.
Now, let’s combine all options to get a complete picture of the bash command:
whereis bash
This command without any options will show all available information about bash, which might look like this:
bash: /usr/bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz
This output shows:
/usr/bin/bash: The binary executable for bash
/etc/bash.bashrc: A system-wide configuration file for bash
/usr/share/man/man1/bash.1.gz: The manual page for bash
Understanding the locations of these files is crucial for system administration tasks. For example, if you need to modify the default behavior of bash for all users, you’d know to look in /etc/bash.bashrc.
Summary
In this lab, you’ve learned how to use the whereis command to locate binary, source, and manual page files for various commands in the Linux system. You’ve discovered how to:
Find basic information about commands
Locate binary files using the -b option
Find manual pages using the -m option
Combine options to get more comprehensive information
Search for source files using the -s option
These skills will prove invaluable in your role as a system administrator, allowing you to quickly locate important files and understand the structure of your Linux system.
Additional whereis command options not covered in this lab include:
-u: Search for unusual entries (files that do not follow the usual naming pattern)
-B: Change or restrict the places where whereis searches for binaries
-M: Change or restrict the places where whereis searches for manual pages
-S: Change or restrict the places where whereis searches for sources
As you continue your journey in system administration, remember that whereis is just one of many tools at your disposal. It’s particularly useful for quick lookups, but for more comprehensive file searches, you might want to explore commands like find or locate in the future.