Combining Options and Searching for Multiple Commands
The whereis
command offers flexibility in how you search for files and can be used to search for multiple commands at once. In this final step, we'll explore how to combine different options and search for multiple commands in a single query.
First, let's combine multiple options to refine our search. For example, if you want to find both binary files and manual pages (but not source files) for the tar
command:
whereis -b -m tar
You should see output similar to:
tar: /usr/bin/tar /usr/share/man/man1/tar.1.gz
This shows both the binary and manual page locations for the tar
command.
You can also search for multiple commands in a single whereis
query. This is useful when you need to locate several related commands at once. Let's find the locations for three commands - cp
, mv
, and rm
:
whereis cp mv rm
You should see output similar to:
cp: /usr/bin/cp /usr/share/man/man1/cp.1.gz
mv: /usr/bin/mv /usr/share/man/man1/mv.1.gz
rm: /usr/bin/rm /usr/share/man/man1/rm.1.gz
This gives you a quick overview of where these three common file manipulation commands are located in your system.
Another useful option is -l
, which lists the directories that whereis
searches when looking for files:
whereis -l
This will show a list of directories that whereis
checks for binary files, manual pages, and source files. The output will vary depending on your system configuration but might look something like:
bin: /usr/bin
bin: /usr/sbin
bin: /usr/games
bin: /usr/local/bin
bin: /usr/local/sbin
man: /usr/man/all
man: /usr/share/man/all
man: /usr/local/man/all
man: /usr/local/share/man/all
src: /usr/src/linux
src: /usr/src/packages
src: /usr/local/src
...
This information is useful for understanding where whereis
is looking and why it might not find certain files even if they exist on your system.
The whereis
command is a quick way to locate important files associated with commands in your Linux system. While it has some limitations (like only searching in predefined paths), it provides a fast and straightforward method to find binary executables, manual pages, and in some cases, source files for the commands you use.