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.
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
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)
Command Line Tools and Utilities
curl - Transfer data from or to a server, supporting various protocols.
curl http://example.com
curl -O http://example.com/file.zip
(download file)
wget - Retrieve files from the web, supporting HTTP, HTTPS, and FTP.
wget http://example.com/file.zip
wget -c http://example.com/file.zip
(resume download)
tar - Archive files.
tar -cvf archive.tar file1 file2
(create archive)
tar -xvf archive.tar
(extract archive)
Managing Processes
ps - Report a snapshot of current processes.
ps aux
ps -ef
(detailed format)
top - Display Linux tasks.
top
kill - Terminate a process using its PID.
kill 1234
kill -9 1234
(force kill)
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)
System Maintenance
df - Report file system disk space usage.
df -h
(human-readable format)
df -T
(show file system type)
du - Estimate file space usage.
du -h
(human-readable format)
du -s
(summarize usage)
free - Display amount of free and used memory in the system.
free -h
(human-readable format)
uptime - Tell how long the system has been running.
uptime
uname - Print system information.
uname -a
(all information)
Learn Python & QA Automation With Self-Paced Video Courses
Python | Selenium WebDriver | API Testing | SQL | Robot Framework | BDD (Cucumber)
Stay connected with news and updates!
Join our mailing list to receive the latest news and updates from our team.
Don't worry, your information will not be shared.
We hate SPAM. We will never sell your information, for any reason.