Linux Cheatsheet
This page presents a list of commonly used commands and config files for Linux.
Categories:
Access this page by simply typing in "cs linux" in your browser address bar if you have bunnylol configured.
Commands
File & Directory Basics
# List files in the current directory.
ls
# List files in the current directory with details.
ls -alh
# Change current directory.
cd
# Show current directory.
pwd
# Create an empty directory.
mkdir
# Copy file.
cp <src-filename> <dst-filename>
# Copy directory.
cp -Rf <src-dirname> <dst-dirname>
# Move file or directory.
mv <src-filename> <dst-filename>
# Remove file.
rm <filename>
# Remove an empty directory.
rmdir <dirname>
# Remove a non-empty directory.
rm -Rf <dirname>
# Create a new empty file.
touch <filename>
# Find files.
find . -iname <filename-regex>
# Find all files.
find . -type f
File Content
# Print file content.
cat <filename>
# Search texts in file.
grep <text> <filename>
# Search regex pattern in file.
grep -e <regex-pattern> <filename>
# Show first few lines in file.
head -n <line-count> <filename>
# Show last few lines in file.
tail -n <line-count> <filename>
# Follow file changes.
tail -f <filename>
File Access
# Change file access. An example of access-code is 600.
chmod <access-code> <filename>
# Change file owner.
chown <owner>[:<group>] <filename>
Package & Compress
# Pack a directory into a tar file.
tar -cvf <tar-filename>.tar <dirname>
# Unpack a tar file.
tar -xvf <tar-filename>.tar
# Zip a file.
zip <zip-filename> file1 file2 file3 ...
# Unzip a file.
unzip <zip-filename>
Disk
# Show free disk spaces for each block device.
df -alh
# Display the disk usage of files under the current directory.
du -h ./*
# Show block devices.
lsblk
Process
# List process.
ps aux
# Kill a process with SIGTERM.
kill <pid>
# Kill a process with SIGKILL (the strongest killing signal).
kill -9 <pid>
# List all processes in a terminal UI.
top
# List all processes in an advanced terminal UI.
htop
Networking
# Download data from url.
curl <url>
# Download data from url to local file.
curl <url> -o <filename>
# List all ports opened.
netstat -an
# List network configuration.
ifconfig
# Ping network connectivity.
ping
User
# Add a new user.
sudo adduser <username>
# Delete a user.
sudo deluser <username>
Packages
# Install packages on ubuntu or debian.
sudo apt install <package-name>[=<version>]
# Uninstall packages from ubuntu or debian.
sudo apt-get --purge remove <package-name>
System
# Display information about your system.
uname -a
# Display Linux release information
lsb_release -a
# Show hostname.
hostname
# Reboot system now.
sudo reboot now
# Shutdown system now.
sudo shutdown -h now
Services
# List all units.
systemctl list-units
# List all service units.
systemctl list-units --type=service
# Start a service.
sudo systemctl start <service-name>
# Restart a service.
sudo systemctl restart <service-name>
# Stop a service.
sudo systemctl stop <service-name>
# Check a service status.
sudo systemctl status <service-name>
# Enable a service to start as system starts.
sudo systemctl enable <service-name>