Are you a Command-Line or Shell connoisseur or New to Command-Line? in MacOS? If so, or you’re interested in learning more about using shell to interact with your MacOS ecosystem, here’s a list of 30 super-handy bash commands for macOS to level-up your terminal game.
These commands are super, SUPER, handy and will give you a lot of flexibility for managing files, monitoring system performance, and working with networks on your Mac. Let me know which ones you want to dive into, or if you need help with examples or automation ideas! 😊
System & File Management:
killall Dock
- Purpose: Refresh the Dock or resolve display issues.
- Usage:
killall Dock
ls
- Purpose: List files and directories.
- Usage:
ls -l
(detailed list)
cd
- Purpose: Change directories.
- Usage:
cd /path/to/folder
mkdir
- Purpose: Create a new directory.
- Usage:
mkdir new_folder
touch
- Purpose: Create an empty file.
- Usage:
touch file.txt
rm
- Purpose: Remove files or directories.
- Usage:
rm file.txt
(files),rm -r folder
(directory)
cp
- Purpose: Copy files or directories.
- Usage:
cp file.txt /path/to/destination
mv
- Purpose: Move or rename files/directories.
- Usage:
mv old_name.txt new_name.txt
cat
- Purpose: Display the content of a file.
- Usage:
cat file.txt
open
- Purpose: Open files, apps, or URLs.
- Usage:
open file.txt
(file),open -a "App Name"
(app)
System Monitoring & Control:
top
- Purpose: Monitor system processes and performance.
- Usage:
top
htop
(if installed)- Purpose: Advanced system monitoring with an interactive interface.
- Usage:
htop
ps
- Purpose: Show currently running processes.
- Usage:
ps aux
df
- Purpose: Check disk space usage.
- Usage:
df -h
du
- Purpose: Check disk usage of files and directories.
- Usage:
du -sh folder_name
uptime
- Purpose: Display system uptime.
- Usage:
uptime
whoami
- Purpose: Show the current logged-in user.
- Usage:
whoami
hostname
- Purpose: Show the computer’s hostname.
- Usage:
hostname
Network Commands:
ifconfig
- Purpose: Show network interface configuration.
- Usage:
ifconfig
ping
- Purpose: Check network connectivity to a server.
- Usage:
ping google.com
traceroute
- Purpose: Show the path packets take to a network host.
- Usage:
traceroute google.com
netstat
- Purpose: Display network statistics.
- Usage:
netstat -an
curl
- Purpose: Transfer data from a server (often used to test web servers).
- Usage:
curl https://example.com
scp
- Purpose: Securely copy files between systems.
- Usage:
scp file.txt user@remote:/path/to/destination
ssh
- Purpose: Log into a remote system via SSH.
- Usage:
ssh user@hostname
File & Text Manipulation:
grep
- Purpose: Search for patterns in files.
- Usage:
grep "search_term" file.txt
find
- Purpose: Search for files and directories.
- Usage:
find /path -name "file.txt"
sed
- Purpose: Stream editor for editing text.
- Usage:
sed 's/old_text/new_text/g' file.txt
awk
- Purpose: Process and analyze text files.
- Usage:
awk '{print $1}' file.txt
(prints first column)
tar
- Purpose: Compress or extract files.
- Usage:
tar -czf archive.tar.gz folder
(compress),tar -xzf archive.tar.gz
(extract)
If you're interested in learning more, see our 30 Advanced Command-Line Utilities List. There you'll find 30 more, more advanced utilities, to support your growing skillset.
Primary Category
Sub-Domain
Confidentiality
No