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
ls
Move 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_NAME
Open 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
history
Clear 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_history
is empty.
cat ~/.zsh_history
Clear Clipboard Content
pbcopy < /dev/null
List 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.me
SSH
Access a remote machine via SSH.
ssh <REMOTE_USERNAME>@<REMOTE_IP_ADDRESS>
Exit SSH Session.
exit
In case your shell does not display user@hostname
, the following are commands to check this information.
Check the current user's username:
whoami
Check the current machine's hostname:
hostname -s
Last updated
Was this helpful?