ZSH
Useful ZSH Commands
NOTE: The following commands are largely the same as BASH commands, since they're both UNIX-based shells.
Basic Commands
Change the Current Directory
cd <DIR_NAME>List Directory Contents
lsMove or Rename Directories
mv <SOURCE> <DESTINATION>Remove Files Directories
rm <FILE_OR_DIR_NAME>Set an Environment Variable
export VARIABLE_NAME=<SOME_VALUE>Display an Environment Variable
echo $VARIABLE_NAMEOpen a Directory in Finder (Mac)
open <DIR_NAME> Display an Entire File
cat <FILE_NAME>Display the First N Lines of a File
Fist 10 Lines:
head <FILE_NAME>First 5 Lines:
head -n 5 <FILE_NAME>Show Command History
historyClear Terminal History
Ensure only one terminal window is open.
Run the command below:
rm -f ~/.zsh_history && kill -9 $$Close the terminal window.
Quit the terminal app by right-clicking the app icon and selecting “Quit”.
Open a terminal window.
Run the command below to ensure your
.zsh_historyis empty.
cat ~/.zsh_historyClear Clipboard Content
pbcopy < /dev/nullList Local IP Address
The following command lists all local, non-loopback IPv4 addresses. Each IP address corresponds to a different network interface or network configuration on your machine.
ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'List Public IP Address
curl ifconfig.meSSH
Access a remote machine via SSH.
ssh <REMOTE_USERNAME>@<REMOTE_IP_ADDRESS>Exit SSH Session.
exitIn case your shell does not display user@hostname, the following are commands to check this information.
Check the current user's username:
whoamiCheck the current machine's hostname:
hostname -sLast updated
Was this helpful?