Post

Use Terminal

Examples of Terminal/Bash commands

Use Terminal

After learning some basic terminal commands, you can/should learn Git!

Go to Use Git.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Display the current working directory
pwd

# Change directory
cd path/to/directory

# Move up to the parent directory
cd ..

# Return to the home directory
cd ~

# Navigate to the previous directory
cd -
1
2
3
4
5
6
7
8
9
10
11
# List all files in the current directory
ls

# List all files with detailed info (permissions, size, etc.)
ls -la

# List files with human-readable sizes
ls -lh

# List all files in a directory
ls -R [path]

Create and Remove Files/Directories

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Create an empty file
touch filename

# Open a file for editing (default editor)
open filename

# Delete a file
rm filename

# Delete multiple files
rm file1 file2 file3

# Force delete without confirmation
rm -f filename
1
2
3
4
5
6
7
8
9
10
11
# Create a new directory
mkdir new_directory

# Create multiple nested directories
mkdir -p dir1/dir2/dir3

# Delete a directory (non-empty)
rm -R directory_name

# Force delete a directory and its contents
rm -rf directory_name

Aliases and Shortcuts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Open shell configuration file .zshrc or .bashrc
nano ~/.zshrc
code ~/.zshrc

# View existing aliases
alias

# Add a permanent alias
alias listall="ls -la"
alias jserve="bundle exec jekyll serve"

# Jekyll post shortcut
function jpost() {
  bundle exec jekyll post "$*"
}

# Jupyter notebook to HTML
function nb2html() {
  jupyter nbconvert --to html "$1"
}

# Save (Ctrl + O), then Enter, and Exit (Ctrl + X)
# Reload the shell configuration
source ~/.zshrc

Shortcuts and Commands

1
2
3
4
5
6
7
8
# Clear the terminal screen
clear     # --- Cmd + K --- also works

# Show all previously executed commands
history

# Run a command from history by its number
!1016     # ![number]
1
2
3
4
5
6
7
8
9
10
11
# Display system info (kernel, architecture, etc.)
uname -a

# View macOS version
sw_vers

# Check your IP address (useful for networking)
ifconfig

# Ping a website or server (test connectivity)
ping example.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# View file permissions
ls -l

# List all processes
ps -A

# Show system uptime
uptime

# Show memory usage (macOS)
vm_stat

# Show running processes with CPU and memory usage
top
This post is licensed under CC BY 4.0 by the author.