Published May 29, 2026 ยท 7 min read ยท ๐Ÿท๏ธ Fundamentals

Command Line Essentials: Terminal Basics for Developers

The command line is a developer's most powerful tool. This guide covers essential commands for navigating, manipulating files, managing processes, and automating tasks.

Navigation Basics

pwd                 # print working directory (where am I?)
cd /path/to/dir    # change directory
cd ~               # go to home directory
cd ..             # go up one directory
cd -              # go to previous directory
ls                # list files
ls -la            # list all files with details
ls -lh            # list with human-readable sizes

File Operations

touch readme.md         # create empty file
cp file.txt backup.txt   # copy file
mv old.txt new.txt       # rename or move
rm file.txt              # delete file
rm -rf folder/          # delete folder and contents (careful!)

# Create directory
mkdir new-project
mkdir -p path/to/deep/dir  # create nested dirs

# File details
stat file.txt          # file info
file file.txt          # file type

Viewing and Editing Files

# View file contents
cat file.txt           # print entire file
head -20 file.txt     # first 20 lines
tail -50 file.txt     # last 50 lines
tail -f logs/app.log  # follow file (live updates)

# Search in file
grep "error" file.txt
grep -r "TODO" ./src/  # recursive search

# Edit files
nano file.txt         # simple editor
vim file.txt          # powerful editor
code file.txt         # open in VS Code

Pipes and Redirection

Pipes (|) connect commands. Redirection (>, >>) sends output to files:

# Pipe: send output of one command as input to another
cat logs.txt | grep ERROR | head -20

# Redirect output to file (overwrite)
ls -la > directory.txt

# Append output to file
echo "Timestamp" >> log.txt

# Redirect stderr (errors)
command 2> errors.txt

# Redirect both stdout and stderr
command > all.txt 2>&1

# Input from file
sort < unsorted.txt > sorted.txt

Process Management

# View running processes
ps aux              # all processes with details
top                 # real-time process monitor
htop                # better version (if installed)

# Kill processes
kill 1234           # graceful termination
kill -9 1234       # force kill
killall node       # kill by name

# Background processes
command &           # run in background
Ctrl+Z             # suspend current process
bg                 # resume in background
fg                 # bring to foreground

Permissions

# View permissions
ls -l file.txt
# -rw-r--r-- 1 user group 4096 Jan 1 10:00 file.txt
#  ^  ^  ^      ^    ^     ^
#  |  |  |      |    |     + size
#  |  |  |      |    + group
#  |  |  |      + owner
#  |  |  + other (read, write, execute)
#  |  + group
#  + owner

# Change permissions
chmod 755 script.sh      # rwxr-xr-x
chmod +x script.sh       # add execute
chmod -w file.txt        # remove write

# Change owner
sudo chown user:group file.txt

Permission codes: r=4, w=2, x=1. So 755 = rwxr-xr-x (owner: 7=rwx, group: 5=r-x, other: 5=r-x)

Networking Commands

# Check connectivity
ping google.com
curl https://api.example.com

# Network info
ifconfig           # macOS
ifconfig           # Linux
ip addr show       # modern Linux

# Port usage
lsof -i :8080     # what's using port 8080?
netstat -tlnp      # listening ports

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

Search and Find

# Find files
find . -name "*.js"              # by name
find . -type d -name node_modules # directories only
find . -mtime -7                 # modified in last 7 days
find . -size +100M               # larger than 100MB

# Search files by content
grep -r "function" ./src/

# Modern search (faster)
ag "function" ./src/            # requires silversearcher
rg "function" ./src/            # requires ripgrep

Archives and Compression

# Tar (common on Linux/macOS)
tar -cvf archive.tar ./folder/   # create
tar -xvf archive.tar            # extract
tar -czvf archive.tar.gz ./folder/  # compress
tar -xzvf archive.tar.gz        # decompress & extract

# Zip
zip -r archive.zip ./folder/    # create
unzip archive.zip               # extract

# View without extracting
tar -tzf archive.tar.gz

Useful Keyboard Shortcuts

  • Ctrl+C โ€” Cancel current command
  • Ctrl+Z โ€” Suspend to background
  • Ctrl+D โ€” Exit shell (EOF)
  • Ctrl+L โ€” Clear screen (same as clear)
  • Ctrl+A โ€” Go to beginning of line
  • Ctrl+E โ€” Go to end of line
  • Ctrl+R โ€” Search command history
  • Tab โ€” Auto-complete
  • !! โ€” Repeat last command

Environment Variables

# View variables
echo $PATH
printenv

# Set variable (temporary)
export NODE_ENV=development

# Persistent (add to ~/.bashrc or ~/.zshrc)
export PATH="$PATH:/new/path"
export EDITOR=vim

Productivity Tips

# Aliases (add to ~/.bashrc or ~/.zshrc)
alias ll='ls -la'
alias gs='git status'
alias gp='git push'
alias ..='cd ..'

# History navigation
history            # show all past commands
!234              # run command #234
!gs               # run last command starting with 'gs'

# Multiple commands
command1 && command2    # run 2 after 1 succeeds
command1 || command2    # run 2 if 1 fails
command1 ; command2     # run both regardless
โ† Back to Blog
Copied!