Top 30 linux shell tricks Cheat Sheet

A Software › Linux cheat sheet in English by TME520

The top 30 Linux shell tricks from https://www.commandlinefu.com

16,976 views 3,436 downloads 17 Oct 2018 History
4.9 avg · 1 rating

Top 30

Run the last command as root
sudo !!
Serve current directory tree at http:/­/$H­OST­NAM­E:8­000/**
python -m Simple­HTT­PServer
Runs previous command but replacing
echo "­Hello Morld"
 
^Morld­^World
 
echo "­Hello World"
Rapidly invoke an editor to write a long command
[ctrl+x e]
Place the argument of the most recent command on the shell
'­ALT­+.' or '­<ES­C> .'
Salvage a borked terminal
reset
List currently mounted filesy­stems in nice layout
mount | column -t
Get your external IP address
curl ifconf­ig.me
Execute a command at a given time
echo "ls -l" | at midnight
Output your microphone to a remote comput­er's speaker
dd if=/de­v/dsp | ssh -c arcfour -C userna­me@host dd of=/de­v/dsp
Type partial command, check something, resume typing
vi /etc/ssh/ [ctrl+u]
 
ls -lisa /etc/ssh/
 
[ctrl+y] vi /etc/s­sh/­ssh­_config
Mount folder­/fi­les­ystem through SSH
sshfs name@s­erv­er:­/pa­th/­to/­folder /path/­to/­mou­nt/­point
Mount a temporary ram partition
mount -t tmpfs tmpfs /mnt -o size=1024m
Download an entire website
wget --rand­om-wait -r -p -e robots=off -U mozilla http:/­/ww­w.e­xam­ple.com`
Clear the terminal screen
[ctrl+l]
Compare a remote file with a local file
ssh user@host cat /path/­to/­rem­otefile | diff /path/­to/­loc­alfile -
Update twitter via curl
curl -u user:pass -d status­="Tw­eeting from the shell" http:/­/tw­itt­er.c­om­/st­atu­ses­/up­dat­e.xml`
SSH connection through host in the middle
ssh -t reacha­ble­_host ssh unreac­hab­le_host
Close shell keeping all subprocess running
disown -a && exit
Make '­les­s' behave like 'tail -f'
less +F somelo­gfile
Put a console clock in top right corner
while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-­29)­);d­ate­;tput rc;done &
Shutdown a Windows machine from Linux
net rpc shutdown -I ipAddr­ess­OfW­ind­owsPC -U userna­me%­pas­sword
List of commands you use most often
history | awk '­{a[­$2]­++}­END­{for(i in a){print a[i] " " i}}' | sort -rn | head
32 bits or 64 bits?
getconf LONG_BIT
Set audible alarm when an IP address comes online
ping -i 60 -a IP_address
Reboot machine when everything is hanging
<al­t> + <print screen/sys rq> + <R> - <S> - <E> - <I> - <U> - <B>
Simulate typing
echo "You can simulate on-screen typing just like in the movies­" | pv -qL 10
Quickly rename a file
mv filena­me.{­ol­d,new}
Escape any command aliases
\[command]
Delete all files in a folder that don't match a certain file extension
rm !(.foo|.bar|*.baz)

Bonus: Tricks of the ancient UNIX masters

Reuse all parameter of the previous command line
!*
Sharing file through http 80 port
nc -v -l 80 < file.ext
Display a block of text with AWK
awk '­/st­art­_pa­tte­rn/­,/s­top­_pa­tte­rn/­' file.txt
Kills a process that is locking a file
fuser -k filename
Display all current terminal settings
stty -a
Type a string, hit [ctrl+d] and see the ASCII codes
od -cx

Badges

Nice Cheat Sheet Good Cheat Sheet Downloaded from Unusual Locations × 3

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.