There are hundreds - possibly thousands - commands available in Linux. Remembering every command is not possible and it can be quite daunting for a novice user. The good news is that you don't need to remember each command. Only a very small subset of those commands are used on a day-to-day basis.
This cheat sheet offers a set of commands that you can use for quick reference.
BASIC
# Print a history list of all commands.
history
# Clear the terminal.
clear
# Shut down the system.
shutdown -h now
# Shut down the system.
poweroff
# Restart the system.
reboot
# List all environment variables.
printenv
# Set a temporary environment variable.
export MY_SITE="alishoff.com"
# Display the value of a variable.
echo $MY_SITE
# Remove a variable.
unset MY_SITE
# Define temporary aliases in your shell session.
alias ls="ls -la"
# List all aliases you have in your shell session.
alias
# Remove an alias from the already defined aliases.
unalias ls
# Display the manual page of any other command.
man mkdir
# Repeats your previous command.
!!
SYSTEM INFORMATION
# Get system information including operating system, kernel and release version.
hostnamectl
# Display the current system date and time.
date
# Show this month's calendar.
cal
# Display the hostname of the system.
hostname
# Display all local IP addresses of the host.
hostname -I
# Display the network address of the host name.
hostname -i
# Display Linux system information.
uname -a
# Display kernel release information.
uname -r
# Show how long the system has been running + load.
uptime
# Who you are logged in as.
whoami
HARDWARE INFORMATION
# Display messages in kernel ring buffer.
dmesg
# Display CPU information.
cat /proc/cpuinfo
# Display memory information.
cat /proc/meminfo
# Display free and used memory (-h for human readable, -m for MB, -g for GB).
free -h
# Display PCI devices.
lspci -tv
# Display USB devices.
lsusb -tv
# Display DMI/SMBIOS (hardware info) from the BIOS.
dmidecode
PERFORMANCE MONITORING AND STATISTICS
# Display and manage the top processes.
top
# Interactive process viewer (top alternative).
htop
# Display processor related statistics.
mpstat 1
# Display virtual memory statistics.
vmstat 1
# Display I/O statistics.
iostat 1
# List all open files on the system.
lsof
# List files opened by user.
lsof -u user
USER INFORMATION AND MANAGEMENT
# Display the user and group ids of your current user.
id
# Show who is logged into the system.
who
# Display currently logged in users in the system.
w
# Create a new group.
groupadd groupname
# Remove a group.
groupdel groupname
# Create a new user.
useradd username
# Create an account named john, with a comment of "John Smith" and create the user's home directory.
useradd -c "John Smith" -m john
# Delete the username account.
userdel -r username
# Change the user account information including group, home directory, shell and expiration date.
usermod [option] username
# Add the username account to the groupname group.
usermod -aG groupname username
# Change the password for a user.
passwd username
FILE AND DIRECTORY COMMANDS
# View the type of any file.
file filename
# List all files and directories in the current working directory by default.
ls
# List all files and directories including hidden files and other information like permissions, size and owner.
ls -la
# List all files and directories from /usr/bin directory.
ls -la /usr/bin
# List all files and directories from home directory of current user and /usr/bin directory.
ls -la ~ /usr/bin
# Display the present working directory.
pwd
# Change the directory to the home directory.
cd
# Change the directory to one level up.
cd ..
# Change the directory to /var/www.
cd /var/www
# Change the directory to the last working directory.
cd -
# Change the directory to the home directory of username. For example, cd ~bob.
cd ~username
# Create a directory.
mkdir directory
# Remove (delete) file.
rm file
# Remove the directory and its contents recursively.
rm -r directory
# Force removal of file without prompting for confirmation.
rm -f file
# Forcefully remove directory recursively.
rm -rf directory
# Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2.
mv file1 file2
# Move file1 and file2 to dir1.
mv file1 file2 dir1
# Create symbolic link to linkname.
ln -s /path/to/file linkname
# Create an empty file or update the access and modification times of file.
touch file
# Display the content of the file.
cat file
# Create a new file with the text you type after.
cat > file.txt
# Combine two files named file1 and file2 and store the output in a new file file3.
cat file1 file2 > file3
# Browse through a text file.
less file
# Display all users.
less /etc/passwd
# Display the first 10 lines of file.
head file
# Display the last 10 lines of file.
tail file
# Display the last 10 lines of file and "follow" the file as it grows.
tail -f file
# Open a file (or create new one) in nano text editor.
nano file.txt
# Open a file (or create new one) in vim text editor.
vim file.txt
PROCESS MANAGEMENT
# Display your currently running processes.
ps
# Display all the currently running processes on the system.
ps -ef
# Display process information for processname.
ps -ef | grep processname
# Kill process with process ID of pid.
kill pid
# Kill all processes named processname.
killall processname
# Get the PID of any process.
pidof processname
# Start program in the background.
program &
# Display stopped or background jobs.
bg
# Brings the most recent background job to foreground.
fg
# Brings job n to the foreground.
fg n
FILE PERMISSIONS
U G W rwx rwx rwx chmod 777 filename rwx rwx r-x chmod 775 filename rwx r-x r-x chmod 755 filename rw- rw- r-- chmod 664 filename rw- r-- r-- chmod 644 filename U = User G = Group W = World r = read (4) w = write (2) x = execute (1) - = no access
# Assign full (read, write and execute) permission to everyone.
chmod 777 filename
# Assign full permission to the directory and all sub-directories.
chmod -R 777 dirname
# Assign full permission to the owner, and read and write permission to group and others.
chmod 766 filename
# Remove the execution permission of any file.
chmod -x filename
# Change the ownership of a file.
chown username filename
# Change the owner and group ownership of a file.
chown user:group filename
# Change the owner and group ownership of the directory and all sub-directories.
chown -R user:group dirname
NETWORKING
# Display all network interfaces and IP address.
ip a
# Display eth0 address and details.
ip addr show dev eth0
# Query or control network driver and hardware settings.
ethtool eth0
# Send ICMP echo request to host.
ping host
# Download http://domain.com/file.
wget http://domain.com/file
ARCHIVES
# Create tar named archive.tar containing directory.
tar cf archive.tar directory
# Extract the contents from archive.tar.
tar xf archive.tar
# Create a gzip compressed tar file name archive.tar.gz.
tar czf archive.tar.gz directory
# Extract a gzip compressed tar file.
tar xzf archive.tar.gz
# Create a tar file with bzip2 compression.
tar cjf archive.tar.bz2 directory
# Extract a bzip2 compressed tar file.
tar xjf archive.tar.bz2
# Compress a single file to a zip.
zip filename.zip filename
# Compress multiple files to a zip.
zip filename.zip file1.txt file2.txt file3.txt
# Add a file to a zip file.
zip -u filename.zip file4.txt
# Delete a file from a zip file.
zip -d filename.zip file4.txt
# Display the content of zip archive file.
unzip -l filename.zip
# Unzip a file.
unzip filename.zip
# Unzip a file to a specific directory.
unzip filename.zip -d /dirname
SEARCH
# Search for pattern in file.
grep pattern file
# Search recursively for pattern in directory.
grep -r pattern directory
# Find files in /home/john that start with "prefix".
find /home/john -name 'prefix*'
# Find files larger than 100MB in /home.
find /home -size +100M
SSH LOGINS
# Connect to host as your local username.
ssh host
# Connect to host as user.
ssh user@host
# Connect to host using port.
ssh -p port user@host
FILE TRANSFERS
# Copy the content of file1 to file2.
cp file1 file2
# Copy file1 and file2 to dir1.
cp file1 file2 dir1
# Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents of source_directory.
cp -r source_directory destination
# Secure copy file.txt to the /tmp folder on server.
scp file.txt server:/tmp
# Copy *.html files from server to the local /tmp folder.
scp server:/var/www/*.html /tmp
# Copy all files and directories recursively from server to the current system's /tmp folder.
scp -r server:/var/www /tmp
DISK USAGE
# Show free and used space on mounted filesystems.
df -h
# Show free and used inodes on mounted filesystems.
df -ih
# Display disks partitions sizes and types.
fdisk -l
# Create a new partition on /dev/sda device.
fdisk /dev/sda
# Format the partition named /dev/sda1.
mkfs.ext4 /dev/sda1
# Check and repair a filesystem for any error.
fsck.ext4 /dev/sda1
# Mount any partition to any directory.
mount /dev/sda1 /mnt
# Display disk usage for all files and directories in human readable format.
du -ah
# Display total disk usage off the current directory.
du -sh
PACKAGE MANAGEMENT
# Install the package on Debian based distributions.
apt-get install packagename
# Remove a package on Debian based distributions.
apt-get remove packagename
# Get a list of all packages on Debian based distributions.
dpkg -l | grep -i installed
# Install .deb package.
dpkg -i packagename.deb
# Update the repository on Debian based distributions.
apt-get update
# Upgrade a specific package on Debian based distributions.
apt-get upgrade packagename
# Remove all unwanted packages on Debian based distributions.
apt-get autoremove