Linux/Mac Command Line Cheat Sheet
Access this comprehensive Command Line cheat sheet for quick reference to essential commands across different operating systems. From file management and navigation to process control and advanced shortcuts, this guide helps both beginners and seasoned users streamline tasks and boost productivity. Ideal for anyone looking to enhance their command line skills and efficiency.
📋 Table of Contents
Command Line Cheat Sheet
Navigating the File System
pwd - Print the current working directory.
pwd
ls - List directory contents, showing files and subdirectories.
ls -l
ls -a
cd - Change the current directory to the specified path.
cd /home/user
cd .. (move up one directory)
touch - Create a new empty file.
touch newfile.txt
clear - Clear the terminal screen.
clear
▼ Show more commands
File and Directory Management
mkdir - Create new directories.
mkdir new_folder
mkdir -p new_folder/nested_folder (create nested directories)
rm - Remove files or directories.
rm file.txt
rm -r folder (remove directory and its contents)
mv - Move or rename files and directories.
mv old_name.txt new_name.txt (rename a file)
mv file.txt /new/location/ (move file to a new location)
cp - Copy files or directories.
cp file.txt copy_of_file.txt (copy a file)
cp -r dir1 dir2 (copy a directory)
Viewing and Editing Files
cat - Concatenate and display file content.
cat file.txt
cat file1.txt file2.txt (display multiple files)
nano - Simple text editor for basic editing tasks.
nano file.txt
nano /path/to/file.txt
less - View the content of a file one screen at a time.
less file.txt
head - Output the first part of files.
head file.txt (first 10 lines)
head -n 20 file.txt (first 20 lines)
tail - Output the last part of files.
tail file.txt (last 10 lines)
tail -n 20 file.txt (last 20 lines)
tail -f file.txt (follow file changes)
Searching and Filtering Text
grep - Search text using patterns within files.
grep "search_term" file.txt
grep -i "search_term" file.txt (case insensitive)
grep -r "search_term" /path/to/directory (recursive search)
grep -ri "search_term" /path/to/directory (recursive search that is case insensitive)
grep -rl "search_term" /path/to/directory (only show file names and not the content)
find - Search for files in a directory hierarchy.
find /path -name "filename"
find . -type f -name "*.txt" (find all .txt files)
awk - Pattern scanning and processing language.
awk '{print $1}' file.txt (print first column)
sed - Stream editor for filtering and transforming text.
sed 's/old/new/g' file.txt (replace text)
Scripting Basics
bash - Execute a bash script to automate tasks.
bash script.sh
bash -x script.sh (debug mode)
sh - Execute a shell script.
sh script.sh
sh -v script.sh (verbose mode)
Command Line for Networking
ping - Send ICMP ECHO_REQUEST to network hosts to test connectivity.
ping google.com
ping -c 4 google.com (limit to 4 packets)
ssh - OpenSSH SSH client for remote login to another host.
ssh user@hostname
ssh -i ~/.ssh/id_rsa user@hostname (use specific key)
Command Line Tools and Utilities
tar - Archive files.
tar -cvf archive.tar file1 file2 (create archive)
tar -xvf archive.tar (extract archive)
💡 Commands & Examples
Explore practical command examples with real-world use cases. These examples complement the cheat sheet above and demonstrate how to combine commands for powerful workflows.