Linux Commands Cheatsheet V1.01
Linux Commands Cheatsheet V1.01
CHEAT SHEET
ANDREI DUMITRESCU
V1.01
HEEELLLOOOOO!
I’m Andrei Neagoie, Founder and Lead Instructor of the Zero To Mastery Academy.
After working as a Senior Software Developer over the years, I now dedicate 100% of my time to
teaching others in-demand skills, help them break into the tech industry, and advance their
careers.
In only a few years, over 1,000,000 students around the world have taken Zero To Mastery courses
and many of them are now working at top tier companies like Apple, Google, Amazon, Tesla, IBM,
Facebook, and Shopify, just to name a few.
This cheat sheet, created by our Linux Instructor (Andrei Dumitrescu) provides you with the key
Linux commands that you need to know and remember.
If you want to not only learn Linux but also get the exact steps to build your own projects and get
hired as a Developer or DevOps Engineer, then check out our Career Paths.
Happy Learning!
Andrei
MAN Pages
Use man command to view the manual for a command.
Example: man ls
The man pages are navigated using the less command with shortcuts:
q : Quit less .
Example: rm is /usr/bin/rm
Example: help cd
Keyboard Shortcuts
Bash History
history : Display the history.
echo $HISTFILESIZE : Print the number of commands saved in the history file.
Linux Paths
Paths
Absolute: Starts with /
.. : Parent directory
Changing Directories
cd : To user's home directory
cd /path_to_dir : To path_to_dir
Installing Tools
Using Tree
tree directory/ : Example: tree .
The ls Command
Usage: ls [OPTIONS] [FILES]
Listing Directories
ls , ls . : Current directory
Options
l : Long listing
1 : Single column
d : Directory information
h : Human-readable sizes
S : Sort by size
X : Sort by extension
R : Recursive listing
i : Inode number
Disk Usage
du -sh ~ : Size of home directory
Sorting with ls
ls -l : Sorted by name
Less Shortcuts
h : Help
q : Quit
Monitoring Commands
watch -n 3 ls -l : Refresh every 3 seconds
Creating Directories
mkdir dir1 : Create a new directory.
The cp Command
Copy files and directories:
The mv Command
Move or rename files and directories:
The rm Command
Remove files and directories:
Command Redirection
Redirect output and errors:
tail -n 10 /var/log/*.log > output.txt 2> errors.txt : Separate output and errors.
tail -n 2 /etc/passwd /etc/shadow > all.txt 2>&1 : Redirect all to one file.
find
Search with various options:
Options include type , name , iname , size , perm , links , atime , mtime , ctime ,
user , and group .
Options
n : Print line number.
i : Case insensitive.
v : Invert match.
R : Recursive search.
c : Count matches.
Config File
VIM settings: ~/.vimrc .
Commands
i , I , a , A , o : Enter Insert Mode.
Navigation
Ctrl+w : Switch between files.
Account Management
## Account Management
/etc/passwd # users and info:
/etc/shadow # users' passwords
/etc/group # groups
## Group Commands
groupadd group_name # Create group.
groupdel group_name # Delete group.
## Examples
useradd -m -d /home/john -c "C++ Developer" -s /bin/bash -G s
udo,adm,mail john # Example of creating a user.
usermod -aG developers,managers john # Example of modifying a
user.
Monitoring Users
## Commands
who -H # User info.
id # User info.
whoami # User info.
w # System usage.
uptime # System usage.
last # Login history.
last -u username # Login history for a specific user.
File Permissions
Understanding Permissions
Legend: (user), g (group),
u o (others), a (all), r (read), w (write), x
Displaying Permissions
Changing Permissions
chmod u+r filename : Add read to user.
Absolute Mode
chmod 777 filename : Set all permissions for all.
chmod 755 filename : Read & execute for group and others.
Special Permissions
SUID: chmod u+s executable_file .
UMASK
Display: umask .
Ownership
Owner: chown new_owner file .
Processes
Process Viewing
type rm : Check if rm is built-in or executable.
pgrep -l sshd , pgrep -f sshd , ps -ef | grep sshd : Check for sshd .
top shortcuts: h for help, space for refresh, d for delay, etc.
Killing Processes
kill -l : List signals.
Networking
Getting Network Interface Information
ifconfig : Enabled interfaces.
ifconfig enp0s3 192.168.0.222/24 up , ip address add 192.168.0.112/24 dev enp0s3 : Set IP.
ifconfig enp0s3 hw ether , ip link set dev enp0s3 address : Change MAC.
# Ubuntu
sudo apt update && sudo apt install openssh-server openssh-cl
ient
# CentOS
sudo dnf install openssh-server openssh-clients
Server Connection
# Ubuntu
sudo systemctl status ssh # Check SSH status
sudo systemctl stop ssh # Stop SSH service
# CentOS
sudo systemctl status sshd # Check SSH status
sudo systemctl stop sshd # Stop SSH service
sudo systemctl restart sshd # Restart SSH service
sudo systemctl enable sshd # Enable SSH to start on boot
sudo systemctl is-enabled sshd # Check if SSH is enabled on
boot
Security Configuration
Edit /etc/ssh/sshd_config and then apply changes by restarting SSH:
Remember to consult the man page ( man sshd_config ) for detailed configuration
options.
RSYNC Commands
# Install wget
sudo apt install wget # Ubuntu
sudo dnf install wget # CentOS
Use these commands to efficiently copy files and directories across systems and
for downloading content from the internet, ensuring data synchronization and
maintaining web accessibility.
LSOF Commands
# List open files
lsof
Use these commands to monitor network connections, check for open ports, and
view files opened by users or processes, especially for security and
troubleshooting.
# OS Detection
nmap -O 192.168.0.1
# Aggressive Scan
nmap -A 192.168.0.1
# Read Targets from File & Output to File without DNS Resolut
ion
nmap -n -iL hosts.txt -p 80 -oN output.txt
Only scan your own networks and systems, or those you have explicit permission
to test. Unauthorized scanning can be illegal.
APT
Update index: sudo apt update
CPU Information
Memory Information
Storage Devices
Network Devices
lshw -C network
iw list # Wi-Fi cards
iwconfig # Wi-Fi configuration
iwlist scan # Wi-Fi networks scan
Battery Power
# Backup MBR
dd if=/dev/sda of=~/mbr.dat bs=512 count=1
# Restore MBR
dd if=~/mbr.dat of=/dev/sda bs=512 count=1
# Clone partition
dd if=/dev/sda1 of=/dev/sdb2 bs=4M status=progress
Service Management
# Analyze boot process
systemd-analyze
systemd-analyze blame
# Service status
sudo systemctl status nginx.service
# Stop service
sudo systemctl stop nginx
# Start service
sudo systemctl start nginx
# Mask service
sudo systemctl mask nginx
# Unmask service
sudo systemctl unmask nginx
Ubuntu
CentOS
Security Configuration
To configure security settings, edit /etc/ssh/sshd_config . Apply changes by
restarting SSH. Key configurations include:
Port 2278
PermitRootLogin no
Set client session intervals and maximum attempts for increased security
Note: Consult the man page ( man sshd_config ) for detailed configuration options.
Bash Programming
Bash Aliases
Useful Aliases
alias c='clear'
alias cl='clear; ls; pwd'
alias root='sudo su'
alias ports='netstat -tupan'
alias sshconfig='sudo vim /etc/ssh/sshd_config'
alias update='sudo apt update && sudo apt dist-upgrade -y &&
sudo apt clean'
Bash Variables
Special Variables
$0, $1, $2, ..., ${10} # Script name & positional argument
s
Test Conditions
Command Examples
Combine these constructs to write effective bash scripts for task automation and
system management.