Instant Linux

Linux commands that I use daily and actually find useful. No fluff, just practical stuff that makes life easier.

Finding Files (Without Losing Your Mind)

The find command looks intimidating but it’s incredibly useful once you get it. Here are the searches I actually use:

Find Files by Name (Case Insensitive)

find . -iname "*.js"

The -iname flag ignores case. Way better than -name because who remembers if it’s README.md or readme.md?

Find Large Files Eating Your Disk

find . -type f -size +100M

This finds all files bigger than 100MB. Super useful when your disk is suddenly full.

Find and Delete Old Log Files

find . -name "*.log" -mtime +30 -delete

Deletes log files older than 30 days. Be careful with -delete though—test without it first.

Find Files Modified Recently

find . -type f -mtime -7

Shows files modified in the last 7 days. Great for tracking what changed recently.

Grep: Actually Finding Stuff Inside Files

grep is how you search file contents. Way more useful than find for code.

grep -r "function" .

Searches recursively for “function” in all files.

Case Insensitive + Line Numbers

grep -rni "todo" .

Finds all TODO comments with line numbers. The -n shows which line, -i ignores case.

Exclude Directories (Like node_modules)

grep -r "import" --exclude-dir={node_modules,.git} .

Because nobody wants to search through dependencies.

Process Management

Find What’s Using a Port

lsof -i :3000

Port 3000 already in use? This tells you what’s hogging it.

Kill a Process by Name

pkill -f "node"

Kills all processes matching “node”. Use carefully.

See What’s Eating CPU

top
# or better yet
htop

htop is like top but actually readable. Install it if you haven’t.

Disk Usage

See Folder Sizes

du -sh */

Shows size of each folder in current directory. The -h makes it human-readable (GB, MB, etc).

Find Biggest Directories

du -h | sort -h | tail -20

Shows the 20 largest directories. Perfect for cleaning up space.

Network Stuff

Test if a Port is Open

telnet localhost 3000
# or better
nc -zv localhost 3000

Download Files

wget https://example.com/file.zip
# or
curl -O https://example.com/file.zip

wget downloads, curl does everything. Both work.

Useful Aliases

Add these to your ~/.bashrc or ~/.zshrc:

alias ll='ls -lah'
alias ports='lsof -i -P -n | grep LISTEN'
alias cleanup='find . -name "node_modules" -type d -prune -exec rm -rf {} +'

The cleanup alias removes all node_modules folders recursively. Use with caution.

Quick File Operations

Create Nested Directories

mkdir -p project/src/components

The -p creates parent directories as needed.

Copy with Progress

rsync -ah --progress source/ destination/

Way better than cp for large files.

Find and Replace in Multiple Files

find . -name "*.js" -exec sed -i 's/oldtext/newtext/g' {} +

Changes all occurrences of “oldtext” to “newtext” in JS files.

The Actually Useful Stuff

These are the commands I use constantly:

  • Ctrl + R - Search command history
  • !! - Repeat last command (useful for sudo !!)
  • cd - - Go back to previous directory
  • Ctrl + L - Clear terminal (faster than typing clear)

Linux isn’t scary once you know the basics. Start with find, grep, and du. The rest comes naturally.