Essential Linux Commands Cheat Sheet for Beginners

Zainul KhanZainul Khan
3 min read

Whether you're a student exploring Linux for the first time or a professional managing your Ubuntu server, having a handy reference can make all the difference. This blog post is designed to be your go-to cheat sheet for essential Linux commands, helping you get started quickly or improve your skills.

Here is your go-to cheat sheet for working with Linux.

Linux File and Directory Operations

ls: List directory contents

ls = List files

ls -l = Detailed list (permissions, owner, size, etc.)

ls -a = Include hidden files

cd: Change directory

cd /path/to/directory = Change to specified directory

cd .. = Move up one directory

cd ~ = Move to home directory

pwd = Print working directory

mkdir: Make directory

mkdir directory_name = Create a new directory

mkdir -p /path/to/directory = Create parent directories if they do not exist

rmdir: Remove empty directory

rmdir directory_name rm = Remove files or directories

rm file_name – Remove file

rm -r directory_name – Remove directory and its contents recursively

rm -f file_name – Force removal without prompting

cp: Copy files or directories

cp source_file destination_file = Copy file

cp -r source_directory destination_directory = Copy directory recursively

mv: Move or rename files or directories

mv source destination = Move or rename file or directory

touch = Create an empty file or update file timestamp

File Viewing and Editing

cat file_name = View file content

head file_name = default is first 10 lines

head -n 20 file_name = First 20 lines tail: Display the last few lines of a file

tail file_name = default is last 10 lines

tail -f file_name – Follow file changes in real time

nano file_name = Open file content in text editor

vim file_name or vi file_name = Advanced text editor

File Permissions and Ownership

chmod = Change file permissions

chmod 755 file_name = Set permissions (rwxr-xr-x)

chmod +x file_name = Add execute permission

chown: Change file owner and group

chown user:group file_name

System Information

uname = Print system information

uname -a = Detailed system information

df = Display disk space usage

df -h = Human-readable format

du = Estimate file and directory space usage

du -sh /path/to/directory = Summarize directory size

free: Display memory usage

free -h = Human-readable format

top = Display real-time system processes

htop = Enhanced version of top with a user-friendly interface (might need to install)

Process Management

ps = Display information about running processes

ps aux = Detailed list of processes top: Monitor system processes and resource usage

kill = Terminate a process

kill PID = Send SIGTERM to process

kill -9 PID = Forcefully kill process

pkill = Kill processes by name

pkill process_name

bg = Resume a suspended job in the background

fg = Bring a background job to the foreground

Networking

ping = Check connectivity to a host

ping hostname_or_IP ifconfig = Display or configure network interfaces (deprecated in favor of ip)

ip = Show/manipulate routing, devices, and tunnels

ip addr = Display IP addresses

ip link = Display network interfaces

netstat: Network statistics

netstat -tuln = List listening ports and services

curl: Transfer data from or to a server

curl http://example.com

wget: Download files from the web

wget http://example.com/file

Package Management (varies by distribution)

apt-get = Debian-based systems (Ubuntu, Debian)

sudo apt-get update = Update package list

sudo apt-get install package_name = Install a package

sudo apt-get upgrade = Upgrade installed packages

yum Red Hat-based systems (CentOS, Fedora)

sudo yum update = Update package list and installed packages

sudo yum install package_name = Install a package

tar -cvf archive_name.tar /path/to/directory = Create an archive

tar -xvf archive_name.tar = Extract an archive

gzip = Compress files

gzip file_name = Compress file

gunzip file_name.gz = Decompress file

zip and unzip = Compress and decompress zip files

zip archive_name.zip file1 file2 – Create a zip archive

unzip archive_name.zip – Extract zip archive

0
Subscribe to my newsletter

Read articles from Zainul Khan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Zainul Khan
Zainul Khan