Linux Cheat Sheet

Here is a Linux cheat sheet that includes commands for general, hardware, and performance information, as well as commands for managing users and groups and manipulating directories and files.

General Info
Hardware Info
Performance Info
User & Group Management
Directories & File Manipulation

Here is a cheat sheet of some common Linux commands that can be useful for various tasks, such as checking general information about the system, viewing hardware information, monitoring performance, managing users and groups, and manipulating directories and files. These commands have been tested on Amazon Linux 2, but they should also work on other Linux distributions.

General Info

CommandDescription
uname -aDisplay the Linux kernel version, the name and version of the operating system, and other system information.
hostnameDisplay the hostname of the system.
uptimeDisplay the system uptime and the load averages for the past 1, 5, and 15 minutes.
dateDisplay the current date and time.
calDisplay a calendar for the current month.

Hardware Info

CommandDescription
lscpuDisplay information about the CPU, such as the architecture, number of cores, and clock speed.
lsblkList the block devices (hard drives, SSDs, etc.) attached to the system.
lspciList the PCI devices (graphics cards, network cards, etc.) attached to the system.
lsusbList the USB devices attached to the system.

General Info

# Show hostname
hostname

# Show IP Address
hostname -I

# Show who you are logged in as
whoami

# Show active user sessions
w

# Show uptime
uptime

# Show reboot history
last reboot

# Show date
date

# Show calendar
cal

Hardware Info

# Show messages in kernal ring buffer
dmesg

# Show CPU details
cat /proc/cpuinfo

# Show memory details
cat /proc/meminfo

# Show memory usage
free -h

Performance Info

# Show top processes (ctrl+c to cancel out)
top

# Show all open files
lsof

# Show all files open by a user
lsof -u user

User & Group Management

# Show last users who logged in
last

# Show users logged in now
users

# Show users logged in now, more info
who

# Show users logged in and commands being run
w

# Show all  users configured on the system
awk -F: '{print $1}' /etc/passwd

# Show all users configured on the system, more info
getent passwd
getent passwd | grep ec2-user

# Create new user
adduser pete 'password1'

# Delete a user (+ delete homefolders)
sudo userdel pete

# Show all groups
groups

# Show all groups, more info
getent group

# Create new group
sudo groupadd it

# Add user to group
sudo usermod -aG it pete

# Show users within a group
getent group it

# Show primary/secondary groups
id ec2-user

# Delete a group
sudo groupdel it

Directories & File Manipulation

# Show all files in current directory (detailed)tou
ls -al

# Show present working directory
pwd

# Create a new directory
sudo mkdir home/ec2-user stuff

# Delete above directory (-rf for without prompt)
sudo rm -r home/ec2-user stuff

# Create a new file
sudo touch home/ec2-user/stuff/newfile.txt

# Delete above file
sudo rm home/ec2-user/stuff/newfile.txt

# Copy a file
sudo cp home/ec2-user/stuff/file.txt home/ec2-user/stuff/copied_file.txt

# Move or rename a file
sudo mv home/ec2-user/stuff/file.txt home/ec2-user/more_stuff/file.txt