Shorts
Miscellaneous Features
SHORT
COMMAND COVERED
whoami - display effective user id as a name
Display the current logged-in user using whoami
This example runs the
whoami command to print the username of the currently logged-in user. The output is a single line containing the effective username associated with the current process. It's a quick way to confirm which account is active, especially when switching between users or running commands with sudo (which is used to execute a command as another user ). Unlike id, it returns only the username with no additional detail. While the whoami command still exists, it has been obsoleted by the id command, which can provide more details about the current logged-in user. See man id for more details.
Miscellaneous Features
SHORT
COMMAND COVERED
env - print environment
Print environment variables using env
This example runs the
env command and pipes the output to head to show the first 5 lines of environment variables, albeit unsorted. Each line displays a variable name and its value separated by =. Environment variables such as PATH, HOME, and SHELL store configuration used by the shell and running processes. This is a useful starting point for understanding the current shell environment. For an alternative command that provides similar output, see man printenv.
Miscellaneous Features
SHORT
COMMAND COVERED
echo - show environment variable
Display the PATH environment variable using echo
This example uses the
echo command to print the value of the PATH environment variable. The shell expands $PATH before passing it to echo, resulting in a colon-separated list of directories. These directories are searched in order when you type a command name. Inspecting $PATH is often the first step when a command can't be found or the wrong version is running.
Miscellaneous Features
SHORT
COMMAND COVERED
alias - define alias
Create and use a command alias
This example defines a shell alias named
ll that expands to ls -lh. Next, it navigates to the /usr/local/var directory and runs the newly created ll alias. The shell substitutes the alias before executing, producing a long-format, human-readable (file size) directory listing. Aliases are session-scoped by default and disappear when the shell exits. To make them permanent, they're typically added to ~/.zshrc or ~/.bashrc.
Miscellaneous Features
SHORT
COMMAND COVERED
alias - Show aliases
List all defined aliases using alias
This example defines a new alias
ll and then runs the alias command with no arguments to list all currently defined aliases. The output includes the newly created ll. Each line shows the alias name and the command to which it expands. This is useful for auditing what shortcuts are active in the current session. If any additional aliases had been defined in this shell environment, they would have also been displayed.
Miscellaneous Features
SHORT
COMMAND COVERED
export - set environment variables
Set and use an environment variable using export
This example uses the
export command to define a new environment variable called MY_VAR with the value hi. Running echo $MY_VAR prints the value, confirming it was set. The export keyword makes the variable available not just in the current shell but also to any child processes spawned from it. Without export, the variable would be local to the current shell only.