Navigation
pwd # print current directory
ls -lah # list files with details
cd /var/www # change directory
cd ~ # go to home directory
cd - # go to previous directory
Files and directories
touch file.txt # create empty file
mkdir -p path/to/dir # create nested directories
cp source dest # copy files
mv old new # move or rename
rm file.txt # delete file
rm -rf directory # delete directory (careful!)
cat file.txt # print file contents
less file.txt # scroll through a file
tail -f log.txt # follow a log file in real time
Editing files
nano file.txt # beginner-friendly editor
vim file.txt # advanced editor
Permissions
chmod 644 file.txt # rw for owner, r for others
chmod 755 script.sh # rwx for owner, rx for others
chown user:group file # change ownership
Users and sudo
whoami # who am I
su - username # switch user
sudo command # run as root
passwd # change your password
System information
uname -a # kernel info
lsb_release -a # OS version
df -h # disk usage
free -h # memory usage
top # live process view (q to quit)
htop # nicer top (install with apt install htop)
uptime # how long the server has been up
Networking
ip addr # network interfaces and IPs
ping google.com # test connectivity
curl https://example.com # make HTTP request
ss -tulpn # list open ports
Package management
apt update && apt upgrade -y
apt install nginx
apt remove nginx
dnf update -y
dnf install nginx
dnf remove nginx
Services
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl status nginx
systemctl enable nginx # start on boot
