Here are some useful commands for the Terminal on a MacBook:
These commands should cover a wide range of tasks and help you effectively manage your MacBook via the Terminal.
Basic Commands
Change Directory
cd <directory>Example:
cd DocumentsList Files and Directories
lsCommon options:
ls -l # long format ls -a # show all files, including hidden ls -lh # long format with human-readable file sizesPrint Working Directory
pwdCreate a New Directory
mkdir <directory>Example:
mkdir new_folderCreate an Empty File
touch <filename>Example:
touch newfile.txtCopy Files or Directories
cp <source> <destination>Example:
cp file1.txt file2.txtMove or Rename Files or Directories
mv <source> <destination>Example:
mv oldname.txt newname.txtRemove Files or Directories
rm <file>Remove directory and its contents:
rm -r <directory>Display File Contents
bash cat <file>Example:bash cat file.txt
System Information and Management
Check Disk Usage
df -hCheck Directory Size
du -sh <directory>Example:
du -sh DocumentsDisplay Running Processes
topTerminate a Process
bash kill <pid>Example:bash kill 1234
Network Commands
Check Network Configuration
ifconfigPing a Host
ping <hostname>Example:
ping google.comCheck Open Network Ports
bash netstat -an
File Permissions and Ownership
Change File Permissions
chmod <permissions> <file>Example:
chmod 755 script.shChange File Owner
bash chown <owner>:<group> <file>Example:bash chown user:staff file.txt
Miscellaneous
Search for Files
find <path> -name <filename>Example:
find / -name "*.txt"Search Inside Files
grep <pattern> <file>Example:
grep "search_term" file.txtCompress Files
zip <archive.zip> <file>Example:
zip archive.zip file.txtExtract Files
bash unzip <archive.zip>
Package Management
Install Homebrew (Package Manager)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Install a Package with Homebrew
bash brew install <package>Example:bash brew install wget
Git Commands
Clone a Repository
git clone <repository_url>Check Repository Status
git statusAdd Changes to Staging Area
git add <file>Add all changes:
git add .Commit Changes
git commit -m "commit message"Push Changes to Remote Repository
git pushPull Changes from Remote Repository
bash git pull