Dive into our comprehensive Linux Commands Cheat Sheet crafted for beginners and experts alike. This guide categorizes essential commands, making it effortless to find and execute the operations you need. Whether you’re managing files, users, or networking, this cheat sheet is your go-to reference to maneuver through the Linux terminal efficiently.
Basic Linux Commands
Command
Description
ls
Display the contents of the current directory
pwd
Show the current directory path
touch filename
Create a new empty file
mkdir dirname
Create a new directory
rmdir dirname
Remove a directory
cp source dest
Copy files or directories
mv old new
Move or rename files or directories
rm filename
Remove a file
cat filename
Display the contents of a file
head filename
Show the first 10 lines of a file
tail filename
Show the last 10 lines of a file
more filename
Display file contents page by page
less filename
Display file contents and allow scrolling
grep pattern file
Search for a pattern within a file
find dir -name pattern
Search for files under dir
who
Show who is logged on
whoami
Display current username
ps
Show current processes
kill pid
Terminate process with given pid
File Permission Commands
Command
Description
chmod permissions filename
Change file permissions
chown user:group filename
Change file ownership and group
chgrp group filename
Change file group
umask
Set default permissions for new files
getfacl filename
Display file permissions in ACL format
setfacl
Set file permissions using ACLs
ls -lh
Display permissions in human-readable format
stat filename
Display detailed file permissions
Environment Variables Commands
Command
Description
export VARIABLE=value
Set a new environment variable
unset VARIABLE
Remove an environment variable
printenv VARIABLE
Display the value of a variable
printenv
Display all environment variables
set
Display all environment variables and functions
env
Display all environment variables
VARIABLE=value command
Set environment variable for the duration of the command
User Management Commands of Linux
Command
Description
useradd username
Create a new user
passwd username
Set or change user password
userdel username
Delete a user account
groupadd groupname
Create a new group
groupdel groupname
Delete a group
usermod -aG groupname username
Add user to a group
gpasswd -a username groupname
Add user to a group
gpasswd -d username groupname
Remove user from a group
getent passwd
List all users
getent group
List all groups
id username
Display user and group IDs
w
Show who is logged on and what they are doing
Networking Commands
Command
Description
ifconfig
Display network configuration
ip addr show
Display IP addresses and network details
ping hostname
Test connectivity to a host
traceroute hostname
Trace the route to a host
netstat
Display network connections, routing tables, and interface statistics
ss
Display socket statistics
telnet hostname
Connect to a host via Telnet
ssh username@hostname
Securely connect to a host via SSH
scp source_file user@host:destination
Securely copy files over the network
ftp hostname
Connect to a FTP server
wget URL
Download files from the web
curl URL
Transfer data to or from a server
nslookup domain
Query DNS lookup name
dig domain
Query DNS
Process Commands
Command
Description
pstree
Display a tree of processes
pkill pattern
Terminate processes with names matching pattern
killall process_name
Terminate all processes with the given name
lsof
List open files and the processes that opened them
vmstat
Display virtual memory statistics
uptime
Show system uptime and load average
dmesg
Display kernel ring buffer messages
systemctl status service_name
Check the status of a system service
journalctl
Query the systemd journal
mpstat
Display CPU statistics
iostat
Display disk I/O statistics
sar
Collect and report system activity information
VI Editing Commands
Command
Description
v
Start visual mode for text selection
y
Yank (copy) selected text
p
Paste copied text
:%s/old/new/g
Replace all occurrences of ‘old’ with ‘new’
:w filename
Save file as ‘filename’
:e filename
Open file ‘filename’ for editing
:q
Quit VI (without saving)
:q!
Quit VI (without saving) and discard changes
:wq
Save and quit VI
:set number
Show line numbers
:set spell
Turn on spell checking
G
Go to the end of file
gg
Go to the beginning of file
:w !sudo tee %
Save file when forgetting to open editor with sudo
Additional Insight: Understanding the Linux File Hierarchy
The Linux File Hierarchy Structure (FHS) defines the directory structure and directory contents in Unix and Unix-like operating systems.
/bin
Essential command binaries that are required to troubleshoot or recover the system
/boot
Static files of the boot loader
/dev
Device files
/etc
Host-specific system configuration
/home
User home directories
/lib
Essential shared libraries and kernel modules
/media
Mount point for removable media
/mnt
Mount point for temporarily mounted filesystems
/opt
Optional application software packages
/sbin
Essential system binaries
/srv
Data for services provided by this system
/tmp
Temporary files
/usr
Secondary hierarchy for read-only user data; contains the majority of multi-user utilities and applications
/var
Variable data including logs, spool files, and temporary e-mail files
More Information on Commands
To delve deeper and gather more information about any Linux command, you can use the man command followed by the name of the command you are interested in. For example:
man ls
This will display the manual page for the ls command, providing detailed explanations and options associated with the command. The man pages are a treasure trove of information, helping you explore the nuances and powerful features of Linux commands.
This Linux Commands Cheat Sheet is designed to be a handy reference, aiding you in your journey through the Linux environment. Whether you’re a newbie starting out or a seasoned professional, this cheat sheet is sure to become a valuable resource in your toolkit.
Keep exploring, and you’ll continue to uncover the boundless possibilities Linux commands unfold. Remember, mastering the terminal is the first step towards becoming proficient in the Linux world. Happy coding!