Linux Cheat Sheet for essential Commands
Linux is a versatile operating system, packed with powerful tools and commands to streamline tasks, troubleshoot issues, and manage systems efficiently.
Whether you’re a seasoned sysadmin or a curious beginner, having a handy cheatsheet can save time and make your Linux experience more productive.
In this post, I will explore interesting and useful Linux commands and update this post regularly.
which
The which command in Linux is a simple utility that shows the location of an executable file for a given command in your system’s PATH. It helps users identify which version of a command or program will be executed when they run it in the shell.
which searches through the directories listed in the PATH environment variable and returns the full path of the first matching executable it finds.
# which zypper
Check the location of multiple commands:
# which zypper vi
-a (all matches): Lists all matching executables in the PATH, not just the first one.
which only works for executables in the PATH. If a command is not in the PATH or is an alias, function, or shell built-in, which will not detect it.
whereis
The whereis command in Linux is a utility used to locate the binary, source code, and manual pages for a given command. Unlike the which command previously, which only looks for executables in your PATH, whereis performs a broader search in predefined directories to provide more comprehensive information.
# whereis zypper
Different output when using the which vs. whereis command for the zypper tool.
# whereis -a zypper
Search for a command’s binary only:
# whereis -b zypper
Find only the manual pages:
# whereis -m zypper
The whereis command searches predefined directories for:
- Binaries in directories like /bin, /usr/bin, and others.
- Source files in standard source directories.
- Manual pages in directories like /usr/share/man.
whereis does not search the entire file system (e.g., for custom installations) and is not aware of shell aliases or functions.
history
The history command in Linux is a powerful utility that allows users to view and manage the command history of their terminal sessions.
The following command lists the last 15 entries.
# history 15
Every command executed in the terminal is stored in a history file, and the history command provides a way to access this list. Users can recall previously used commands, re-execute them, or even search through past commands for efficiency. This command is especially useful for users who frequently work in the terminal, as it saves time and reduces the need to manually retype lengthy or complex commands.
More about the history command in my following post.
Links
whereis(1) – Linux man page
https://linux.die.net/man/1/whereiswhich(1) – Linux man page
https://linux.die.net/man/1/whichhistory(3) — Linux manual page
https://www.man7.org/linux/man-pages/man3/history.3.html