Linux Commands Howsnip

50+ Essential Linux Commands You Should Know

Linux provides powerful command-line tools for managing files, monitoring system resources, troubleshooting problems, and working with remote servers. Whether you’re just getting started with Linux or need a quick reference for everyday administration tasks, this guide covers some of the most useful commands organized by category.

Prerequisites

Before using these commands:

  • Open a terminal window on your Linux system.
  • Ensure you have appropriate permissions for administrative commands.
  • Some tools such as htop, ncdu, and nmap may need to be installed first.
  • Be cautious when using commands that modify or delete files.

Important: Commands that use sudo, rm, kill -9, or recursive operations can affect your system. Verify commands before running them.

  1. File Operations
  2. Disk and Memory Management
  3. Process Management
  4. Network Commands
  5. Text Processing Commands
  6. Managing Permissions and Users
  7. SSH and Remote Access
  8. Git Quick Reference
  9. System Information Commands

1. File Operations

File management is one of the most common tasks in Linux. These commands help you find, search, copy, move, and remove files efficiently.

Find Files by Name

Use find to locate files by name while searching the current directory and its subdirectories.

Search for JavaScript files in the current directory and all subdirectories:

find . -name "*.js" -type f

Essential Linux Commands Howsnip

Find Files Modified in the Last 7 Days

Use this command to identify files that have been modified recently, which is useful for tracking changes.

find . -mtime -7 -type f

Essential Linux Commands Howsnip

This is useful when tracking recently changed files within a project.

Find Large Files

Use find with a size filter to locate files that are consuming a significant amount of disk space.

Locate files larger than 100 MB:

find . -size +100M -ls

Essential Linux Commands Howsnip

This helps identify files that may be consuming significant storage space.

Search Inside Files

Use grep to search file contents recursively for a specific word, phrase, or pattern.

Search recursively for a specific word:

grep -r "TODO" .

Essential Linux Commands Howsnip

Search only JavaScript files in the src directory:

grep -r "functionName" src/ --include="*.js"

Essential Linux Commands Howsnip

Replace Text in Files

Use sed to search for and replace text directly inside matching files.

Replace all instances of text within JavaScript files:

sed -i 's/oldText/newText/g' *.js

Essential Linux Commands Howsnip

Warning: This command modifies files directly. Consider making a backup first.

Copy Files and Directories

Use cp to create a copy of files or directories while preserving the original data.

Copy a directory and its contents:

cp -r source/ dest/

Essential Linux Commands Howsnip

Move or Rename Files

Use mv to rename a file or directory or move it to a different location.

mv old_name.js new_name.js

Essential Linux Commands Howsnip

This command can be used either to rename a file or move it to another location.

Delete Directories Recursively

Use rm with recursive options to remove a directory and everything contained within it.

rm -rf node_modules/

Essential Linux Commands Howsnip

Warning: rm -rf permanently deletes files and folders without confirmation.

2. Disk and Memory Management

Monitoring storage and memory usage is essential for maintaining system performance.

Check Disk Usage

Use df to view filesystem disk usage, including used space and available space.

View mounted disks and available space:

df -h

Essential Linux Commands Howsnip

The -h option displays values in a human-readable format.

View Directory Sizes

Use du to calculate directory sizes and sort the results so the largest directories are easy to identify.

Show directory sizes and sort them from largest to smallest:

du -sh * | sort -hr

Essential Linux Commands Howsnip

Find the Largest Files

Use du, sort, and head together to quickly identify the largest files and directories.

Display the top 10 largest files and directories:

du -ah . | sort -hr | head -10

Essential Linux Commands Howsnip

Check Available Memory

Use free to view available, used, and total system memory in a human-readable format.

free -h

Essential Linux Commands Howsnip

This command provides a quick overview of RAM usage.

Identify Disk Space Usage Interactively

Use ncdu to explore disk usage interactively and quickly locate directories consuming the most space.

ncdu /

Essential Linux Commands Howsnip

Install it first if necessary:

sudo apt install ncdu

Clean Up Unused Resources

Use system cleanup commands to remove unused packages, Docker data, or cached files and recover disk space.

Remove unused packages:

sudo apt autoremove

Essential Linux Commands Howsnip

Clean unused Docker data:

docker system prune -a

Essential Linux Commands Howsnip

Clear the npm cache:

npm cache clean --force

Essential Linux Commands Howsnip

3. Process Management

Linux makes it easy to monitor and manage running applications.

Find Running Processes

Use ps to list running processes and grep to filter the output for a specific application or process.

Search for Node.js-related processes:

ps aux | grep node

Essential Linux Commands Howsnip

Monitor Processes in Real Time

Use htop to interactively monitor running processes, CPU usage, memory usage, and system load.

htop

Essential Linux Commands Howsnip

Install htop if it is not already available:

sudo apt install htop

Stop a Process

Use kill to request that a running process terminate gracefully by specifying its process ID.

Terminate a process using its PID:

kill PID

Essential Linux Commands Howsnip

Force termination if needed:

kill -9 PID

Essential Linux Commands Howsnip

Note: Use kill -9 only when a normal termination fails.

Kill a Process by Name

Use pkill to terminate processes by matching their name or command line.

pkill -f "node server"

Essential Linux Commands Howsnip

Check Which Process Is Using a Port

Use lsof or ss to identify the process that is listening on or using a specific network port.

Using lsof:

lsof -i :3000

Essential Linux Commands Howsnip

Using ss:

ss -tlnp | grep :3000

Essential Linux Commands Howsnip

Run Processes in the Background

Use the background operator, nohup, and disown to keep commands running without occupying the current terminal.

Start a server in the background:

node server.js &

Essential Linux Commands Howsnip

For persistent execution after terminal closure:

nohup node server.js &

Essential Linux Commands Howsnip

Detach the process:

disown

Essential Linux Commands Howsnip

4. Network Commands

Networking tools help troubleshoot connectivity issues and inspect network behavior.

Test Internet Connectivity

Use ping to test basic network reachability and measure response time to a remote host.

ping google.com

Essential Linux Commands Howsnip

Perform DNS Lookups

Use nslookup or dig to query DNS records and troubleshoot domain name resolution.

Basic lookup:

nslookup example.com

Essential Linux Commands Howsnip

Detailed lookup:

dig example.com

Essential Linux Commands Howsnip

Make HTTP Requests

Use wget to retrieve content from an HTTP or HTTPS URL directly from the command line.

Retrieve webpage content:

wget -qO- https://example.com

Essential Linux Commands Howsnip

View HTTP Headers

Use curl to inspect HTTP response headers and, with verbose mode, view additional connection details.

Headers only:

curl -I https://example.com

Essential Linux Commands Howsnip

Verbose output:

curl -v https://example.com

Essential Linux Commands Howsnip

Send a POST Request

Use curl to send data to a web API using an HTTP POST request with custom headers and a request body.

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

Essential Linux Commands Howsnip

Download a File

Use curl with the -o option to download remote content and save it with a specified filename.

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

Essential Linux Commands Howsnip

Scan Open Ports

Use nmap to identify open ports on a host and get a basic view of its network services.

nmap localhost

Essential Linux Commands Howsnip

Install nmap if required:

sudo apt install nmap

5. Text Processing Commands

Linux includes powerful text-processing tools for inspecting and manipulating files.

View File Contents

Use cat to display a file’s contents directly in the terminal, while less is useful for viewing large files page by page.

Display an entire file:

cat file.txt

Essential Linux Commands Howsnip

Open a large file page by page:

less file.txt

Essential Linux Commands Howsnip

Exit less by pressing:

q

View the Beginning or End of a File

Use head to view the beginning of a file and tail to inspect the end or follow new content in real time.

First 20 lines:

head -n 20 file.txt

Essential Linux Commands Howsnip

Follow a file in real time:

tail -f file.txt

Essential Linux Commands Howsnip

Count Lines and Words

Use wc to count lines, words, and other basic file statistics.

Count lines:

wc -l file.txt

Essential Linux Commands Howsnip

Count words:

wc -w file.txt

Essential Linux Commands Howsnip

Sort Data

Use sort to arrange text alphabetically, numerically, or by a selected field.

Alphabetical sort:

sort file.txt

Essential Linux Commands Howsnip

Numerical reverse sort:

sort -nr numbers.txt

Essential Linux Commands Howsnip

Sort a CSV file by the second column:

sort -k2 -t',' file.csv

Essential Linux Commands Howsnip

Find Unique Values

Use uniq with sorted input to remove duplicate lines, count occurrences, or identify the most common values.

Remove duplicates:

sort file.txt | uniq

Essential Linux Commands Howsnip

Count occurrences:

sort file.txt | uniq -c

Essential Linux Commands Howsnip

Display most common values:

sort file.txt | uniq -c | sort -rn | head

Essential Linux Commands Howsnip

Extract Specific Columns

Use awk or cut to select specific fields or columns from structured text such as CSV files.

Using awk:

awk -F',' '{print $1, $3}' data.csv

Essential Linux Commands Howsnip

Using cut:

cut -d',' -f1-3 data.csv

Essential Linux Commands Howsnip

6. Managing Permissions and Users

Permissions control who can read, write, and execute files.

Check Current Permissions

Use ls -la to view files, directories, ownership, permissions, hidden files, and other metadata.

ls -la

Essential Linux Commands Howsnip

Change Permissions

Use chmod to change read, write, and execute permissions for files and directories.

Set permissions explicitly:

chmod 755 script.sh

Essential Linux Commands Howsnip

Make a file executable:

chmod +x script.sh

Change permissions recursively:

chmod -R 644 linux-practice/

Essential Linux Commands Howsnip

Change File Ownership

Use chown to change the user and group ownership associated with a file or directory.

chown user:group file

Essential Linux Commands Howsnip

Recursive ownership change:

chown -R www-data:www-data ~/linux-practice/src/

Essential Linux Commands Howsnip

Check Current User Information

Use whoami and id to determine the current user and view associated user and group information.

Current user:

whoami

Essential Linux Commands Howsnip

User and group details:

id

Essential Linux Commands Howsnip

Switch Users

Use su to switch to another user account or sudo to run a command with another user’s privileges.

su - username

Essential Linux Commands Howsnip

Run a command as another user:

sudo -u postgres psql

Essential Linux Commands Howsnip

7. SSH and Remote Access

SSH allows secure access to remote Linux systems.

Connect to a Remote Server

Use ssh to establish a secure command-line connection to a remote Linux server.

ssh user@hostname

Essential Linux Commands Howsnip

Connect Using a Custom Port

Use ssh with the -p option when the remote SSH service is listening on a port other than the default.

ssh -p 22 user@hostname

Essential Linux Commands Howsnip

Copy Files to a Remote Server

Use scp to securely transfer files or directories from the local system to a remote server.

Copy a file:

scp file.txt user@host:/path/to/dest/

Essential Linux Commands Howsnip

Copy a directory:

scp -r folder/ user@host:/path/to/dest/

Essential Linux Commands Howsnip

Copy Files from a Remote Server

Use scp to securely copy files from a remote server to the local system.

scp user@host:/path/file.txt ./

Essential Linux Commands Howsnip

Configure Passwordless Authentication

Use SSH keys to authenticate to remote servers without entering a password for every connection.

Generate an SSH key:

ssh-keygen -t ed25519

Essential Linux Commands Howsnip

Copy the key to the remote server:

ssh-copy-id user@host

Essential Linux Commands Howsnip

Create an SSH Configuration

Use ~/.ssh/config to define reusable SSH connection settings and simplify access to frequently used servers.

Edit ~/.ssh/config:

Host myserver
HostName 192.168.1.100
User ubuntu
IdentityFile ~/.ssh/id_ed25519

Essential Linux Commands Howsnip

Then connect using:

ssh myserver

Essential Linux Commands Howsnip

8. Git Quick Reference

These Git commands are useful for daily development tasks.

Check Repository Status

Use git status to see modified, staged, and untracked files in the current Git repository.

git status

Essential Linux Commands Howsnip

Review Changes

Use git diff to inspect changes that have been made but are not yet committed.

git diff

Essential Linux Commands Howsnip

View Recent Commits

Use git log to review recent commits in a compact, easy-to-read format.

git log --oneline -10

Essential Linux Commands Howsnip

Commit Changes

Use git add and git commit to stage changes and save them as a new commit in the repository.

git add -A && git commit -m "msg"

Essential Linux Commands Howsnip

Push Changes

Use git push to upload local commits from a branch to the configured remote repository.

git push origin main

Essential Linux Commands Howsnip

Pull Latest Updates

Use git pull to fetch and integrate the latest changes from the remote repository into the current branch.

git pull origin main

Essential Linux Commands Howsnip

Save Work Temporarily

Use git stash to temporarily save uncommitted changes so you can switch tasks without committing them.

Create a stash:

git stash

Essential Linux Commands Howsnip

Restore the stash:

git stash pop

Essential Linux Commands Howsnip

9. System Information Commands

These commands help you inspect operating system and hardware details.

View Operating System Information

Use uname and /etc/os-release to view kernel, architecture, distribution, and operating system details.

uname -a

Essential Linux Commands Howsnip

cat /etc/os-release

Essential Linux Commands Howsnip

Check CPU Details

Use nproc for the number of available processing units and lscpu for detailed CPU architecture information.

Number of CPU cores:

nproc

Essential Linux Commands Howsnip

Detailed CPU information:

lscpu

Essential Linux Commands Howsnip

Check System Uptime

Use uptime to see how long the system has been running along with current load information.

uptime

Essential Linux Commands Howsnip

Work With Environment Variables

Use env, grep, and echo to inspect environment variables and view or modify the shell’s PATH.

Filter variables by keyword:

env | grep NODE

Essential Linux Commands Howsnip

Display the system PATH:

echo $PATH

Essential Linux Commands Howsnip

Add a directory to PATH:

export PATH="$PATH:/new/path"

Essential Linux Commands Howsnip

Conclusion

These commands provide a practical foundation for everyday Linux administration, troubleshooting, development, networking, and remote system management.

These Linux commands cover the most common tasks you’ll encounter when working with files, processes, networking, system administration, Git repositories, and remote servers.

Learning and practicing these commands can significantly improve your productivity and troubleshooting skills. Keep this guide handy as a reference.