25 Essential Linux Commands Every Beginner Should Learn (With Examples)

RootVerse
0

Mastering the Linux command line starts with a handful of essential commands. This guide covers 25 must-know commands, each with a clear, practical example. By the end, you'll feel comfortable navigating, managing files, and controlling your system from the terminal.

1. pwd – Print Working Directory

Shows you the full path of the directory you’re currently in. Never get lost again.

$ pwd
pwd/home/john/Documents
The command outputs the absolute path, starting from the root (/).

2. ls – List Directory Contents

Lists files and folders in the current (or specified) directory. Use flags for details.

$ ls -la
ls -latotal 32
drwxr-xr-x 2 john john 4096 Mar 15 10:23 .
drwxr-xr-x 18 john john 4096 Mar 15 10:22 ..
-rw-r--r-- 1 john john 220 Mar 15 10:23 notes.txt
-l shows detailed info (permissions, size, date), -a includes hidden files.

3. cd – Change Directory

Navigates between folders.

$ cd /var/log
cd /var/log(no output – changes directory)
Go to the log directory. cd .. goes up one level, cd ~ or just cd takes you home.

4. mkdir – Make Directory

Creates a new folder. Add -p to create parent directories automatically.

$ mkdir -p projects/linux-basics
mkdir -p projects/linux-basics(creates both "projects" and "linux-basics" if they don't exist)

5. rmdir & rm – Remove Directory & Files

rmdir removes empty directories; rm removes files (or directories with -r).

$ rm -rf old-project/
rm -rf old-project/(deletes folder and everything inside – be careful!)
The -r flag is recursive, -f forces deletion without asking. Always double-check before using -rf.

6. cp – Copy Files & Directories

Duplicates files. Use -r for folders.

$ cp -r source/ destination/
cp -r source/ destination/(copies all contents from source to destination folder)

7. mv – Move or Rename Files

Relocates files or renames them.

$ mv oldname.txt newname.txt
mv oldname.txt newname.txt(renames the file)
Also moves files between directories: mv file.txt /target/folder/

8. touch – Create Empty File or Update Timestamps

Quickly creates a blank file or updates the modification time of an existing file.

$ touch newfile.txt
touch newfile.txt(creates newfile.txt if it doesn't exist)

9. cat – Concatenate & Display File Content

Displays the entire contents of a file on the screen.

$ cat /etc/os-release
cat /etc/os-releaseNAME="Ubuntu"
VERSION="22.04 LTS"

10. less & more – View Large Files Page by Page

Both let you scroll through big files, but less is more powerful (scroll up, search).

$ less /var/log/syslog
less /var/log/syslog(opens the log file; press q to quit, / to search)

11. head & tail – View Beginning or End of Files

head shows the first 10 lines (default), tail the last 10. Essential for logs.

$ tail -n 20 /var/log/syslog
tail -n 20 /var/log/syslog(last 20 lines of syslog)
Use tail -f to follow a log file in real time (very handy).

12. grep – Search Text Patterns

Searches inside files for a pattern and prints matching lines.

$ grep "error" /var/log/syslog
grep "error" /var/log/syslogMar 15 10:45:43 server kernel: [UFW BLOCK] error ...
Add -i for case-insensitive search, -r to search recursively in folders.

13. find – Search for Files & Directories

Locates files based on name, type, size, and more.

$ find . -name "*.jpg" -type f
find . -name "*.jpg" -type f./images/photo.jpg
./backup/pic.jpg
The dot (.) means "start from current directory". -type f restricts results to files only.

14. man – Manual Pages

Displays the built‑in manual for any command. Your best teacher.

$ man ls
man ls(opens the manual for 'ls'; press q to quit)

15. --help – Quick Command Help

Most commands support the --help flag for a fast summary of options.

$ ls --help
ls --helpUsage: ls [OPTION]... [FILE]...
List information about the FILEs...

16. sudo – Super User Do

Run commands with administrative (root) privileges.

$ sudo apt update
sudo apt update(asks for your password, then updates package lists)
Always double‑check before using sudo, especially with destructive commands.

17. chmod – Change File Permissions

Adjusts who can read, write, or execute a file.

$ chmod +x script.sh
chmod +x script.sh(makes script.sh executable)
Numeric mode: chmod 755 file gives rwx to owner, rx to group and others.

18. chown – Change File Owner & Group

Transfers ownership of a file to another user/group.

$ sudo chown john:devs report.txt
sudo chown john:devs report.txt(john becomes owner, group set to devs)

19. ps – Process Status

Lists running processes. The most common flags: aux (BSD style) or -ef (Unix style).

$ ps aux | grep nginx
ps aux | grep nginxroot 1234 0.0 0.1 55248 6789 ? Ss 10:12 0:00 nginx: master process

20. kill – Terminate Processes

Sends a signal to a process (usually to stop it).

$ kill -9 1234
kill -9 1234(forcefully kills process with PID 1234)
Use kill -l to list signal names. -15 (SIGTERM) asks nicely; -9 (SIGKILL) is immediate.

21. top & htop – Real‑time System Monitor

top is built‑in; htop is a more user‑friendly version (install with sudo apt install htop).

$ top
top(live view of CPU, memory, and process list; q to quit)

22. df & du – Disk Space Usage

df reports filesystem disk usage; du shows directory sizes.

$ df -h
df -hFilesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 45G 55G 45% /
-h makes output human‑readable. To check a folder size: du -sh /home/user/

23. free – Memory Usage

Displays total, used, and free RAM plus swap.

$ free -h
free -htotal used free shared buff/cache available
Mem: 7.7Gi 2.1Gi 3.2Gi 234Mi 2.3Gi 5.0Gi

24. ping – Test Network Connectivity

Sends ICMP packets to check if a host is reachable. Press Ctrl+C to stop.

$ ping -c 4 google.com
ping -c 4 google.comPING google.com (142.250.190.46) 56(84) bytes of data.
64 bytes from ... time=12.3 ms
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss
-c 4 sends exactly 4 packets and stops.

25. ssh – Secure Shell Remote Connection

Connects to a remote Linux server securely.

ssh [email protected](prompts for password, then opens a remote shell)
Use -p to specify a port (default is 22). For key‑based auth: ssh -i mykey.pem user@host
You're now ready. Practice these 25 commands daily, and the terminal will quickly become second nature. The key is repetition — open a terminal right now and try at least five of them.

Found this helpful? Share it with a friend who's starting their Linux journey. And stay tuned for our next deep dive into shell scripting basics.

Post a Comment

0 Comments

Post a Comment (0)
To Top