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

  1. Ensure only one terminal window is open.

  2. Run the command below:

rm -f ~/.zsh_history && kill -9 $$
  1. Close the terminal window.

  2. Quit the terminal app by right-clicking the app icon and selecting β€œQuit”.

  3. Open a terminal window.

  4. 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?