Essential Linux Command Line Tools for Daily Productivity

Mastering essential command-line tools dramatically increases productivity for Linux users. Whether you’re a system administrator, developer, or power user, knowing the right tools and how to use them efficiently saves time and simplifies complex tasks. This guide covers indispensable command-line utilities that should be part of every Linux user’s toolkit.

File and Directory Operations

cd (change directory):

# Go to home directory
cd
cd ~

## Previous directory
cd -

## Parent directory
cd ..

## Absolute path
cd /var/log

## Relative path
cd ../../documents

ls (list directory contents):

## Basic listing
ls

## Long format
ls -l

## Show hidden files
ls -a

## Human-readable sizes
ls -lh

## Sort by time (newest first)
ls -lt

## Reverse sort
ls -ltr

## Recursive listing
ls -R

## Color output
ls --color=auto

tree (directory tree):

## Install tree
sudo apt install tree

## Show directory tree
tree

## Limit depth
tree -L 2

## Show hidden files
tree -a

## Show only directories
tree -d

## Show file sizes
tree -h

File Manipulation

cp (copy):

## Copy file
cp source.txt destination.txt

## Copy recursively
cp -r source_dir/ dest_dir/

## Preserve attributes
cp -p file1 file2

## Interactive (prompt before overwrite)
cp -i file1 file2

## Verbose output
cp -v file1 file2

## Backup existing files
cp -b file1 file2

mv (move/rename):

## Rename file
mv oldname.txt newname.txt

## Move file
mv file.txt /path/to/destination/

## Move multiple files
mv file1 file2 file3 /destination/

## Interactive mode
mv -i file1 file2

## No clobber (don't overwrite)
mv -n file1 file2

rm (remove):

## Remove file
rm file.txt

## Remove directory recursively
rm -r directory/

## Force remove (no prompts)
rm -f file.txt

## Interactive mode
rm -i file.txt

## Remove empty directory
rmdir empty_dir/

## Verbose output
rm -v file.txt

Text Processing

Viewing Files

cat (concatenate):

## Display file
cat file.txt

## Number lines
cat -n file.txt

## Multiple files
cat file1.txt file2.txt

## Create file
cat > newfile.txt
## Type content, press Ctrl+D to save

less (pager):

## View file
less file.txt

## Navigation:
## Space - next page
## b - previous page
## / - search forward
## ? - search backward
## q - quit
## G - end of file
## g - beginning of file

head (first lines):

## First 10 lines
head file.txt

## First N lines
head -n 20 file.txt

## Multiple files
head file1.txt file2.txt

## First N bytes
head -c 100 file.txt

tail (last lines):

## Last 10 lines
tail file.txt

## Last N lines
tail -n 20 file.txt

## Follow file (live updates)
tail -f /var/log/syslog

## Follow with retry
tail -F /var/log/app.log

## Multiple files
tail -f file1.log file2.log

Text Manipulation

grep (search patterns):

## Search in file
grep "pattern" file.txt

## Case-insensitive
grep -i "pattern" file.txt

## Show line numbers
grep -n "pattern" file.txt

## Recursive search
grep -r "pattern" /path/to/dir/

## Invert match (show non-matching)
grep -v "pattern" file.txt

## Count matches
grep -c "pattern" file.txt

## Show only filenames
grep -l "pattern" *.txt

## Extended regex
grep -E "pattern1|pattern2" file.txt

## Context (lines before/after)
grep -C 3 "pattern" file.txt

sed (stream editor):

## Substitute
sed 's/old/new/' file.txt

## Global substitution (all occurrences)
sed 's/old/new/g' file.txt

## In-place edit
sed -i 's/old/new/g' file.txt

## Delete lines
sed '/pattern/d' file.txt

## Print specific lines
sed -n '10,20p' file.txt

## Multiple commands
sed -e 's/old/new/' -e 's/foo/bar/' file.txt

awk (pattern scanning):

## Print specific column
awk '{print $1}' file.txt

## Print multiple columns
awk '{print $1, $3}' file.txt

## With condition
awk '$3 > 100' file.txt

## Sum column
awk '{sum+=$1} END {print sum}' numbers.txt

## Custom delimiter
awk -F: '{print $1}' /etc/passwd

## Pattern matching
awk '/error/ {print $0}' logfile.txt

sort (sort lines):

## Sort alphabetically
sort file.txt

## Numeric sort
sort -n numbers.txt

## Reverse sort
sort -r file.txt

## Unique only
sort -u file.txt

## Sort by column
sort -k 2 file.txt

## Case-insensitive
sort -f file.txt

## Random sort (shuffle)
sort -R file.txt

uniq (unique lines):

## Remove duplicates (requires sorted input)
sort file.txt | uniq

## Count occurrences
sort file.txt | uniq -c

## Show only duplicates
sort file.txt | uniq -d

## Show only unique
sort file.txt | uniq -u

Finding Files

find (search files):

## Find by name
find /path -name "*.txt"

## Case-insensitive name
find /path -iname "*.TXT"

## Find directories
find /path -type d -name "logs"

## Find files
find /path -type f -name "*.log"

## Modified in last N days
find /path -mtime -7

## Larger than size
find /path -size +100M

## Execute command on results
find /path -name "*.tmp" -exec rm {} \;

## Find and list
find /path -name "*.conf" -ls

## Multiple conditions
find /path -name "*.log" -size +10M -mtime -7

locate (fast file search):

## Install locate
sudo apt install mlocate

## Update database
sudo updatedb

## Search for file
locate filename

## Case-insensitive
locate -i filename

## Count results
locate -c pattern

## Show only existing files
locate -e filename

File Information

file (determine file type):

## Check file type
file document.pdf
file script.sh
file unknown_file

## MIME type
file -i document.pdf

stat (file statistics):

## Detailed file info
stat file.txt

## Show only size
stat -c %s file.txt

## Show only modification time
stat -c %y file.txt

du (disk usage):

## Directory size
du -sh /path/to/dir

## All files in directory
du -ah /path/to/dir

## Sort by size
du -sh * | sort -h

## Summarize total only
du -s /path/to/dir

## Exclude patterns
du -sh --exclude="*.log" /path

df (filesystem disk space):

## Show all filesystems
df -h

## Specific filesystem
df -h /

## Inodes information
df -i

## Type-specific
df -t ext4

System Information

System Status

uname (system information):

## Kernel name
uname

## All information
uname -a

## Kernel version
uname -r

## Hostname
uname -n

## Machine hardware
uname -m

uptime (system uptime):

## Show uptime and load average
uptime

## Pretty format
uptime -p

whoami (current user):

## Display current username
whoami

## User ID information
id

## Full user details
id -a

date (display/set date):

## Current date/time
date

## Custom format
date +"%Y-%m-%d %H:%M:%S"

## ISO 8601 format
date -I

## Unix timestamp
date +%s

## Date arithmetic
date -d "tomorrow"
date -d "next week"
date -d "2 days ago"

Network Tools

Basic Network Commands

ping (test connectivity):

## Ping host
ping google.com

## Limited count
ping -c 4 google.com

## Interval
ping -i 2 google.com

## Quiet output
ping -q -c 10 google.com

curl (transfer data):

## Get webpage
curl https://example.com

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

## Save with custom name
curl -o filename.zip https://example.com/file.zip

## Follow redirects
curl -L https://example.com

## Show headers
curl -I https://example.com

## POST request
curl -X POST -d "data=value" https://api.example.com

## With authentication
curl -u user:pass https://example.com

wget (download files):

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

## Resume download
wget -c https://example.com/large-file.iso

## Download recursively
wget -r https://example.com

## Mirror website
wget -m https://example.com

## Background download
wget -b https://example.com/file.zip

## Limit rate
wget --limit-rate=500k https://example.com/file.zip

netstat (network statistics):

## All connections
netstat -a

## Listening ports
netstat -l

## TCP connections
netstat -t

## UDP connections
netstat -u

## Show programs
netstat -p

## Numeric addresses
netstat -n

## Common combination
netstat -tulpn

ss (socket statistics):

## All sockets
ss -a

## Listening sockets
ss -l

## TCP sockets
ss -t

## Show process
ss -p

## Numeric ports
ss -n

## Common usage
ss -tulpn

Archive and Compression

tar (archive files)**:

## Create archive
tar -cvf archive.tar files/

## Create compressed archive (gzip)
tar -czvf archive.tar.gz files/

## Create compressed archive (bzip2)
tar -cjvf archive.tar.bz2 files/

## Extract archive
tar -xvf archive.tar

## Extract gzip archive
tar -xzvf archive.tar.gz

## List archive contents
tar -tvf archive.tar

## Extract to directory
tar -xzvf archive.tar.gz -C /path/to/dir

Compression Tools

gzip (compress):

## Compress file
gzip file.txt
## Creates file.txt.gz

## Keep original
gzip -k file.txt

## Decompress
gunzip file.txt.gz

## View compressed file
zcat file.txt.gz
zless file.txt.gz

zip/unzip:

## Create zip
zip archive.zip file1 file2

## Recursive zip
zip -r archive.zip directory/

## Unzip
unzip archive.zip

## List contents
unzip -l archive.zip

## Extract to directory
unzip archive.zip -d /path/to/dir

Process and System Management

ps (process status):

## Current processes
ps

## All processes
ps aux

## Process tree
ps auxf

## Specific user
ps -u username

kill (terminate process):

## Terminate process
kill PID

## Force kill
kill -9 PID

## Kill by name
killall process_name

which (locate command):

## Find command location
which python
which bash
which git

whereis (locate binary, source, manual):

## Find program files
whereis python
whereis bash

Useful Shortcuts and Tricks

Command History

## View history
history

## Execute previous command
!!

## Execute command by number
!123

## Last argument of previous command
!$

## Search history
Ctrl+R

## Clear history
history -c

Command Line Editing

## Beginning of line
Ctrl+A

## End of line
Ctrl+E

## Delete to end
Ctrl+K

## Delete to beginning
Ctrl+U

## Previous word
Alt+B

## Next word
Alt+F

## Clear screen
Ctrl+L

Redirection and Pipes

## Redirect output
command > file.txt

## Append output
command >> file.txt

## Redirect stderr
command 2> errors.txt

## Redirect both stdout and stderr
command &> output.txt

## Pipe output
command1 | command2

## Tee (output to file and stdout)
command | tee output.txt

Productivity Boosters

Aliases

Add to ~/.bashrc:

## Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ll='ls -lah'
alias la='ls -A'

## Safety
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

## Shortcuts
alias grep='grep --color=auto'
alias h='history'
alias c='clear'

## System
alias update='sudo apt update && sudo apt upgrade'
alias ports='netstat -tulpn'

Reload:

source ~/.bashrc

Functions

Add to ~/.bashrc:

## Create directory and cd into it
mkcd() {
    mkdir -p "$1" && cd "$1"
}

## Extract any archive
extract() {
    if [ -f "$1" ]; then
        case "$1" in
            *.tar.gz) tar xzf "$1" ;;
            *.tar.bz2) tar xjf "$1" ;;
            *.zip) unzip "$1" ;;
            *.rar) unrar x "$1" ;;
            *) echo "Unknown archive format" ;;
        esac
    else
        echo "File not found: $1"
    fi
}

## Backup file with timestamp
backup() {
    cp "$1" "$1.backup.$(date +%Y%m%d-%H%M%S)"
}

Quick Reference

Most Used Commands

## Files
ls -lh                     # List files
cd /path                   # Change directory
cat file.txt               # View file
less file.txt              # Page through file
cp source dest             # Copy
mv source dest             # Move/rename
rm file                    # Remove

## Text
grep pattern file          # Search
sed 's/old/new/' file      # Replace
awk '{print $1}' file      # Extract column
sort file                  # Sort lines
uniq file                  # Remove duplicates

## System
ps aux                     # List processes
top                        # Monitor processes
df -h                      # Disk usage
du -sh dir                 # Directory size
free -h                    # Memory usage

## Network
ping host                  # Test connectivity
curl URL                   # Transfer data
wget URL                   # Download file
netstat -tulpn             # Network connections

## Archive
tar -czf archive.tar.gz    # Create archive
tar -xzf archive.tar.gz    # Extract archive
zip -r archive.zip dir     # Create zip
unzip archive.zip          # Extract zip

Conclusion

Mastering these essential command-line tools significantly enhances productivity on Linux systems. From basic file operations to advanced text processing, networking utilities to system monitoring, these tools form the foundation of efficient Linux usage.

The key to proficiency is regular practice and understanding when to use each tool. Combined with aliases, functions, and shell scripting, these utilities enable powerful automation and streamlined workflows. As you become more comfortable with these tools, you’ll discover new ways to combine them for increasingly complex tasks.

Linux command-line proficiency is a journey—start with the basics, gradually incorporate more advanced tools, and continually refine your workflow for maximum efficiency.


References

Thank you for reading! If you have any feedback or comments, please send them to [email protected].