๐Ÿ‘จโ€๐Ÿซ Tutorial Linux Command Line: Tips & Tricks for Power Users

Paul25

Honorary Poster

๐Ÿš€ The Essentials Everyone Should Know​



CommandWhat It Does
man <command>Read the manual for any command
<command> --helpQuick help for most commands
historyShow your command history
!!Re-run the last command
!$Use the last argument of the previous command
Ctrl + RReverse-search your command history
Ctrl + LClear the terminal screen
Ctrl + CKill the running command
Ctrl + DExit the terminal / send EOF
TabAuto-complete file names & commands
Tab TabShow all possible completions

๐Ÿ“‚ File & Directory Navigation​

bash
cd - # Jump back to the previous directory
cd ~ # Go to your home directory
pushd /tmp && popd # Save & return to a directory
ls -lah # Human-readable sizes, hidden files, long format
ls -lt # Sort by modification time (newest first)
tree -L 2 # Show directory tree, 2 levels deep
find . -name "*.log" -mtime +7 # Find .log files older than 7 days
Pro tip: Use zoxide or autojump for smarter cd โ€” it learns your most-used directories.

bash
z project # Jumps to your most-visited "project" folder

๐Ÿ” Searching Like a Pro​

bash
grep -rin "error" /var/log/ # Recursive, case-insensitive, line numbers
grep -v "debug" app.log # Invert match (exclude lines)
rg "pattern" . # ripgrep โ€” blazing fast alternative
find . -type f -exec grep -l "TODO" {} + # Files containing TODO
locate filename # Instant search (run sudo updatedb first)
ripgrep (rg) is a modern replacement for grep โ€” install it with sudo apt install ripgrep.


๐Ÿ“œ History & Aliases​

bash
alias ll='ls -lah' # Create a shortcut
alias ..='cd ..' # Quick parent dir
alias gs='git status'
unalias ll # Remove an alias
Make aliases permanent โ€” add them to ~/.bashrc or ~/.zshrc:

bash
echo "alias ll='ls -lah'" >> ~/.bashrc
source ~/.bashrc
History tricks:

bash
history | grep ssh # Find past ssh commands
!123 # Run command #123 from history
sudo !!

๐Ÿ”€ *****, Redirection & Chaining​

bash
command > file # Overwrite file
command >> file # Append to file
command 2> error.log # Redirect stderr only
command &> all.log # Redirect both stdout & stderr
command1 && command2 # Run cmd2 only if cmd1 succeeds
command1 || command2 # Run cmd2 only if cmd1 fails
command1 | tee out.txt # Show output AND save to file
Real-world example:

bash
ps aux | grep nginx | grep -v grep | awk '{print $2}' | xargs kill -9

โšก Process Management​

bash
htop # Interactive process viewer (better than top)
ps aux | grep <name> # Find a process
pgrep -af <name> # Find process by name with full command
kill -9 <PID> # Force kill
pkill -f "python app.py" # Kill by command pattern
nohup ./script.sh & # Run in background, survives logout
disown # Detach a running job from the shell
Background job control:

bash
Ctrl + Z # Suspend current process
bg # Resume it in the background
fg # Bring it back to foreground
jobs # List background jobs

๐Ÿ” Permissions & Ownership​

bash
chmod +x script.sh # Make executable
chmod 755 file # rwxr-xr-x
chmod 644 file # rw-r--r--
chown user:group file # Change owner and group
chown -R user:group dir/ # Recursive
umask 022 # Default permission mask
Quick octal reference:



ValuePermission
7rwx
6rw-
5r-x
4r--
0---

๐ŸŒ Networking​

bash
ip a # Show IP addresses (modern replacement for ifconfig)
ip r # Show routing table
ss -tulnp # Show listening ports (better than netstat)
curl -I You do not have permission to view the full content of this post. Log in or register now. # Get HTTP headers only
curl -O You do not have permission to view the full content of this post. Log in or register now. # Download file
wget -c You do not have permission to view the full content of this post. Log in or register now. # Resume a partial download
ping -c 4 google.com
traceroute google.com
nmap -sV 192.168.1.1 # Scan ports & services
Transfer files:

bash
scp file.txt user@host:/path/ # Copy to remote
rsync -avz --progress src/ user@host:/dst/ # Sync with progress

๐Ÿ’พ Disk & Storage​

bash
df -h # Disk space (human-readable)
du -sh * # Size of each item in current dir
du -sh */ | sort -h # Sorted by size
ncdu # Interactive disk usage explorer
lsblk # List block devices
mount | column -t # Show mounts nicely
Find largest files:

bash
find / -type f -size +100M 2>/dev/null

๐Ÿง  Text Processing Power Moves​

bash
awk '{print $1, $3}' file.txt # Print columns 1 and 3
sed 's/old/new/g' file.txt # Replace all occurrences
sort file.txt | uniq -c | sort -rn # Count duplicates, sort by frequency
cut -d',' -f2 data.csv # Get 2nd CSV column
tr 'a-z' 'A-Z' < file.txt # Uppercase
head -n 20 file.txt # First 20 lines
tail -f /var/log/syslog # Follow a log live
wc -l file.txt # Count lines
One-liner: top 10 most frequent words in a file

bash
tr -c '[:alnum:]' '[\n*]' < file.txt | sort | uniq -c | sort -rn | head

๐Ÿ› ๏ธ Handy System Info​

bash
uname -a # Kernel & system info
lsb_release -a # Distro info
lscpu # CPU details
free -h # RAM usage
uptime # How long system has been running
whoami # Current user
id # User & group IDs
neofetch # Pretty system summary (install separately)

๐Ÿ“ฆ Package Management Cheatsheet​

Debian/Ubuntu (apt):

bash
sudo apt update && sudo apt upgrade -y
sudo apt install <pkg>
sudo apt remove <pkg>
apt search <term>
dpkg -l | grep <pkg>
Fedora/RHEL (dnf):

bash
sudo dnf install <pkg>
sudo dnf upgrade --refresh
Arch (pacman):

bash
sudo pacman -Syu
sudo pacman -S <pkg>
Universal:

bash
snap install <pkg>
flatpak install <pkg>

๐Ÿ”ฅ Power User Tricks​

1. Run a command as another user​

bash
sudo -u www-data ls /var/www

2. Watch a command's output repeatedly​

bash
watch -n 2 'df -h'

3. Create a file instantly​

bash
newfile.txt # Empty file
touch newfile.txt # Also empty

4. Extract any archive​

bash
tar -xzvf file.tar.gz
tar -xjvf file.tar.bz2
unzip file.zip
7z x file.7z

5. Create a tarball​

bash
tar -czvf backup.tar.gz /path/to/folder

6. Compare two files​

bash
diff file1 file2
vimdiff file1 file2 # Side-by-side in vim

7. Generate a random password​

bash
openssl rand -base64 16

8. Serve current directory over HTTP​

bash
python3 -m http.server 8000

9. SSH without password (key-based auth)​

bash
ssh-keygen -t ed25519
ssh-copy-id user@host

10. Keep SSH sessions alive​

Add to ~/.ssh/config:

text
Host *
ServerAliveInterval 60

๐Ÿงฐ Must-Have Modern Tools​



ToolReplacesWhy
ripgrep (rg)grepFaster, respects .gitignore
fdfindSimpler syntax, faster
batcatSyntax highlighting + git diff
eza / exalsIcons, colors, tree view
zoxidecdSmarter directory jumping
fzfโ€”Fuzzy finder for everything
tmuxscreenTerminal multiplexer
jqโ€”Parse JSON in terminal
htoptopBetter process viewer
ncduduInteractive disk usage
Install them all (Ubuntu):

bash
sudo apt install ripgrep fd-find bat fzf jq htop ncdu tmux

๐ŸŽฏ FZF: The Game Changer​

Install fzf and add this to your ~/.bashrc:

bash
# Ctrl+R for fuzzy history search
# Ctrl+T for fuzzy file finder
# Alt+C for fuzzy cd
Killer combos:

bash
vim $(fzf) # Open a file from fuzzy search
kill -9 $(ps aux | fzf | awk '{print $2}')



๐Ÿ”— Resources​



TL;DR: Master Tab, Ctrl+R, *****, and fzf. Then add ripgrep, fd, bat, and zoxide. You'll feel like a wizard in a week. ๐Ÿง™โ€โ™‚๏ธ
 

About this Thread

  • 0
    Replies
  • 14
    Views
  • 1
    Participants
Last reply from:
Paul25

Trending Topics

Online now

Members online
987
Guests online
2,919
Total visitors
3,906

Forum statistics

Threads
2,332,131
Posts
29,262,788
Members
1,146,073
Latest member
kingjade26
Back
Top