Navigation

Change to the specified directory.

$ cd directory_name

Go back to the parent directory.

$ cd ..

Print the current working directory.

$ pwd

Push the current directory onto the stack and change to the specified directory.

$ pushd directory_name

Pop the top directory from the stack and change to it.

$ popd

Change to the home directory.

$ cd ~

Change to the previous directory.

$ cd -

Change to the root directory.

$ cd /

Listing

List all files in the current directory.

$ ls

List files in long format with detailed information.

$ ls -l

List all files, including hidden ones.

$ ls -a

List files with human-readable file sizes.

$ ls -lh

List subdirectories recursively.

$ ls -R

List files sorted by modification time.

$ ls -lt

List only directories in the current directory.

$ ls -ld */

List files and directories in a tree-like format.

$ tree

File and Directory Operations

Create a new directory with the specified name.

$ mkdir directory_name

Remove an empty directory.

$ rmdir directory_name

Create an empty file named 'file.txt'.

$ touch file.txt

Remove (delete) a file.

$ rm file.txt

Remove a directory and its contents recursively.

$ rm -r directory_name

Move (rename) files or directories.

$ mv source destination

Copy files or directories.

$ cp source destination

Copy directories recursively.

$ cp -r source destination

Permission and Ownership

Change file permissions (e.g., chmod 755 file).

$ chmod permissions file

Change the owner and group of a file.

$ chown user:group file

Change the group of a file.

$ chgrp group_name file

Display or set the file creation mask.

$ umask

Execute a command with superuser privileges.

$ sudo

Switch user or become superuser.

$ su

Repeat the last command with superuser privileges.

$ sudo !!

Run a command as another user.

$ sudo -u username command

Archives and Compression

Create a compressed tarball of a directory.

$ tar -czvf archive.tar.gz directory

Extract files from a compressed tarball.

$ tar -xzvf archive.tar.gz

Extract files from a ZIP archive.

$ unzip archive.zip

Compress a file with gzip.

$ gzip file

Decompress a gzip-compressed file.

$ gunzip file.gz

Compress a file with bzip2.

$ bzip2 file

Decompress a bzip2-compressed file.

$ bunzip2 file.bz2

Create a 7-Zip archive of a directory.

$ 7z a archive.7z directory

Network Commands

Test Network Connection.

$ ping

Display network interface configuration.

$ ifconfig

Trace Route to Destination.

$ traceroute

Display Network Statistics.

$ netstat

Query DNS for Information.

$ nslookup

Display or Modify the ARP Cache.

$ arp

Display or Modify the Routing Table.

$ route

Connect to a Remote Host.

$ telnet

System Information Commands

Detailed system configuration information.

$ system_profiler

Display macOS version and build information.

$ sw_vers

Display and update sorted information about system processes.

$ top

Display information about active processes.

$ ps

Display current user information.

$ whoami

Display how long the system has been running.

$ uptime

List all connected disks and their partitions.

$ diskutil list

Display disk space usage.

$ df -h

Output and Formatting Commands

Display messages or enable/disable echoing.

$ echo

Clear the terminal screen.

$ clear

Display output one screen at a time.

$ more

Display the contents of a file.

$ cat filename

Turn off command echoing.

$ echo off

Turn on command echoing.

$ echo on

Format and print data.

$ printf

Count lines, words, and characters in a file.

$ wc

User Account Commands

Display user and group information.

$ id

List all user accounts.

$ dscl . -list /Users

Display information about a specific user.

$ dscl . -read /Users/username

Create a new user.

$ sudo dscl . -create /Users/new_user

Delete a user account.

$ sudo dscl . -delete /Users/username

Add a user to the admin group.

$ sudo dseditgroup -o edit -a username -t user admin

Remove a user from the admin group.

$ sudo dseditgroup -o edit -d username -t user admin

Display members of the admin group.

$ dscacheutil -q group -a name admin

Security and Permissions

Change file permissions (e.g., chmod 755 file).

$ chmod permissions file

Change the owner and group of a file.

$ chown user:group file

Change file flags.

$ chflags

Display or set the file creation mask.

$ umask

Execute a command with superuser privileges.

$ sudo

Switch user or become superuser.

$ su

Repeat the last command with superuser privileges.

$ sudo !!

Run a command as another user.

$ sudo -u username command

System Utilities

Open Activity Monitor.

$ activity monitor

Open an application.

$ open -a app_name

Open Spotlight search.

$ spotlight

Configure system settings.

$ systemsetup

Power management settings.

$ pmset

Prevent the system from sleeping temporarily.

$ caffeinate

Disk management utility.

$ diskutil

Network configuration utility.

$ networksetup

I/O Redirection

Redirect command output to a file (overwrite).

$ command > output_file

Redirect command output to a file (append).

$ command >> output_file

Redirect command input from a file.

$ command < input_file

Redirect error output to a file.

$ command 2> error_file

Redirect both standard output and error output to a file.

$ command 2>&1 > output_file

Redirect command output to a file and also display it in the terminal.

$ command | tee output_file

Append command output to a file and also display it in the terminal.

$ command | tee -a output_file

Redirect both input and output using file descriptors.

$ command < input_file > output_file

Text Processing

Search for a pattern in a file.

$ grep pattern file

Stream editor for filtering and transforming text.

$ sed

Pattern scanning and processing language.

$ awk

Remove sections from each line of a file.

$ cut

Sort lines of text files.

$ sort

Report or omit repeated lines.

$ uniq

Translate or delete characters.

$ tr

Output the first part of files.

$ head

Process Management

Display information about active processes.

$ ps

Display and update sorted information about system processes.

$ top

Terminate or signal a process.

$ kill

Signal processes based on their name.

$ pkill

Kill processes by name.

$ killall

List active jobs.

$ jobs

Bring a background job to the foreground.

$ fg

Send a job to the background.

$ bg

System Information

Display how long the system has been running.

$ uptime

Display current user information.

$ whoami

Display kernel and system information.

$ sysctl

Display system information.

$ uname -a

Display disk space usage.

$ df -h

Display disk usage of files and directories.

$ du -h

Display amount of free and used memory in the system.

$ free -h

List all network hardware ports.

$ networksetup -listallhardwareports

Networking

Configure network interfaces.

$ ifconfig

Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

$ netstat

Test network reachability.

$ ping

Trace the route to a network host.

$ traceroute

Query Internet name servers interactively.

$ nslookup

DNS lookup utility.

$ dig

OpenSSH SSH client.

$ ssh

Secure copy (remote file copy program).

$ scp

System Management

Execute a command with superuser privileges.

$ sudo

Interact with the Apple Software Update server to install macOS updates as well as updates for Apple's applications and utilities.

$ softwareupdate

Disk management utility.

$ diskutil

Power management settings.

$ pmset

Manipulate firmware variables.

$ nvram

Configure system settings.

$ systemsetup

Read and write user defaults from a defaults domain.

$ defaults

Load or unload jobs and services.

$ launchctl

Disk Management

Disk management utility.

$ diskutil

List all connected disks and their partitions.

$ diskutil list

Display information about a specific disk.

$ diskutil info /dev/diskX

Mount a specific partition.

$ diskutil mount /dev/diskXsY

Unmount a specific partition.

$ diskutil unmount /dev/diskXsY

Eject a disk.

$ diskutil eject /dev/diskX

Manipulate disk images (mount, unmount, verify, etc.).

$ hdiutil

Display disk space usage.

$ df -h

Terminal Multiplexer

Terminal multiplexer.

$ tmux

Create a new tmux session with a specific name.

$ tmux new-session -s session_name

Attach to an existing tmux session with a specific name.

$ tmux attach-session -t session_name

List all tmux sessions.

$ tmux list-sessions

Kill a specific tmux session.

$ tmux kill-session -t session_name

Kill the tmux server and all sessions.

$ tmux kill-server

Load a tmux configuration file.

$ tmux source-file tmux.conf

List tmux commands.

$ tmux list-commands

Package Management

Package manager for macOS.

$ brew

Install a package using Homebrew.

$ brew install package_name

List installed packages.

$ brew list

Upgrade installed packages.

$ brew upgrade

Remove a package installed with Homebrew.

$ brew remove package_name

Search for packages.

$ brew search keyword

Display information about a package.

$ brew info package_name

Remove old versions of installed packages.

$ brew cleanup