Show Menu
Cheatography

Linux General Purpose Cheat Sheet Cheat Sheet (DRAFT) by

This cheat sheet covers essential Linux commands and tips for general-purpose tasks, including file management, process handling, networking, permissions, and system monitoring. Designed to help beginners and intermediate users quickly access the most useful Linux terminal commands, it includes examples and key options to enhance productivity in a Linux environment.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Firewalld

Show all zones
firewall-cmd --get-zones
Show all zones and settings
firewall-cmd --list-all-zones
Allow port at zone
firewall-cmd --permanent --zone=<zone> --add-port=<port>/<protocol>
Reload settings
firewall-cmd --reload
Allow port from specific network
firewall-cmd --permanent --zone=<zone> --add-rich-rule='rule family="ipv4" source address="<network>" port protocol="<protocol>" port="<port>" accept'
Remove port from zone
firewa­ll-cmd --perm­anent --zone=<zo­ne> --remo­ve-­port=<po­rt>/<pr­oto­col>
Remove port from specific network
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="<network>" port protocol="<protocol>" port="<port>" accept
Allow traffic between interface
firewall-cmd --permanent --zone=<zone> --add-rich-rule='rule family="ipv4" source address="<interface>" accept'
After making any modifi­cations to firewall rules, it is necessary to reload the rules for the changes to take effect.

File, Folders and Permis­sions management

Remove file
rm -f <file>
Remove folder and its contents
rm -fr <folder>
Recurs­ively remove files matching regex patterns
find <directory> -regex '<extendend_regex>' -exec rm -f {} \;
Recurs­ively remove files by extension
find <directory> -iname '*.<extension>' -exec rm -f {} \;
Recurs­ively remove files older than N days
find <directory> -type f -mtime +<number_of_days> -exec rm -f {} \;
Cut or rename files or folders
mv <sources files/folder> <destination folder/file>
Copy files
cp <source files> <destination folder>
Copy folders
cp -r <folders> <destination folder>
Change permission of file/f­older
chmod <owner_octal><group_octal><other_octal> <file/folder>
Change permission of folder (Recur­sively)
chmod -R <owner_octal><group_octal><other_octal> <folder>
Change owner user and group of file/f­older
chown <us­er>:<gr­oup> <fi­le/­fol­der>
Change owner user and group of folder (Recur­sively)
chown -R <us­er>:<gr­oup> <fo­lde­r>
1 Check the octal permis­sions system at Octal Permis­sions session
2 You can set the maximum search depth when using
find
to remove files with the
-maxdepth N
option. This helps prevent unwanted recursive deletions. For example:
find <di­rec­tor­y> -maxdepth 1 ....

Networking

Check port commun­ication (telnet)
telnet <address> <port>
Check port commun­ication (netcat)
nc -zv <address> <port>
Open dummy port (netcat)
nc -lp <port>
Open TLS/SSL Port (openssl)
openssl s_server -accept <port> -cert <certificate_file> -key <key_file>
Test connection to TLS/SSL Port(o­penssl)
openssl s_client -connect <address>:<port>
Show TCP IPV4 Listening ports
ss -ltnp4 | grep <port>
Show TCP IPV6 Listening ports
ss -ltpn6 | grep <port>
Show all connection and ports
ss -putona
Show interfaces
ip a
Show routes
ip route
Show DNS properties
nslookup <DNS>
Show ip inform­ation
dig -x <ip> +all
Show route to destin­ation
traceroute <ip>

Octal Permis­sions

Read
4
Write
2
Execute
1
For multiple permis­sions, just add the octal values. Example: read(4) and execute(1) = 5.

More about it: Linux file permis­sions explained

Remote Access

Connect via SSH using password
ssh -p <po­rt> <us­ern­ame>@<ho­stn­ame­/ip>
Copy file from local to remote using SCP
scp -P <po­rt> <lo­cal­_fi­le_­pat­h> <us­ern­ame>@<ho­stn­ame­/ip>:<de­sti­nation folder­/fi­le>
Copy file from remote to local using SCP
scp -P <po­rt> <us­ern­ame>@<ho­stn­ame­/ip>:<fi­le_­pat­h> <de­sti­nation folder­/fi­le>
Copy file from local to remote using rsync
rsync -avz -e "ssh -p <po­rt>" <local file/f­old­er> <us­ern­ame>@<ho­stn­ame­/ip>:<de­sti­nation folder­/fi­le>
Copy file from remote to local using rsync
rsync -avz -e "ssh -p <po­rt>" <us­ern­ame>@<ho­stn­ame­/ip>:<fo­lde­r/f­ile> <de­sti­nation folder­/fi­le>
1 Prefer using rsync instead of SCP since it will be deprecated soon. Check references for more inform­ation.
2 For key authen­tic­ation with SSH, SCP or RSYNC add a
-i <ke­y_f­ile>
after the SSH or SCP command. I.e:
ssh -i /home/­foo­/ke­y.rsa ...
.

References
OpenSSH SCP deprec­ation in RHEL 9

User Management

Add user
useradd -s <sh­ell> -d <us­er_­hom­e> -m -U <us­ern­ame>
Add User to Group
usermod -aG <gr­oup­_na­me> <us­er_­nam­e>
Remove user from group
deluser <gr­oup­_na­me> <us­er_­nam­e>
Delete User
userdel -f -r <us­er_­nam­e>
Add group
groupadd <gr­oup­_na­me>
Delete group
groupdel <gr­oup­_na­me>
List user groups
groups <us­er_­nam­e>