Linux Commands Cheat Sheet
Linux Commands Cheat Sheet
Did you know that there are literally hundreds of Linux commands? Even on a bare-
bones Linux server install there are easily over 1,000 different commands.
The interesting thing is that most people only need to use a very small subset of
those commands. Below you’ll find a Linux “cheat sheet” that breaks down some of
the most commonly used commands by category.
To get your own PDF and printable copy, scroll to the bottom of the page.
Enjoy!
1 – SYSTEM INFORMATION
# Display Linux system information
uname -a
uname -r
cat /etc/os-release
uptime
hostname
# Display all local IP addresses of the host.
hostname -I
last reboot
date
cal
whoami
2 – HARDWARE INFORMATION
# Display messages in kernel ring buffer
dmesg
cat /proc/meminfo
# Display free and used memory ( -h for human readable, -m for MB, -g for GB.)
free -h
lspci -tv
lsusb -tv
dmidecode
hdparm -i /dev/sda
top
htop
mpstat 1
vmstat 1
iostat 1
# Display the last 100 syslog messages (Use /var/log/syslog for Debian based systems.)
tcpdump -i eth0
# Monitor all traffic on port 80 ( HTTP )
lsof
lsof -u user
# Display free and used memory ( -h for human readable, -m for MB, -g for GB.)
free -h
watch df -h
id
# Display the last users who have logged onto the system.
last
# Show who is logged into the system.
who
groupadd test
# Create an account named john, with a comment of "John Smith" and create the user's home
directory.
userdel john
ls -al
# Create a directory
mkdir directory
rm file
rm -r directory
rm -f file
rm -rf directory
cp file1 file2
cp -r source_directory destination
# Rename or move file1 to file2. If file2 is an existing directory, move file1 into
directory file2
mv file1 file2
ln -s /path/to/file linkname
# Create an empty file or update the access and modification times of file.
touch file
cat file
less file
head file
tail file
# Display the last 10 lines of file and "follow" the file as it grows.
tail -f file
6 – PROCESS MANAGEMENT
# Display your currently running processes
ps
ps -ef
top
htop
kill pid
killall processname
bg
fg
fg n
7 – FILE PERMISSIONS
PERMISSION EXAMPLE
U G W
LEGEND
U = User
G = Group
W = World
r = Read
w = write
x = execute
- = no access
8 – NETWORKING
# Display all network interfaces and IP address
ip a
ping host
whois domain
dig domain
dig -x IP_ADDRESS
host domain
hostname -i
hostname -I
# Download http://domain.com/file
wget http://domain.com/file
netstat -nutlp
tar xf archive.tar
# Install package.
rpm -i package.rpm
# Remove/uninstall package.
cd sourcecode
./configure
make
make install
11 – SEARCH
# Search for pattern in file
locate name
12 – SSH LOGINS
# Connect to host as your local username.
ssh host
ssh user@host
# Connect to host using port
13 – FILE TRANSFERS
# Secure copy file.txt to the /tmp folder on server
# Copy all files and directories recursively from server to the current system's /tmp
folder.
# Synchronize files/directories between the local and remote system with compression
enabled
14 – DISK USAGE
# Show free and used space on mounted filesystems
df -h
# Show free and used inodes on mounted filesystems
df -i
fdisk -l
# Display disk usage for all files and directories in human readable format
du -ah
du -sh
15 – DIRECTORY NAVIGATION
# To go up one level of the directory tree. (Change into the parent directory.)
cd ..
cd
cd /etc
16 – SECURITY
# Change the current user's password.
passwd
sudo -i
sudo -s
sudo -l
visudo
getenforce
# Display SELinux details such as the current SELinux mode, the configured mode, and the
loaded policy.
sestatus
# Change the current SELinux mode to Permissive. (Does not survive a reboot.)
setenforce 0
# Change the current SELinux mode to Enforcing. (Does not survive a reboot.)
setenforce 1
# Set the SELinux mode to enforcing on boot by using this setting in the
/etc/selinux/config file.
SELINUX=enforcing
# Set the SELinux mode to permissive on boot by using this setting in the
/etc/selinux/config file.
SELINUX=permissive
# Set the SELinux mode to disabled on boot by using this setting in the
/etc/selinux/config file.
SELINUX=disabled
dmesg
journalctl
journalctl -u servicename