DEV Community

Cover image for Top 50 Command Line Tricks for Developers
Pixel Mosaic
Pixel Mosaic

Posted on

Top 50 Command Line Tricks for Developers

Navigation & File Management

  1. Go back to previous directory
   cd -
Enter fullscreen mode Exit fullscreen mode
  1. Create and enter directory
   mkdir myapp && cd $_
Enter fullscreen mode Exit fullscreen mode
  1. List files with sizes (human readable)
   ls -lh
Enter fullscreen mode Exit fullscreen mode
  1. Show hidden files
   ls -a
Enter fullscreen mode Exit fullscreen mode
  1. Find files by name
   find . -name "*.js"
Enter fullscreen mode Exit fullscreen mode
  1. Delete files interactively
   rm -i file.txt
Enter fullscreen mode Exit fullscreen mode
  1. Show directory size
   du -sh folder/
Enter fullscreen mode Exit fullscreen mode

Search & Text Processing

  1. Search text in files (recursive)
   grep -R "TODO" .
Enter fullscreen mode Exit fullscreen mode
  1. Case‑insensitive search
   grep -i "error" log.txt
Enter fullscreen mode Exit fullscreen mode
  1. Count lines, words, characters

    wc file.txt
    
  2. View file with paging

    less file.txt
    
  3. Print first 10 lines

    head file.txt
    
  4. Print last 10 lines (live logs)

    tail -f app.log
    
  5. Replace text in files

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

    sort names.txt
    

Git Power Tricks

  1. Undo last commit (keep changes)

    git reset --soft HEAD~1
    
  2. Discard all local changes

    git reset --hard
    
  3. Show commit graph

    git log --oneline --graph --all
    
  4. Stash with message

    git stash push -m "WIP"
    
  5. List changed files only

    git diff --name-only
    
  6. Fix last commit message

    git commit --amend
    

Productivity & Shortcuts

  1. Repeat last command

    !!
    
  2. Run last command as sudo

    sudo !!
    
  3. Search command history

    Ctrl + R
    
  4. Clear terminal

    clear
    
  5. Exit terminal fast

    exit
    
  6. Open current folder in file manager

    xdg-open .
    

Networking & System

  1. Check open ports

    lsof -i -P -n
    
  2. Test HTTP endpoint

    curl https://api.example.com
    
  3. Download file

    wget https://example.com/file.zip
    
  4. Check disk usage

    df -h
    
  5. Show running processes

    ps aux
    
  6. Kill process by name

    pkill node
    

Docker & DevOps

  1. List Docker containers

    docker ps -a
    
  2. Stop all containers

    docker stop $(docker ps -q)
    
  3. Remove unused Docker data

    docker system prune
    
  4. Build Docker image

    docker build -t myapp .
    
  5. Exec into running container

    docker exec -it container_name bash
    

Bash & Scripting

  1. Make script executable

    chmod +x script.sh
    
  2. Run script in background

    ./script.sh &
    
  3. Redirect output to file

    command > output.txt
    
  4. Pipe output to another command

    ps aux | grep node
    
  5. Set environment variable

    export NODE_ENV=production
    

Advanced & Fun

  1. Watch command output live

    watch -n 1 ls
    
  2. Measure command time

    time npm run build
    
  3. Generate random password

    openssl rand -base64 16
    
  4. Create alias

    alias gs="git status"
    
  5. List aliases

    alias
    
  6. Quick HTTP server

    python3 -m http.server
    
  7. One‑liner system info

    uname -a
    

Final Tip

Mastering the command line saves hours every week. Start with 5 tricks and build from there.

If you enjoyed this, share it on dev.to & help other developers level up!

Top comments (1)

Collapse
 
leob profile image
leob

Aready knew (and use) most of these - but, this is a great list, contains quite a few nuggets of gold!