Linux Command Notes

A comprehensive guide to essential Linux commands for system administration, file management, and development workflows.

  • Linux
  • Commands
  • DevOps
  • System Administration
  • Terminal

This is a living document of useful Linux commands and snippets that I frequently use in development, system administration, and DevOps work.


1. Filesystem Layout

/ → root /home → user homes (~) /etc → configs /var/log → logs (critical) /proc → running processes (virtual) /tmp → temp files

File & Directory Management

Basic Navigation

echo $?
After running a command, how do you check if it succeeded or failed?  # 0 = success, non-zero = error

pwd
Print working directory

cd /path
Change directory

cd ~
Go to home directory

cd -
Go to previous directory

ls -la
List all files with details

find . -name "*.txt"
Find files by name

File Operations

cp source dest
Copy file

mv source dest
Move/rename file

rm file
Remove file

mkdir dir
Create directory

rmdir dir
Remove empty directory

Text Processing

Viewing Files

cat file.txt
Display file content

less file.txt
View file with pagination

head -n 10 file.txt
First 10 lines

tail -n 10 file.txt
Last 10 lines

tail -f /var/log/syslog
tail -f means “follow” it keeps showing new lines as they’re added to the file

Searching & Filtering

grep "pattern" file.txt
Search in file

grep -r "pattern" .
Recursive search

grep -v "pattern"
Invert match (exclude)

grep -n "ERROR" trading.log
line numbers with error

grep "ERROR" trading.log | wc -l
count of lines with word "ERROR"

grep -i "root" /etc/passwd
Search "root" case insensitive

awk '{print $1}'
Print first column

sed 's/old/new/g'
Replace text

System & Process Management

System Information

uname -a
System information

lsb_release -a
OS information

df -h
Disk space usage

du -sh dir
Directory size

free -h
Memory usage

Process Management

ps aux
List all processes

ps aux | grep "process"
Find specific process

kill PID
Terminate process

kill -9 PID
Force kill

top
Real-time process monitor

Interactive keys inside top
- Shift + P sort by CPU usage (highest first).
- Shift + M sort by Memory usage.
- Shift + N sort by PID.
- Shift + T sort by running time.
- u filter by user (e.g., type adarsh to see only your processes).
- k kill a process (it will prompt for PID).
- r renice (change priority of a process).
- f choose which fields/columns to display.
- o filter by expression (e.g., COMMAND=ping).
- q quit top.


htop
Better top alternative

jobs
all running background jobs

kill %N where N - {1,2,3,4,...}
kill running job by job number not process id

Network & Connectivity

Testing & Debugging

ping google.com
Test connectivity

ping -c 3 google.com

curl https://example.com
Fetch URL

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

netstat -an
Network connections

ss -tuln
network sockets on a Linux system
tuln simply a shorthand combination of options passed to the ss (socket statistics) tool:
- t show TCP sockets
- u show UDP sockets
- l show only listening sockets (services waiting for connections)
- n show numeric addresses/ports (don’t resolve names like http or ssh)

SSH & Remote Access

ssh user@host
SSH (secure shell) connection

ssh -i ~/.ssh/key user@host
SSH with key

scp file user@host:/path
Copy to remote

ssh-keygen -t rsa -b 4096
Generate SSH key

Permissions & Ownership

chmod 755 file
Change permissions

chmod +x script.sh
Make executable

chown user:group file
Change owner

sudo command
Run as admin

umask # see current (usually 0022)
umask is short for “user file creation mask”. It controls the default permissions that new files and directories get when they’re created.

Package Management

apt (Ubuntu/Debian)

sudo apt update
Update package list

sudo apt upgrade
Upgrade packages

sudo apt install pkg
Install package

sudo apt remove pkg
Remove package

sudo apt search keyword
Search packages

yum/dnf (RedHat/CentOS/Fedora)

sudo yum install pkg
Install package

sudo yum remove pkg
Remove package

sudo dnf update
Update packages

Compression & Archives

tar -czf archive.tar.gz dir/
Create tar.gz

tar -xzf archive.tar.gz
Extract tar.gz

zip -r archive.zip dir/
Create zip

unzip archive.zip
Extract zip

gzip file
Compress file

gunzip file.gz
Decompress

Other Useful Commands

date
Current date/time

history
Command history

clear
Clear terminal

which command
Locate command

man command
Manual pages

cal
Calendar

echo "text"
Print text

wc -l file.txt
Count lines

sort file.txt
Sort content

uniq file.txt
Remove duplicates

Redirection & Piping Operators

OperatorNameDescriptionExampleOutput
<Input RedirectRead input from filewc -l < trading.logCounts lines from trading.log
>Output RedirectWrite output to file (overwrite)echo "Hello" > file.txtCreates/overwrites file.txt
>>Append RedirectAppend output to fileecho "World" >> file.txtAppends to file.txt
2>Error RedirectRedirect errors to filels /not/here 2> errors.txtErrors go to errors.txt
2>>Error AppendAppend errors to filecommand 2>> errors.logErrors appended to errors.log
&>All RedirectRedirect stdout + stderr to filecommand &> all.txtBoth output and errors to all.txt
|PipePass output of one command to anothercat file.txt | grep "pattern"Grep searches in piped content
|&Pipe AllPipe stdout + stderrcommand1 |& command2Piped output includes errors

More commands and examples will be added as I discover or need them!