Linux Commands

Essential Linux commands for navigating, managing files, and system administration.

File System Navigation

pwd

Print the current working directory path

ls -la

List all files including hidden ones with details

cd /var/www

Change directory to an absolute path

cd ..

Move up one directory level

tree -L 2

Display directory structure as a tree (2 levels deep)

File Operations

touch index.html

Create a new empty file

mkdir -p src/components

Create nested directories

cp -r src/ backup/

Copy a directory and its contents recursively

mv old.txt new.txt

Rename or move a file

rm -rf node_modules

Remove a directory and all its contents

cat package.json

Display the full contents of a file

head -20 README.md

Show the first 20 lines of a file

tail -f /var/log/syslog

Follow a log file in real time

Permissions

chmod 755 deploy.sh

Make a script executable (owner rwx, others rx)

chmod +x script.sh

Add execute permission to a file

chown user:group file.txt

Change the owner and group of a file

ls -l file.txt

View file permissions and ownership details

Process Management

ps aux

List all running processes with details

top

Interactive real-time view of system processes

kill -9 PID

Force kill a process by its ID

lsof -i :3000

Find which process is using a specific port

nohup node server.js &

Run a process in the background that survives logout

Networking

curl -I https://example.com

Fetch HTTP headers from a URL

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

Download a file from the internet

netstat -tulpn

List all listening ports and associated processes

ping -c 4 google.com

Send 4 ICMP packets to test connectivity

ssh user@192.168.1.10

Connect to a remote server via SSH

Search & Text Processing

grep -rn "TODO" src/

Recursively search for text in files with line numbers

find . -name "*.log" -delete

Find and delete all .log files

wc -l src/**/*.ts

Count lines in TypeScript files

sed -i 's/old/new/g' file.txt

Find and replace text in a file

sort data.txt | uniq -c

Sort lines and count unique occurrences