Linux_Commands_Cheatsheet_V1.01
Linux_Commands_Cheatsheet_V1.01
COMMANDS
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.
man ls
Example:
The man pages are navigated usingless
the command with shortcuts:
q : Quit less .
type rm
: Check is a shell built-in or an executable file.
if
Example:rm is a shell
iscd/usr/bin/rm
built-in.
type cd : Check
if
Example:help cd
Linux Commands 1
Cheatsheet
: Get help for executable commands.
command --help
Linux Commands 2
Cheatsheet
Example:rm --help
Searching Man
uname in all man pages.
Pages
man -k uname : Search
for
apropos passwd
: Search passwd related man pages.
for
Keyboard Shortcuts
TAB TAB: Display all commands or filenames starting with writ ten
letters.
CTRL + L: Clear the current line. CTRL + D: Close the shell.
CTRL + U: Cut the current line.
CTRL + A: Move cursor to start of the line. Ctrl + E: Move cursor
to the end of the line. CTRL + C: Stop the current command.
CTRL + Z: Sleep the running program. CTRL + ALT + T: Open a
terminal.
Bash History
history : Display the history.
echo $HISTFILESIZE : Print the number of commands saved in the history file.
Linux Commands 3
Cheatsheet
!abc:p : Print the last command starting with.
abc
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
Linux Commands 4
Cheatsheet
sudo apt install tree
: Installs tree command
the
Using
Tree
tree directory/ : Example:tree .
The ls Command
Usage:ls [OPTIONS] [FILES]
Listing Directories
,
ls ls . : Current directory
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
Linux Commands 5
Cheatsheet
File Timestamps and Date
ls -lu : Access timeatime
( )
cal
, cal 2021 , : Calendars
cal 7 2021
: Previous, current, next month
cal -3
date --set="2 OCT 2020 18:00:00" : Set date/time
Sorting with ls
ls -l : Sorted by
name
, newest first
ls -lt : Sorted bymtime
: Reverse order
ls -ltu --reverse
Linux Commands 6
Cheatsheet
Displaying File
Contents
cat filename: Display content
Less Shortcuts
h : Help
q : Quit
Monitoring Commands
watch -n 3 ls -l : Refresh every 3 seconds
Linux Commands 7
Cheatsheet
: Create
touch filename a new file or update timestamps.
Creating Directories
mkdir dir1 : Create a new directory.
: Create
mkdir -p mydir1/mydir2/mydir3 nested directories.
The cp Command
Copy files and
directories:
to file2 .
cp file1 file2 : Copy file1
The mv Command
Move or rename files and directories:
The rm Command
Remove files and directories:
Linux Commands 8
Cheatsheet
rm file1 : Remove a file.
tail -n 2 /etc/passwd /etc/shadow > all.txt 2>&1 : Redirect all to one file.
Linux Commands 9
Cheatsheet
sudo updatedb: Update the database.
: Find
locate filename a file by name.
:
which command Show command path.
fin
d
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.
Linux Commands 1
Cheatsheet 0
strings binary_file : Examplestrings /bin/ls .
Config File
VIM settings:~/.vimrc .
Commands
i
, I , , , : Enter Insert Mode.
a A o
:w!
, :q! , , : Save/quit commands in Last Line Mode.
:wq! :e!
x
, dd , , , , , , : Editing commands in Command Mode.
ZZ u G $ 0 ^
/string
, ?string , n , N : Search commands in Command Mode.
Navigatio
n
: Switch between files.
Ctrl+w
Account Management
## Account Management
/etc/passwd # users and info:
/etc/shadow # users' passwords
/etc/group # groups
Linux Commands 1
Cheatsheet 0
## User Commands
useradd [OPTIONS] username # Create user.
usermod [OPTIONS] username # Modify user.
userdel -r username # Delete user.
## 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
Legen (user) (group (others (all) (read) (write),
d: , ), ), , ,
u g o a r w x
(execute), (no access).
Displaying
Permissions
Linux Commands 11
Cheatsheet
ls -l /etc/passwd : View file permissions.
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 .
Group:
Both:
Linux Commands 12
Cheatsheet
.
ssh -p 22 username@server_ip
t
ssh -p 22 -l username server
ername
ssh -v -p 22 username@server
r detailed information
# Ubuntu
sudo systemctl status ssh# C
sudo systemctl stop ssh# Sto
Linux Commands 13
Cheatsheet
File Attributes
Display:lsattr filename .
Processes
Process Viewing
type rm : Check ifrm is built-in or executable.
ps -ef
, ps aux , ps aux | less: System processes.
top
shortcut h for space for d for delay, etc.
s: help, refresh,
Killing Processes ,
pkill process_name killall process_name
kill -l : List
signals.
Linux Commands 14
Cheatsheet
: Send specific signal.
: Kill by name.
: Send signals.
: Kill using .
kill $(pidof process_name) pidof
Linux Commands 15
Cheatsheet
Background and Foreground Management
command & : Run in background.
Networking
Getting Network Interface Information
ifconfig : Enabled interfaces.
: Only IPv4
ip -4 address info.
: L2 info, including MAC.
ip -6 address
ip link show , : Only IPv6
info. : Default gateway.
route , ip link show dev enp0s3
systemd-resolve --status
: DNS servers.
Setting Network Interfaces
: Disable interface.
ifconfig enp0s3 down , ip link set enp0s3 down
: Enable interface.
ifconfig enp0s3 up , ip link set enp0s3 up
ifconfig -a
, ip link show dev enp0s3 : Check
status. : Set IP.
ifconfig enp0s3 192.168.0.222/24 up , ip address add 192.168.0.112/24 dev enp0s3
: Secondary IP.
ifconfig enp0s3:1 10.0.0.1/24
Linux Commands 16
Cheatsheet
route del default gw ip route del default ip route add default via
, , : Default
gatewa
ifconfig enp0s3 hw ether , ip link set dev enp0s3 address : Change MAC.
y.
ssh -p 22 username@s
t
ssh -p 22 -l usernam
ername
ssh -v -p 22 usernam
r detailed informati
# Ubuntu
sudo systemctl statu
sudo systemctl stop
# Ubuntu
sudo apt update && sudo apt install openssh-server openssh-cl
ient
# CentOS
sudo dnf install openssh-server openssh-clients
Linux Commands 15
Cheatsheet
Server Connection
# Ubuntu
sudo systemctl status ssh# Check SSH status
sudo systemctl stop ssh# Stop SSH service
Linux Commands 16
Cheatsheet
sudo systemctl restart ssh # Restart SSH service
sudo systemctl enable ssh# Enable SSH to start on boot
sudo systemctl is-enabled ssh# Check if SSH is enabled on b
oot
# 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
Linux Commands 17
Cheatsheet
# Copy local file to remote host scp a.txt
scp -P 2288 a.txt # Custom port
RSYNC Commands
Linux Commands 18
Cheatsheet
# Exclude specific file types during transfer rsync -av --
exclude='*.mkv' /source/ /dest/
# Install wget
sudo apt install wget # Ubuntu
sudo dnf install wget # CentOS
Linux Commands 1
Cheatsheet 8
# Check if port 80 is open netstat -tupan | grep :80
LSOF Commands
# List open files
lsof
Linux Commands 1
Cheatsheet 9
# Scan Specific Ports
nmap -p 20,22-100,443,1000-2000 192.168.0.1
# 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.
Linux Commands 2
Cheatsheet 0
Install from .deb:
sudo dpkg -i package.deb
Find by name:
package: Remove
sudo dpkg -r package
package:
Purge package:
sudo dpkg -P package
APT
Update index:
sudo apt update
List upgradable:
sudo apt list --upgradable
dependencies:sudo apt
Clean
clean
cache:
Search:
installed:
Linux Commands 21
Cheatsheet
crontab -e # Edit crontab crontab -l # List tasks crontab -r #
# Schedule Format:
* * * * * command # Every minute
15 * * * * command # Hourly
30 18 * * * command # Daily
3 22 * * 1 command # Weekly
10 6 1 * * command # Monthly @yearly command # Yearly @reboot
command # At reboot
CPU Information
Memory Information
Linux Commands 22
Cheatsheet
lspci es # PCI buses and connected devic
lspci | grep -i wireless
lspci | grep -i vga
lsusb
lsusb -v # USB controllers and devices
# Verbose output
Storage Devices
Network Devices
lshw -C network
iw list # Wi-Fi cards
iwconfig # Wi-Fi configuration
iwlist scan # Wi-Fi networks scan
Battery Power
Linux Commands 23
Cheatsheet
acpi -V # All ACPI info
# 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
Linux Commands 24
Cheatsheet
# Restart service
sudo systemctl restart nginx
# Mask service
sudo systemctl mask nginx
# Unmask service
sudo systemctl unmask nginx
Ubuntu
CentOS
Linux Commands 25
Cheatsheet
sudo systemctl status sshd # Check SSHD service status
sudo systemctl stop sshd sudo # Stop SSHD service
systemctl restart sshd sudo # Restart SSHD service
systemctl enable sshd ot # Enable SSHD to start on bo
sudo systemctl is-enabled sshd
n boot # Check if SSHD is enabled o
Security
Configuration . Apply changes by
PermitRootLogin no
Restrict
user access to specified users only:
Set client session intervals and maximum attempts for increased security
Bash Programming
Bash Aliases
Linux Commands 26
Cheatsheet
alias # List all aliases
alias name='command' # Create an alias
unalias name # Remove an alias
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
Linux Commands 27
Cheatsheet
$# "$*" # Number of positional arguments
gle string # All positional arguments as a sin
$?
# Exit status of the last command
Test Conditions
Linux Commands 28
Cheatsheet
name # Call
a function
Command Examples
Linux Commands 29
Cheatsheet