Last updated
Linux Basics
Linux Command Basics
Master essential Linux terminal commands for navigating, managing files, and running processes.
Contents
Navigation
pwd # print current directory
ls -lah # list files with sizes and hidden files
cd /var/log # change to absolute path
cd .. # go up one level
cd ~ # go to home directory
cd - # go to previous directory
File Management
cp file.txt /tmp/file.txt # copy file
cp -r dir/ /tmp/dir/ # copy directory recursively
mv old.txt new.txt # rename or move
rm file.txt # delete file
rm -rf /tmp/old_dir/ # delete directory (caution!)
mkdir -p /var/www/myapp # create nested directories
touch newfile.txt # create empty file or update timestamp
Viewing Files
cat file.txt # print entire file
less file.txt # page through file (q to quit)
head -20 file.txt # first 20 lines
tail -20 file.txt # last 20 lines
tail -f /var/log/syslog # follow log in real time
Search & Filter
grep -r "error" /var/log/ # recursive search in directory
grep -i "failed" auth.log # case-insensitive
find /etc -name "*.conf" # find files by name
find /var -size +100M # find files larger than 100MB
locate nginx.conf # fast system-wide search
File Permissions Quick Reference
chmod 755 script.sh # rwxr-xr-x
chmod 644 config.txt # rw-r--r--
chmod 600 secret.key # rw-------
chown www-data:www-data /var/www/html
chown -R craig:craig ~/projects
System Information
uname -a # kernel version
hostname # server hostname
uptime # uptime and load average
whoami # current user
id # user and group IDs
df -h # disk usage
free -h # RAM usage
top # process monitor (q to quit)
htop # better process monitor
Networking
ip a # show IP addresses
ip r # show routing table
ping -c 4 8.8.8.8 # test connectivity
ss -tulpn # show open ports
curl -I https://example.com # fetch HTTP headers
FAQ
What are the first Linux commands to learn?
pwd, ls, cd, cp, mv, rm, mkdir, cat, less, grep and man. With these you can move around and read any file.
How do I get help for a command?
Run man command for the manual, or command –help for a short summary.