Linux: Basic Shell Commands

By Xah Lee. Date: . Last updated: .

write a tutorial of the most frequently used linux commands

write a tutorial of the most frequently used linux commands

ai answer

Linux Command Line Tutorial: The Most Frequently Used Commands

The Linux command line (terminal/shell) is one of the most powerful tools for developers, system administrators, and power users. Almost everything you can do with a graphical interface can be done faster and more precisely with commands.

This tutorial covers the most frequently used Linux commands, with practical examples. All examples assume a standard bash shell (the default on most Linux distributions).

1. Getting Started & Navigation

pwd
Print Working Directory – shows your current location
pwd
ls
List files and directories
ls
ls -l (long format)
ls -la (include hidden files)
ls -lh (human-readable sizes)
cd
Change Directory
cd /home/username
cd .. (go up one level)
cd ~ or cd (go to home)
cd - (go to previous directory)

Pro tip: Use Tab for auto-completion of file and directory names.

2. Working with Files and Directories

mkdir
Create directory
mkdir projects
mkdir -p projects/2026/reports (create nested folders)
touch
Create empty file or update timestamp
touch notes.txt
cp
Copy files/directories
cp file.txt backup.txt
cp -r folder1 folder2 (recursive for directories)
mv
Move or rename
mv oldname.txt newname.txt
mv file.txt /home/user/Documents/
rm
Remove files/directories
rm file.txt
rm -r folder (recursive)
rm -rf folder (force, no confirmation – dangerous)
rmdir
Remove empty directory
rmdir empty_folder

Important safety note: rm -rf / or similar can destroy your system. Always double-check paths.

3. Viewing File Contents

cat
Display entire file
cat file.txt
less / more
View file page by page (recommended for long files)
less largefile.log (use arrows, / to search, q to quit)
head
Show first lines
head -n 20 file.txt
tail
Show last lines
tail -n 50 file.txt
tail -f logfile.log (follow in real time – very useful for logs)
echo
Print text or variables
echo "Hello World"
echo $HOME

4. Searching & Filtering

grep
Search for text patterns
grep "error" logfile.log
grep -i "error" logfile.log (case-insensitive)
grep -r "TODO" . (recursive search)
grep -n "pattern" file.txt (show line numbers)
find
Find files and directories
find . -name "*.txt"
find /home -type d -name "projects"
find . -mtime -7 (modified in last 7 days)
locate
Fast file search (uses database)
locate filename (run sudo updatedb first if needed)
which / whereis
Locate a command
which python3

Combining commands with pipes (|) is extremely powerful:

ps aux | grep nginx
cat file.txt | grep "error" | sort | uniq

5. System Information & Processes

whoami
Current user
whoami
uname
System information
uname -a
df
Disk space usage
df -h
du
Directory/file size
du -sh folder/
du -h --max-depth=1
free
Memory usage
free -h
top / htop
Real-time process monitor
top (press q to quit). htop is nicer if installed.
ps
List processes
ps aux
kill
Stop a process
kill PID
kill -9 PID (force)
history
Show command history
history
!123 (re-run command number 123)

6. Permissions & Ownership

Linux uses a permission system (read/write/execute for owner/group/others).

ls -l
View permissions
Shows something like -rw-r--r--
chmod
Change permissions
chmod 755 script.sh
chmod +x script.sh (make executable)
chmod -R 644 folder/
chown
Change owner
sudo chown user:group file.txt
sudo
Run command as superuser
sudo apt update

Common permission numbers:

7. Package Management

Commands vary by distribution:

Debian/Ubuntu (apt):

sudo apt update
sudo apt upgrade
sudo apt install package-name
sudo apt remove package-name
sudo apt search keyword

Fedora/RHEL (dnf):

sudo dnf update
sudo dnf install package-name

Arch (pacman):

sudo pacman -Syu
sudo pacman -S package-name

8. Networking Basics

ping
Test connectivity
ping google.com
curl
Transfer data / test APIs
curl https://api.example.com
curl -O https://example.com/file.zip
wget
Download files
wget https://example.com/file.tar.gz
ip / ifconfig
Network interfaces
ip a
ssh
Secure remote login
ssh user@192.168.1.100
scp
Secure copy over network
scp file.txt user@server:/path/

9. Archiving & Compression

# Create tar archive
tar -czvf archive.tar.gz folder/

# Extract
tar -xzvf archive.tar.gz

# Zip
zip -r archive.zip folder/
unzip archive.zip

10. Help & Documentation

Quick Productivity Tips

  1. Use Tab completion aggressively.
  2. Arrow keys to navigate command history.
  3. Ctrl + R → reverse search through history.
  4. Ctrl + C → cancel running command.
  5. Ctrl + L or clear → clear the screen.
  6. Aliases – create shortcuts in ~/.bashrc:
    alias ll='ls -lah'
    alias update='sudo apt update && sudo apt upgrade'
  7. Learn to chain commands:
    mkdir project && cd project && touch README.md

Practice Path for Beginners

  1. Open a terminal.
  2. Practice navigation (pwd, ls, cd).
  3. Create a practice folder and files.
  4. Practice copying, moving, and deleting (carefully).
  5. Explore grep and find.
  6. Look at running processes with top or ps.
  7. Read a few man pages (man ls, man grep).

Mastering these core commands will cover 80–90% of daily Linux terminal work. Once comfortable, explore more advanced topics like shell scripting, awk, sed, systemd, and containers.