Linux

Important Linux Commands Every User Should Know

2026-04-27

Introduction

The Linux command line is one of the most powerful tools available to developers, system administrators, and power users. Learning a core set of commands will let you navigate the system, manage files, inspect processes, and control services with confidence. This tutorial covers the most important commands grouped by category.



pwd — Print Working Directory

Shows your current location in the file system.


pwd


ls — List Directory Contents

Lists files and folders in the current directory.


ls


Use flags to get more detail.


ls -l # detailed list with permissions and sizes

ls -a # show hidden files (those starting with .)

ls -lh # human-readable file sizes


cd — Change Directory

Move between directories.


cd /etc # go to /etc

cd ~ # go to your home directory

cd .. # go up one level

cd - # go back to previous directory


Managing Files and Directories


cp — Copy Files

cp source.txt destination.txt

cp -r myfolder/ backup/ # copy a folder recursively


mv — Move or Rename Files

mv oldname.txt newname.txt # rename a file

mv file.txt /home/alice/docs/ # move a file


rm — Remove Files

rm file.txt

rm -r myfolder/ # remove a folder and its contents

rm -rf myfolder/ # force remove without prompts (use carefully)


mkdir — Create Directories

mkdir newproject

mkdir -p projects/flask/templates # create nested directories at once


touch — Create an Empty File

touch app.py


Viewing File Contents


cat — Print File Contents

cat config.txt


less — Scroll Through a File

Useful for large files. Press q to quit.


less /var/log/syslog


head and tail — View the Start or End of a File

head -n 20 file.txt # first 20 lines

tail -n 20 file.txt # last 20 lines

tail -f /var/log/nginx/access.log # follow a log file in real time


grep — Search Inside Files

grep "error" /var/log/syslog

grep -r "flask" /home/alice/myapp/ # search recursively in a folder

grep -i "warning" app.log # case-insensitive search


File Permissions


chmod — Change File Permissions

chmod +x script.sh # make a file executable

chmod 644 config.txt # set read/write for owner, read for others

chmod 755 myfolder/ # standard permission for directories


chown — Change File Owner

sudo chown alice:staff file.txt # change owner and group

sudo chown -R alice /var/www/myapp/ # change ownership recursively


System Information


uname — System Information

uname -a # full system and kernel information


df — Disk Usage

df -h # show disk space usage in human-readable format


du — Directory Size

du -sh /home/alice/myapp/ # total size of a folder


free — Memory Usage

free -h # show RAM and swap usage


top and htop — Live Process Monitor

top # built-in process monitor

htop # improved version, install with: sudo apt install htop


Managing Processes


ps — List Running Processes

ps aux # show all running processes with details


kill — Stop a Process

First find the process ID with ps or top, then kill it.


kill 1234 # send termination signal to process 1234

kill -9 1234 # force kill if it does not respond


Managing Services with Systemd


systemctl — Control Services

sudo systemctl start nginx # start a service

sudo systemctl stop nginx # stop a service

sudo systemctl restart nginx # restart a service

sudo systemctl status nginx # check if a service is running

sudo systemctl enable nginx # start automatically on boot

sudo systemctl disable nginx # do not start on boot


journalctl — View Service Logs

sudo journalctl -u nginx # all logs for nginx

sudo journalctl -u nginx -f # follow logs in real time

sudo journalctl -u myapp --since "1 hour ago"


Networking


ping — Test Connectivity

ping google.com


curl — Make HTTP Requests

curl https://example.com # fetch a webpage

curl -I https://example.com # fetch headers only

curl -X POST -d "name=alice" /api/users # send a POST request


wget — Download Files

wget https://example.com/file.zip


ss — Show Open Ports and Connections

ss -tulnp # show all listening ports and which process owns them


Package Management (Ubuntu / Debian)


apt — Install and Update Software

sudo apt update # refresh package list

sudo apt upgrade # upgrade all installed packages

sudo apt install nginx # install a package

sudo apt remove nginx # remove a package

sudo apt search python # search for a package


Useful Shortcuts and Tips


sudo — Run as Superuser

Prefix any command with sudo to run it with administrator privileges.


sudo nano /etc/hosts


history — View Command History

history

history | grep ssh # search your history for a specific command


clear — Clear the Terminal

clear


man — Read the Manual for Any Command

man ls

man grep


Keyboard Shortcuts

Ctrl+C stops a running command. Ctrl+Z suspends it to the background. Ctrl+L clears the screen. Tab auto-completes file names and commands. Up arrow cycles through previous commands.


Combining Commands


Pipe — Pass Output to Another Command

ls -l | grep ".py" # list only Python files

cat access.log | grep "404" | wc -l # count 404 errors in a log


Redirect Output to a File

echo "Hello" > file.txt # write to file (overwrites)

echo "Hello" >> file.txt # append to file


Run Multiple Commands

sudo apt update && sudo apt upgrade -y # run second only if first succeeds

mkdir logs; cd logs # run both regardless


Conclusion

These commands form the foundation of working effectively on any Linux system. The more you use them, the more natural they become. A great habit is to use man followed by any command name whenever you want to learn more about what it can do.