99 Essential Linux Terminal Commands You Need to Know

Why Mastering Linux Commands is Essential Linux is the backbone of modern computing, powering everything from web servers and cloud infrastructure to embedded systems and supercomputers. Unlike other operating systems that rely heavily on graphical user interfaces (GUIs), Linux offers a powerful command-line interface (CLI) that provides unmatched flexibility and control. Why Linux is Widely […]

Why Mastering Linux Commands is Essential

Linux is the backbone of modern computing, powering everything from web servers and cloud infrastructure to embedded systems and supercomputers. Unlike other operating systems that rely heavily on graphical user interfaces (GUIs), Linux offers a powerful command-line interface (CLI) that provides unmatched flexibility and control.

Why Linux is Widely Used in Servers, Development, and Cloud Computing

Linux dominates the server and cloud industry, with major platforms like AWS, Google Cloud, and Microsoft Azure relying heavily on it. Developers and system administrators prefer Linux due to its stability, security, and scalability. Whether you’re managing a web server, deploying applications, or working with DevOps tools, understanding Linux commands is essential for efficiency.

The Power of the Command Line vs. GUI Tools

While GUI-based Linux distributions exist, the command line remains the preferred tool for power users. The CLI allows for faster execution of tasks, automation through scripting, and remote server management without requiring heavy graphical interfaces.

How Learning Essential Linux Commands Boosts Productivity and Troubleshooting Skills

Mastering Linux commands enables users to:

  • Navigate and manage files faster than using a GUI.
  • Automate repetitive tasks with shell scripting.
  • Troubleshoot server issues efficiently.
  • Manage processes, users, and permissions with ease.

In this guide, we’ll explore 99 essential Linux terminal commands that every user should know, from beginners to advanced professionals.

Table of Contents

Basic System Navigation and File Management (For Beginners)

Understanding how to navigate and manage files in the Linux terminal is fundamental for any user. These commands allow you to move through directories, create and delete files, and manage folder structures efficiently.

pwd – Show Current Directory

The pwd (print working directory) command displays the full path of the current directory you are in.

pwd

Example Output:

/home/user

ls – List Files in a Directory

The ls command lists the files and folders inside a directory.

ls

Common Options:

  • ls -l β†’ Show detailed list (permissions, size, owner).
  • ls -a β†’ Show hidden files (files starting with .).
  • ls -lh β†’ Display sizes in human-readable format.

cd – Change Directory

Used to move between directories.

cd /path/to/directory

Examples:

  • cd Documents β†’ Moves into the Documents folder.
  • cd .. β†’ Moves one level up.
  • cd ~ β†’ Moves to the home directory.

mkdir – Create a New Folder

Creates a new directory.

mkdir new_folder

To create multiple nested folders:

mkdir -p parent/child/grandchild

rmdir – Remove Empty Directories

Deletes empty folders.

rmdir empty_folder

If the directory contains files, use rm -r instead.

rm -rf – Delete Files and Folders (Be Careful!)

Removes files and directories permanently.

rm -rf folder_name

Warning: The -rf option forces deletion without confirmation. Use with caution as it cannot be undone.

cp – Copy Files and Folders

Copies files and directories from one location to another.

cp file.txt /destination/path

To copy directories:

cp -r folder_name /destination/path

mv – Move or Rename Files

Moves files or renames them.

mv file.txt /new/location/

To rename a file:

mv old_name.txt new_name.txt

These basic commands help in navigating the Linux system and performing everyday file operations. Now, let’s dive deeper into more powerful system utilities!

File Viewing and Editing Commands

Working with text files in Linux is crucial for system administration, programming, and configuration management. These commands allow you to view, edit, and create files efficiently.

cat – View File Contents

The cat command displays the entire content of a file.

cat filename.txt

To concatenate multiple files:

cat file1.txt file2.txt > merged.txt

less – View Files Page by Page

The less command allows you to view large files without opening them entirely.

less largefile.log

Navigation inside less:

  • Space β†’ Move down one page
  • b β†’ Move up one page
  • q β†’ Quit

head – Show the First 10 Lines of a File

By default, head displays the first 10 lines of a file.

head filename.txt

To display a specific number of lines:

head -n 20 filename.txt

tail – Show the Last 10 Lines of a File

The tail command is useful for monitoring logs and viewing recent file updates.

tail filename.txt

To continuously monitor a file in real-time:

tail -f /var/log/syslog

nano – Simple File Editor

nano is an easy-to-use text editor for quick edits.

nano filename.txt

Common shortcuts inside nano:

  • CTRL + X β†’ Exit
  • CTRL + S β†’ Save
  • CTRL + K β†’ Cut a line

vim – Advanced Text Editor

vim is a powerful text editor with extensive functionality.

vim filename.txt

Basic vim commands:

  • i β†’ Enter insert mode
  • ESC + :wq β†’ Save and exit
  • ESC + :q! β†’ Exit without saving

touch – Create a New Empty File

The touch command creates an empty file.

touch newfile.txt

It can also update the timestamp of an existing file.

touch existingfile.txt

These commands are essential for managing text files, from simple viewing to advanced editing.

File and Directory Permissions & Ownership

Understanding and managing file permissions is crucial for security and proper system functioning in Linux. These commands allow you to control who can access, modify, or execute files.

ls -l – View File Permissions

To check file permissions, use the ls -l command:

ls -l filename.txt

Example output:

-rw-r--r-- 1 user group 1234 Feb 6 12:30 filename.txt
  • -rw-r–r– β†’ File permissions (read, write, execute)
  • 1 β†’ Number of links
  • user β†’ Owner of the file
  • group β†’ Group ownership
  • 1234 β†’ File size in bytes
  • Feb 6 12:30 β†’ Last modified date
  • filename.txt β†’ File name

chmod – Change File Permissions

Modify file permissions using chmod with numerical or symbolic notation.

To give full access to the owner and read-only access to others:

chmod 744 filename.txt

Breakdown:

  • 7 β†’ Owner: Read (4) + Write (2) + Execute (1)
  • 4 β†’ Group: Read (4)
  • 4 β†’ Others: Read (4)

Using symbolic notation:

chmod u+x script.sh  # Add execute permission for the owner  
chmod g-w file.txt   # Remove write permission for the group  
chmod o+r file.txt   # Add read permission for others

chown – Change File Owner

Change the owner of a file:

chown newuser filename.txt

Change both owner and group:

chown newuser:newgroup filename.txt

chgrp – Change File Group Ownership

Change the group ownership of a file:

chgrp newgroup filename.txt

umask – Set Default File Permissions

The umask command defines default file permissions for new files.

Check the current umask value:

umask

Set a new default permission:

umask 022

This results in new files having 755 permissions instead of the default 666.

Proper permission management prevents unauthorized access and protects sensitive data. In the next section, we’ll cover system monitoring and process management.

Process Management and System Monitoring

Efficient process management is critical for maintaining system stability and ensuring that applications run smoothly. These commands help monitor system resources and control running processes.

ps – List Running Processes

The ps command provides a snapshot of active processes.

ps aux
  • a β†’ Show processes from all users.
  • u β†’ Display user-oriented output.
  • x β†’ Include processes without a terminal.

For a more specific list, filter by a process name:

ps aux | grep apache

top / htop – View System Resource Usage

Π•op shows a real-time view of system resource consumption, including CPU and memory usage.

top

Π top is an enhanced alternative with an interactive interface (requires installation).

htop

Use arrow keys to navigate, and press F9 to kill a process.

kill – Terminate a Process

Find the process ID (PID) and terminate it:

ps aux | grep firefox
kill 1234

Replace 1234 with the actual PID.

For a forceful termination:

kill -9 1234

pkill – Kill Processes by Name

Instead of looking up a PID manually, pkill kills processes by name.

pkill firefox

jobs – Show Background Tasks

Displays background jobs running in the current shell session.

jobs

fg / bg – Bring Processes to Foreground/Background

Move a background process to the foreground:

fg %1

Resume a suspended process in the background:

bg %1

These commands provide essential control over system performance and resource management.

User and Group Management

Managing users and groups is crucial for system administration, ensuring proper access control and security across multi-user environments. Below are the key Linux commands for handling users and groups.

whoami – Show Current User

Displays the currently logged-in username.

whoami

id – Display User ID and Group ID

Shows the user ID (UID), group ID (GID), and associated group memberships.

id

To check another user’s ID details:

id username

who – List Logged-In Users

Displays all users currently logged into the system.

who

For more details, including login time and remote sessions:

who -a

adduser / useradd – Create a New User

Adduser is a high-level command that creates a user and home directory.

sudo adduser newuser

It will prompt for a password and user details.

Useradd is a low-level alternative that requires manual configurations.

sudo useradd -m -s /bin/bash newuser
  • -m β†’ Creates a home directory.
  • -s /bin/bash β†’ Sets the default shell.

passwd – Change a User’s Password

Change the password for the current user:

passwd

To change another user’s password (requires sudo):

sudo passwd newuser

usermod – Modify a User Account

Used to modify user properties, such as adding to a group or changing the home directory.

Add a user to an additional group:

sudo usermod -aG sudo newuser

Change a user’s home directory:

sudo usermod -d /new/home/directory username

These commands help administer user access, enforce security policies, and manage multi-user systems efficiently. Next, we’ll explore Networking and Connectivity Commands.

Networking and Connectivity Commands

Networking commands in Linux are essential for troubleshooting connectivity issues, managing network interfaces, and retrieving remote data. Below are some of the most useful networking commands for system administrators and developers.

ping – Test Network Connectivity

The ping command sends ICMP echo requests to a host to check if it’s reachable and measure response time.

ping webhostmost.com

To send a specific number of packets:

ping -c 5 webhostmost.com

curl – Fetch Data from a URL

Used to retrieve data from a remote URL or API.

curl https://example.com

Download a file and save it:

curl -o filename.zip https://example.com/file.zip

Send a POST request with JSON data:

curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.com/endpoint

wget – Download Files from the Web

Unlike curl, wget is designed specifically for downloading files.

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

Download a file in the background:

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

ifconfig / ip a – Show Network Configuration

The ifconfig command (deprecated in some distros) displays network interfaces and their settings.

ifconfig

The modern alternative is ip a, which provides more detailed information.

ip a

To display only active interfaces:

ip -br a

netstat – Display Network Connections

The netstat command provides information on active connections, routing tables, and network statistics.

netstat -tulnp
  • -t β†’ Show TCP connections
  • -u β†’ Show UDP connections
  • -l β†’ Show listening ports
  • -n β†’ Display numerical addresses
  • -p β†’ Show associated processes

nslookup – Query DNS Records

nslookup is used to retrieve DNS records for a domain.

nslookup example.com

To check a specific DNS server:

nslookup example.com 8.8.8.8

traceroute – Trace a Network Route

The traceroute command maps the path packets take to reach a destination.

traceroute webhostmost.com

If traceroute is not installed, use tracepath as an alternative:

tracepath webhostmost.com

These networking commands are essential for diagnosing and troubleshooting network issues. Next, we’ll look at System and Disk Management Commands.

Disk and Storage Management

Managing disk space and storage efficiently is crucial for system stability and performance. These Linux commands help monitor disk usage, manage partitions, and troubleshoot filesystem issues.

df -h – Show Disk Space Usage

Displays the available and used disk space on mounted filesystems in a human-readable format.

df -h

-h β†’ Show sizes in GB/MB instead of bytes.

To check space usage for a specific partition:

df -h /home

du -sh – Check Folder Size

du (disk usage) estimates the space occupied by directories and files.

du -sh /var/log
  • -s β†’ Show total size of the directory.
  • -h β†’ Human-readable output.

To list sizes of all subdirectories within a directory:

du -h --max-depth=1 /home

mount / umount – Mount or Unmount Drives

To manually mount a device:

mount /dev/sdb1 /mnt

To unmount a mounted device:

umount /mnt

List all mounted filesystems:

mount | column -t

fsck – Check and Repair Filesystem Errors

fsck (filesystem check) scans and fixes filesystem corruption.

First, unmount the partition:

umount /dev/sda1

Then run a check:

fsck -y /dev/sda1

-y β†’ Automatically fix detected errors.

Warning: Running fsck on a mounted filesystem can cause data loss.

fdisk -l – View Disk Partitions

Shows a list of all available storage devices and partitions.

fdisk -l

To manage partitions interactively:

fdisk /dev/sdb

mkfs – Format a Filesystem

To format a partition as ext4:

mkfs.ext4 /dev/sdb1

To format a partition as XFS:

mkfs.xfs /dev/sdb1

Caution: This command will erase all data on the partition.

These commands are essential for managing storage efficiently, whether for checking disk usage, formatting partitions, or troubleshooting filesystem errors.

Package Management (Debian & Red Hat Based Systems)

Linux package managers simplify software installation, updates, and dependency resolution. Here’s how to manage packages effectively on Debian-based (Ubuntu, Debian) and Red Hat-based (CentOS, RHEL, Fedora) systems.

Debian-Based Systems (Ubuntu, Debian, Linux Mint)

apt update && apt upgrade – Update & Upgrade Packages

Before installing new software, always update the package lists:

sudo apt update

Then, upgrade all installed packages:

sudo apt upgrade -y
  • update β†’ Refreshes the package index.
  • upgrade β†’ Installs available updates.
  • -y β†’ Automatically confirms the installation.

To update everything, including dependencies:

sudo apt full-upgrade -y

apt install – Install a Package

To install a package from the official repositories:

sudo apt install vim

To install multiple packages at once:

sudo apt install curl wget git

dpkg -i – Install a .deb Package Manually

For local .deb packages (e.g., downloaded from websites):

sudo dpkg -i package.deb

If dependencies are missing, fix them with:

sudo apt --fix-broken install

Red Hat-Based Systems (CentOS, RHEL, Fedora, Rocky Linux, AlmaLinux)

yum install / dnf install – Install a Package

Older CentOS/RHEL versions use yum:

sudo yum install nano -y

Newer systems (RHEL 8+, Fedora, AlmaLinux, Rocky Linux) use dnf:

sudo dnf install nano -y

rpm -ivh – Install a .rpm Package Manually

To install an RPM package:

sudo rpm -ivh package.rpm
  • -i β†’ Install the package.
  • -v β†’ Verbose output.
  • -h β†’ Show progress in a human-readable format.

If dependencies are missing, install them with:

sudo dnf install package.rpm

Cross-Distribution Package Management

snap install – Install a Snap Package

Snaps are universal packages that work across Linux distributions. To install a Snap package:

sudo snap install spotify

To list installed Snaps:

snap list

To remove a Snap package:

sudo snap remove package-name

Mastering package management allows for efficient software installation, updates, and maintenance across different Linux distributions.

Log Files and System Monitoring

Monitoring system logs and resource usage is essential for troubleshooting, performance optimization, and security. Here are some key Linux commands to help you analyze logs and keep track of system health.

System Logs Management

dmesg – View System Boot Messages

Displays kernel messages, useful for diagnosing hardware issues:

dmesg | less

To filter messages related to storage devices:

dmesg | grep -i sda

For real-time monitoring:

dmesg -w

journalctl – View Logs from systemd

On systemd-based distributions (Ubuntu, Fedora, Debian, etc.), use journalctl to view logs:

journalctl -xe

To check logs for a specific service:

journalctl -u sshd --no-pager

For real-time logs:

journalctl -f

tail -f /var/log/syslog – Monitor Logs in Real Time

View the latest system logs and monitor new entries in real-time:

tail -f /var/log/syslog

For Red Hat-based systems:

tail -f /var/log/messages

To monitor authentication logs:

tail -f /var/log/auth.log

System Performance Monitoring

uptime – Check How Long the System Has Been Running

Displays system uptime, number of users, and load average:

uptime

Output example:

Essential Linux Terminal commands
  • up 2 days, 3:17 β†’ System has been running for 2 days and 3 hours.
  • load average: 0.15, 0.08, 0.01 β†’ CPU load over the last 1, 5, and 15 minutes.

free -m – View Memory Usage

Shows available and used RAM in megabytes:

free -m

Output example:

Essential Linux Terminal commands
  • total β†’ Total memory available.
  • used β†’ Memory currently in use.
  • free β†’ Unused memory.
  • buff/cache β†’ Memory used by buffers and caches.

vmstat – Get CPU, Memory, and I/O Statistics

Provides an overview of system performance:

vmstat 5

The command updates every 5 seconds, displaying CPU, memory, and I/O usage.

Example output:

Linux commands
  • us β†’ User CPU usage.
  • sy β†’ System CPU usage.
  • id β†’ Idle CPU time.
  • wa β†’ Time spent waiting for I/O.

Understanding system logs and performance metrics is crucial for debugging, optimizing, and securing your Linux environment. With these commands, you can quickly diagnose issues, track system health, and ensure stable operation.

Compression and Archiving Commands

Efficient file compression and archiving help save disk space, transfer large files, and back up critical data. Below are essential Linux commands for creating and extracting archives using tar, zip, and gzip.

Working with tar Archives

Create a tar Archive

The tar command bundles multiple files into a single archive without compression:

tar -cvf archive.tar file1 file2 folder/
  • -c β†’ Create an archive
  • -v β†’ Verbose output (list files being archived)
  • -f β†’ Specify the filename

Extract a tar Archive

To extract a tar archive:

tar -xvf archive.tar
  • -x β†’ Extract
  • -v β†’ Show extracted files
  • -f β†’ Specify filename

Create a Compressed tar.gz Archive

To reduce file size while archiving, use gzip compression:

tar -czvf archive.tar.gz folder/

-z β†’ Enable gzip compression

Extract a tar.gz Archive

To extract a compressed archive:

tar -xzvf archive.tar.gz

Working with zip Archives

Compress a Folder into a zip File

The zip command compresses folders and files into .zip format:

zip -r archive.zip folder/

-r β†’ Recursively compress all files inside the folder

Extract a zip File

To unzip an archive:

unzip archive.zip

Working with gzip

Compress a Single File with gzip

Unlike tar, gzip compresses individual files:

gzip file.txt

This replaces file.txt with file.txt.gz.

Decompress a gzip File

To restore the original file:

gunzip file.txt.gz

Compression and archiving are essential for optimizing storage, data transfers, and backups. Whether you’re using tar, zip, or gzip, these commands will help you efficiently manage large files and directories.

Scripting and Automation

Linux scripting and automation help streamline repetitive tasks, manage system operations, and enhance efficiency. Below are essential commands for working with Bash scripts, cron jobs, and automation techniques.

Running and Managing Shell Scripts

Run a Shell Script

To execute a script:

bash script.sh

Alternatively, if the script has execution permissions:

./script.sh

Make a Script Executable

Before running a script without explicitly calling bash, make it executable:

chmod +x script.sh

Scheduling Tasks with Cron Jobs

Edit Cron Jobs

The crontab command schedules repetitive tasks:

crontab -e

Example: Run a script every day at 3 AM:

0 3 * * * /path/to/script.sh

Basic Shell Scripting Commands

echo "Hello, World!"

Read User Input

echo "Enter your name:"
read name
echo "Hello, $name!"

Mastering scripting and automation can save time and reduce human errors. Whether running simple scripts or scheduling system tasks with cron, these commands are fundamental for efficient Linux administration.

Remote Access and SSH Commands

Remote access is essential for managing Linux servers, transferring files, and maintaining systems from anywhere. Below are key commands for secure remote connections, file transfers, and session management.

SSH: Secure Shell Access

Connect to a Remote Server

ssh user@server

For a specific port (e.g., 2222):

ssh -p 2222 user@server

Run a Command on a Remote Server Without Logging In

ssh user@server "ls -la /var/www"

Secure File Transfer with SCP

Copy a File to a Remote Server

scp file.txt user@server:/home/user/

Copy a File from a Remote Server to Local Machine

scp user@server:/home/user/file.txt .

Copy a Folder Recursively

scp -r folder user@server:/home/user/

Efficient File Synchronization with Rsync

Synchronize a Directory with a Remote Server

rsync -av source/ user@server:/destination/
  • -a: Archive mode (preserves permissions, timestamps, symbolic links).
  • -v: Verbose mode (shows progress).

Delete Files on Destination that No Longer Exist in Source

rsync -av --delete source/ user@server:/destination/

Session Management for Remote Work

Use tmux for Persistent Sessions

tmux
  • Detach session: Ctrl + B, then D
  • Reattach session:
tmux attach-session -t 0

Use screen as an Alternative

screen
  • Detach session: Ctrl + A, then D
  • List sessions:
screen -ls

Reattach session:

screen -r session_id

Mastering remote access, file transfers, and session management is essential for efficient Linux administration. Whether working with SSH, SCP, rsync, or tmux, these tools ensure seamless control over remote servers.

Advanced Linux Commands for Power Users

For those looking to level up their Linux skills, these powerful commands help with searching, text processing, and automation.

Finding Files and Directories

Search for Files by Name

find . -name "*.txt"
  • . β†’ Search in the current directory and subdirectories.
  • -name “*.txt” β†’ Look for files with the .txt extension.

Find Files Modified in the Last 7 Days

find /var/log -mtime -7

Searching Inside Files with Grep

Find a Specific Word in a File

grep "error" /var/log/syslog
  • error β†’ The keyword you’re searching for.
  • /var/log/syslog β†’ The file being searched.

Search Recursively in a Directory

grep -r "password" /etc/

Highlight Matches in Color

grep --color "failed" /var/log/auth.log

Find and Replace Text with Sed

Replace a Word in a File

sed -i 's/oldword/newword/g' file.txt
  • -i β†’ Modify the file in place.
  • s/oldword/newword/g β†’ Replace β€œoldword” with β€œnewword” globally.

Delete Lines Containing a Specific Word

sed -i '/error/d' log.txt

Processing Text with Awk

Extract the First Column of a File

awk '{print $1}' data.txt

{print $1} β†’ Extracts the first column of text.

Sum All Numbers in the Second Column

awk '{sum += $2} END {print sum}' data.txt

Passing Output Between Commands with Xargs

Delete All .log Files Found by find

find /var/log -name "*.log" | xargs rm -f

Count the Number of Files in a Directory

ls | wc -l

These advanced Linux commands help power users search files, process text, and automate tasks efficiently. Mastering them boosts productivity and efficiency when working in a Linux environment.

Conclusion: Mastering the Linux Terminal for Productivity

Mastering Linux terminal commands is essential for anyone working with servers, development, or IT operations. Whether you’re a developer, system administrator, or power user, knowing how to efficiently navigate and control a Linux system saves time, enhances security, and boosts productivity.

Why It Matters

  • Efficiency – Automate tasks, manage files, and troubleshoot issues faster.
  • Full Control – Work directly with the operating system without GUI limitations.
  • Essential for IT Pros – Every sysadmin and developer needs strong command-line skills.

Keep Practicing & Bookmark This Guide!

The best way to master Linux commands is through hands-on practice. Keep this guide handy, experiment with the commands, and integrate them into your daily workflow.

Next Steps

  • Set up a Linux sandbox (VM, Docker, or a cloud instance) to practice.
  • Explore man pages (man <command>) for in-depth command details.
  • Learn scripting (bash, cron, sed, awk) to automate workflows.

With consistent practice, you’ll become a Linux power user, making your workflow faster and more efficient than ever.

Tags