Skip to content

Instantly share code, notes, and snippets.

@copyleftdev
Created August 24, 2024 06:44
Show Gist options
  • Save copyleftdev/4440d1ee3b528b7a9153b732191d6c49 to your computer and use it in GitHub Desktop.
Save copyleftdev/4440d1ee3b528b7a9153b732191d6c49 to your computer and use it in GitHub Desktop.
Ultimate Linux Terminal Tricks Cheatsheet

๐Ÿš€ Ultimate Linux Terminal Tricks Cheatsheet

๐Ÿงญ Navigation Ninja

Command Description
cd - ๐Ÿ”™ Teleport to previous directory
pushd <dir> ๐Ÿ“š Change directory, save current to stack
popd ๐Ÿ“š Return to most recently pushed directory
cd ~ ๐Ÿ  Go to home directory
cd .. โฌ†๏ธ Go up one directory
pwd ๐Ÿ—บ๏ธ Print working directory
ls -lah ๐Ÿ“‹ List all files (including hidden) with details
tree ๐ŸŒณ Display directory structure

๐Ÿงน Tidy Terminal

Command Description
Ctrl + L ๐Ÿงผ Quick clear screen
reset ๐Ÿ”„ Deep clean terminal state
clear ๐Ÿงฝ Clear screen (alternative to Ctrl + L)
history -c ๐Ÿ—‘๏ธ Clear command history

๐ŸŽญ Multitasking Magic

Command Description
Ctrl + Z โธ๏ธ Suspend foreground process
fg โ–ถ๏ธ Resume most recent background job
bg ๐Ÿƒโ€โ™‚๏ธ Resume job in background
jobs ๐Ÿ“‹ List all background jobs
command & ๐Ÿƒโ€โ™‚๏ธ Run command in background
nohup command & ๐Ÿƒโ€โ™‚๏ธ๐Ÿ’ช Run command in background, immune to hangups
screen ๐Ÿ“บ Terminal multiplexer
tmux ๐Ÿ–ฅ๏ธ Terminal multiplexer (alternative to screen)

๐Ÿ” Sudo Sorcery

Command Description
sudo !! ๐Ÿง™โ€โ™‚๏ธ Re-run last command with sudo
sudo -i ๐Ÿ‘‘ Start a root shell
sudo -u <user> command ๐ŸŽญ Run command as another user
visudo ๐Ÿ“ Safely edit sudoers file

๐Ÿ“œ History Hacks

Command Description
Ctrl + R ๐Ÿ” Search command history
history ๐Ÿ“– Display full command history
!<number> ๐Ÿ”ข Run command by history number
!! โ†ฉ๏ธ Repeat last command
!$ ๐Ÿ”š Use last argument of previous command
!* ๐Ÿ”— Use all arguments of previous command
!string ๐Ÿ”ฎ Run most recent command starting with 'string'
export HISTTIMEFORMAT="%F %T " โฐ Add timestamps to history
export HISTCONTROL=ignorespace ๐Ÿ•ต๏ธ Hide commands starting with space
export HISTIGNORE="ls:cd:exit" ๐Ÿ™ˆ Ignore common commands in history

๐Ÿ–ฅ๏ธ Terminal Tweaks

Command Description
F11 ๐Ÿ–ฅ๏ธ Toggle fullscreen mode
Ctrl + Shift + Plus ๐Ÿ” Increase font size
Ctrl + Shift + Minus ๐Ÿ”Ž Decrease font size
Ctrl + Shift + C ๐Ÿ“‹ Copy selected text
Ctrl + Shift + V ๐Ÿ“‹ Paste clipboard content
tput cols ๐Ÿ“ Get terminal width
tput lines ๐Ÿ“ Get terminal height

โŒจ๏ธ Text Editing Tricks

Command Description
Ctrl + U โœ‚๏ธ Cut from cursor to line start
Ctrl + K โœ‚๏ธ Cut from cursor to line end
Ctrl + Y ๐Ÿ“‹ Paste previously cut text
Ctrl + A โฌ…๏ธ Move to start of line
Ctrl + E โžก๏ธ Move to end of line
Alt + B ๐Ÿ‘ˆ Move back one word
Alt + F ๐Ÿ‘‰ Move forward one word
Ctrl + W ๐Ÿ—‘๏ธ Delete word before cursor
Alt + D ๐Ÿ—‘๏ธ Delete word after cursor
Ctrl + _ โ†ฉ๏ธ Undo last edit

๐Ÿ”— Command Chaining

Command Description
command1 ; command2 ๐Ÿ”— Run commands sequentially
command1 && command2 โœ… Run command2 if command1 succeeds
command1 || command2 โŒ Run command2 if command1 fails
command1 | command2 ๐Ÿšฟ Pipe output of command1 to command2
command1 &> /dev/null ๐Ÿคซ Redirect all output to null

๐Ÿ“Š Output Optimization

Command Description
tail -f <file> ๐Ÿ‘€ Monitor file in real-time
head -n 20 <file> ๐Ÿ” Display first 20 lines of file
truncate -s 0 <file> ๐Ÿ—‘๏ธ Clear file contents
command | column -t ๐Ÿ“ Align output in columns
command | less ๐Ÿ“œ Paginate command output
command | tee <file> ๐Ÿ“๐Ÿ–ฅ๏ธ Write output to file and display on screen
command | xargs ๐Ÿ”จ Build command lines from standard input

๐Ÿ” File Search and Manipulation

Command Description
find . -name "*.txt" ๐Ÿ”Ž Find all .txt files in current directory and subdirectories
grep "pattern" <file> ๐Ÿ” Search for pattern in file
sed 's/foo/bar/g' <file> ๐Ÿ”„ Replace 'foo' with 'bar' in file
awk '{print $1}' <file> โœ‚๏ธ Print first column of file
sort <file> ๐Ÿ”ค Sort lines in file
uniq <file> ๐ŸŽญ Remove duplicate lines from file
wc -l <file> ๐Ÿ”ข Count lines in file

๐Ÿ’พ System Information

Command Description
uname -a ๐Ÿ’ป Display system information
lscpu ๐Ÿง  Display CPU information
free -h ๐Ÿงฎ Display memory usage
df -h ๐Ÿ’ฝ Display disk usage
du -sh * ๐Ÿ“‚ Display size of files and directories
ps aux ๐Ÿ”„ List all running processes
top ๐Ÿ“Š Dynamic real-time view of running processes
htop ๐Ÿ“ˆ Interactive process viewer

๐ŸŒ Networking

Command Description
ifconfig ๐Ÿ–ง Display network interfaces
ip addr ๐Ÿ–ง Modern alternative to ifconfig
netstat -tuln ๐Ÿ”Œ Display network connections
ss -tuln ๐Ÿ”Œ Modern alternative to netstat
ping <host> ๐Ÿ“ก Test network connectivity
traceroute <host> ๐Ÿ—บ๏ธ Trace route to host
nslookup <domain> ๐Ÿ” Query DNS
curl <url> ๐Ÿ“ฅ Transfer data from or to a server
wget <url> ๐Ÿ“ฅ Download files from the web

๐Ÿ”’ File Permissions

Command Description
chmod 755 <file> ๐Ÿ” Change file permissions
chown user:group <file> ๐Ÿ‘ค Change file owner and group
umask 022 ๐ŸŽญ Set default permissions for new files

๐Ÿ† Pro Tips

  1. ๐Ÿ’ก Use tab completion to save time
  2. ๐ŸŽจ Customize your shell prompt (PS1)
  3. ๐Ÿท๏ธ Create aliases for frequent commands
  4. ๐Ÿ“ Use Ctrl + X + E to edit long commands in text editor
  5. ๐Ÿ”ง Master Vim or Nano for quick edits
  6. ๐Ÿ“Š Use htop for system monitoring
  7. ๐Ÿ“ฆ Learn package management commands
  8. ๐Ÿง  Explore advanced shell features
  9. ๐Ÿ” Use SSH keys for secure remote access
  10. ๐Ÿ“œ Write shell scripts to automate repetitive tasks
  11. ๐Ÿ” Learn regular expressions for powerful text processing
  12. ๐Ÿ“š Read man pages (man <command>) to learn more about commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment