Linux One-liner cheat sheet…

Everyday, you seem to use the same commands over and over again, but you still forget which parameters you should enter to do this or do that…

Here is a list of commonly used everyday commands, hope you find it useful…

Also let me know if you wish to see something here…



archives and compression

tar zcf file.tar.gz /some/path

Compresses the path (file/folder) and create a tar.gz file

tar zxf file.tar.gz

De-Compresses the .tar.gz file to the current working directory

tar jcf file.tar.bz2 /some/path

Compresses the path (file/folder) and create a tar.bz2 file (better compression but slower)

tar jxf file.tar.bz2

De-Compresses the .tar.bz2 file to the current working directory

find dir/ -name ‘*.txt’ | tar -c –files-from=- | bzip2 > dir_txt.tar.bz2

Make archive of subset of dir/ and below

find dir/ -name ‘*.txt’ | xargs cp -a –target-directory=dir_txt/ –parents

Make copy of subset of dir/ and below

rsync (Network efficient file copier: Use the –dry-run option for testing)

rsync -P rsync:// file

Only get diffs. Do multiple times for troublesome downloads

rsync –bwlimit=1000 fromfile tofile

Locally copy with rate limit. It’s like nice for I/O

wget (multi purpose download tool)

(cd cli && wget -nd -pHEKk

Store local browsable version of a page to the current dir

wget -c

Continue downloading a partially downloaded file

wget -r -nd -np -l1 -A ‘*.jpg’

Download a set of files to the current directory

echo ‘wget url’ | at 01:00

Download url at 1AM to current dir

wget –limit-rate=20k url

Do a low priority download (limit to 20KB/s in this case)


ethtool eth0

Show status of ethernet interface eth0

ifconfig|grep inet

Shows current IPs (usefull for machines with lots of virtual interfaces)

route -n

Shows current routing table


Lookup DNS ip address for name or vice versa

netstat -tupl

List internet services on a system

netstat -tup

List active connections to/from system

Text manipulation

sed ‘s/string1/string2/g’ input-file

Replace string1 with string2 from input-file and prints to stdout

sed ‘/ *#/d; /^ *$/d’

Remove comments and blank lines (useful for cleaning config files)

sed -n ‘1000p;1000q’

Print 1000th line

sed -n ‘10,20p;20q’

Print lines 10 to 20

sed -i 42d ~/.ssh/known_hosts

Delete a particular line

sort -t. -k1,1n -k2,2n -k3,3n -k4,4n

Sort IPV4 ip addresses

Disk space

ls -lSr

Show files by size, biggest last

df -h

Show free space on mounted filesystems

fdisk -l

Show disks partitions sizes and types (run as root)

rpm -q -a –qf ‘%10{SIZE}\t%{NAME}\n’ | sort -k1,1n

List all packages by installed size (Bytes) on rpm distros

dpkg-query -W -f=’${Installed-Size;10}\t${Package}\n’ | sort -k1,1n

List all packages by installed size (KBytes) on deb distros

Monitoring / Debugging

tail -f /var/log/messages

Monitor messages in a log file

lsof -p $$

List paths that process id $$ has open

tcpdump not port 22

Show network traffic except ssh port traffic

ps -e -o pcpu,cpu,nice,state,cputime,args –sort pcpu

List processes by % cpu usage

last reboot

Show system reboot history

free -m

Show amount of (remaining) RAM (-m displays in MB)

Other cheat sheets can be found on this URL, I love this guy’s mod_rewrite cheat sheet, it’s really helpful…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: