What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands using host from sorted by
Terminal - Commands using host - 40 results
host -t srv _ldap._tcp | sed "s/.*[ ]\([^ ]*\)[.]$/\1/g" | xargs -i ping -c 1 {} | grep -E "(statistics|avg)" | sed "s/^--- \([^ ]*\).*/,\1:/g"|tr -d "\n" | tr "," "\n" | sed "1d;s|^\([^:]*\).*=[^/]*/\([^/]*\).*|\2\t\1|g" |sort -n
2016-09-02 03:26:29
User: glaudiston
Functions: grep host ping sed sort tr xargs
Tags: ldap

This command line detect ldap hosts, by mandatory dns entry, then ping them to detect response average. based on ping response average it sorts and print the faster server in first output line

host `hostname` | rev | cut -d' ' f1 | rev
2014-10-01 18:55:05
Functions: cut host rev

Gives the DNS listed IP for the host you're on... or replace `hostname` with any other host

host -t a www.google.com
host -t TXT _netblocks.google.com
host example.com | head -1 | awk '{print $4}'
for i in `ip addr show dev eth1 | grep inet | awk '{print $2}' | cut -d/ -f1`; do echo -n $i; echo -en '\t'; host $i | awk '{print $5}'; done
tcpdump host <IP> -nXXv -s0 -w file.pcap
tcpdump -s 1024 -l -A -n host
2013-02-02 22:29:52
User: wejn
Functions: host tcpdump
Tags: http tcpdump

This is a better way to do the "src X or dst X" filter; plus you might not want to bother with DNS lookups (-n).

for host in $HOSTNAMES; do ping -q -c3 $host && ssh $host 'command' & for count in {1..15}; do sleep 1; jobs | wc -l | grep -q ^0\$ && continue; done; kill %1; done &>/dev/null
for host in $MYHOSTS; do ping -q -c3 $H 2>&1 1>/dev/null && ssh -o 'AllowedAuthe ntications publickey' $host 'command1; command2' & for count in 1 2 3 4 5; do sleep 1; jobs | wc -l | grep -q ^0\$ && continue; done; kill %1; done
2012-11-13 23:12:27
User: a8ksh4
Functions: grep host jobs kill ping sleep ssh wc

Execute commands serially on a list of hosts. Each ssh connection is made in the background so that if, after five seconds, it hasn't closed, it will be killed and the script will go on to the next system.

Maybe there's an easier way to set a timeout in the ssh options...

ngrep host -O $(date +%Y%m%d_%H%M%S).pcap > $(date +%Y%m%d_%H%M%S).txt
lsof -p `pidof pidgin` | awk '{ print $9 }'|egrep `hostname` | grep -o ">[^:]\+:" | tr -d ":>" | while read line; do host $line; done;
nc -zvw 1 host port
2012-07-13 20:02:17
User: akhilravidas
Functions: host
Tags: netcat

Try to perform a fully TCP 3 way handshake on for a given host-port with a timeout of 1s.

sudo tcpdump -n -i eth0 -w data.pcap -v tcp or udp and 'not host'
hostresult=$(host -t A www.example.com); echo "${hostresult##* }"
2011-04-21 10:16:50
User: kilx
Functions: echo host

The host command comes with the bind-utils package, which is has a better chance to be installed than resolveip from mysql. The last word of the query result is displayed, which is the last result host got.

This works with CNAMEs.

You get "3(NXDOMAIN)" in case of failure.

pdsh -R ssh -w se00[1-5] # a list of host names
2011-03-10 18:29:24
User: dexterhu
Functions: host ssh

parrallel execution of a command on remote host by ssh or rsh or ...

very useful for cluster management (software update)

host google.com|awk '{print $NF}'
host foo.com|grep " has address "|cut -d" " -f4
2010-10-29 17:01:37
User: dinomite
Functions: cut grep host

Get just the IP address for a given hostname. For best results, make this a function in your shell rc file so that it can be used for things like traceroute:

Titus:~$ traceroute `getip foo.com`

traceroute to (, 64 hops max, 52 byte packets

for host in host1 host2 host3; do ssh -n user@$host <command> > $host.log & done; wait
2010-07-14 14:55:31
User: cout
Functions: host ssh

Ssh to host1, host2, and host3, executing on each host and saving the output in {host}.log.

I don't have the 'parallel' command installed, otherwise it sounds interesting and less cryptic.

echo data | nc -q 0 host 5000
2010-06-26 11:57:55
User: strake
Functions: echo host

With no '-q 0' switch, nc simply waits, and whatever awaits the data hangs.

ssh host -l user $(<cmd.txt)
2010-06-04 17:47:00
User: recursiverse
Functions: host ssh

Much simpler method. More portable version: ssh host -l user "`cat cmd.txt`"

perl -e 'system @ARGV, <STDIN>' ssh host -l user < cmd.txt
2010-06-04 17:27:20
User: recursiverse
Functions: host perl ssh

I was tired of the endless quoting, unquoting, re-quoting, and escaping characters that left me with working, but barely comprehensible shell one-liners. It can be really frustrating, especially if the local and remote shells differ and have their own escaping and quoting rules. I decided to try a different approach and ended up with this.

for host in *; do { if [ -d $host ]; then { cd ${host}; for share in *; do { if [ -d $share ]; then { cd $share; rsync -av --delete rsyncuser@$host::$share . 2>../$share.err 1>../$share.log; cd ..; }; fi; }; done; cd ..; }; fi; }; done;
2010-03-11 19:54:31
User: c3w
Functions: cd host rsync
Tags: rsync

traverses e.g. "/data/myhost1.com/myrsyncshare"; logs stderr and stdout. useful with cron.

for host in $(cat ftps.txt) ; do if echo -en "o $host 21\nquit\n" |telnet 2>/dev/null |grep -v 'Connected to' >/dev/null; then echo -en "FTP $host KO\n"; fi done
2010-01-26 15:34:18
User: vlan7
Functions: cat echo grep host telnet

I must monitorize a couple of ftp servers every morning WITHOUT a port-scanner

Instead of ftp'ing on 100 ftp servers manually to test their status I use this loop.

It might be adaptable to other services, however it may require a 'logout' string instead of 'quit'.

The file ftps.txt contains the full list of ftp servers to monitorize.

mysqldump -u user -h host -ppwd -B dbname | bzip2 -zc9 > dbname.sql.bz2
2010-01-19 07:34:21
User: olaseni
Functions: bzip2 host

To also move the db backup to another location you could pass the output to the dd command instead of a file

mysqldump -u user -h host -ppwd -B dbname | bzip2 -zc9 | dd ssh [email protected] "dd of=db_dump"