Here’s a cheat sheet for some commonly used terminal commands on macOS:
Basic Commands
Navigation
cd [directory]
: Change directory.pwd
: Print current working directory.ls
: List files and directories.ls -l
: List files and directories in long format.ls -a
: List all files (including hidden files).
File Operations
touch [filename]
: Create an empty file.cp [source] [destination]
: Copy file or directory.mv [source] [destination]
: Move or rename file or directory.rm [file]
: Remove/delete file.rm -r [directory]
: Remove directory and its contents.
Viewing and Editing Files
cat [file]
: Display file content.more [file]
orless [file]
: Display file content page by page.nano [file]
orvim [file]
: Open text editor to edit file.
System Information
System Info
uname -a
: Display system information.
Hardware Info
system_profiler SPHardwareDataType
: Display hardware information.df -h
: Display disk space usage.
Network Info
ifconfig
: Display network interfaces and their configurations.ping [host]
: Ping a host to test network connectivity.traceroute [host]
: Display the route packets take to network host.
User and Permissions
User Management
whoami
: Display current username.who
: Display who is logged in.users
: Display all logged-in users.
Permissions
chmod [permissions] [file]
: Change file permissions.chown [user]:[group] [file]
: Change file ownership.
Process Management
Running Processes
ps
: Display information about active processes.top
: Display real-time system statistics.
Process Control
kill [process_id]
: Terminate a process.killall [process_name]
: Terminate all instances of a process.
Package Management
Homebrew (Package Manager)
brew install [package]
: Install a package.brew upgrade [package]
: Upgrade a package.brew uninstall [package]
: Uninstall a package.brew list
: List installed packages.
Miscellaneous
Searching
find [directory] -name [filename]
: Search for files.
Archive and Compression
tar -cvf [archive_name].tar [files]
: Create a tar archive.tar -xvf [archive_name].tar
: Extract files from a tar archive.gzip [file]
: Compress a file.
System Preferences
open -a [application]
: Open an application.open [file]
: Open a file using the default application.
SSH (Secure Shell)
ssh [user]@[hostname]
: Connect to a remote server using SSH.
This cheat sheet covers a variety of macOS terminal commands. For more details and options, refer to the man pages using man [command]
or check online resources.