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.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.


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:



2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.




Commands tagged tail from sorted by
Terminal - Commands tagged tail - 53 results
rsstail -o -n 1 --f 'RedditQuote: {title}' http://www.reddit.com/r/quotes/new/.rss
2014-01-08 15:33:48
User: Youpfu

The rsstail is the python version (python-rsstail). The final command pipe it on every new line to gammu and a connected phone

rsstail -o -n 1 --f 'RedditQuote: {title}' http://www.reddit.com/r/quotes/new/.rss | while read line; do /usr/bin/gammu --sendsms TEXT +*yournumber* -text "$line"; done
dig +short <domain>
host example.com | head -1 | awk '{print $4}'
nslookup www.example.com | tail -2 | head -1 | awk '{print $2}'
2013-09-05 20:26:45
User: wsams
Functions: awk head nslookup tail

I'm not sure how reliable this command is, but it works for my needs. Here's also a variant using grep.

nslookup www.example.com | grep "^Address: " | awk '{print $2}'

tail -F some.log | perl -ne 'print time(), "\n";' | uniq -c
watch 'ls -tr1 | tail -n1 | xargs tail'
2013-05-09 11:37:59
User: batandwa
Functions: tail watch xargs
Tags: tail ls xargs watch

Watches for file modifications in the current directory and tails the file.

history | tail -100 | grep cmd
2013-04-22 03:49:43
User: datamining
Functions: grep tail

this also can find the old command you used before

cat .bash_history | tail -100 | grep {command}
2013-04-10 10:40:52
User: techie
Functions: cat grep tail

I know how hard it is to find an old command running through all the files because you couldn't remember for your life what it was. Heres the solution!! Grep the history for it. depending on how old the command you can head or tail or if you wanted to search all because you cannot think how long ago it was then miss out the middle part of the command. This is a very easy and effective way to find that command you are looking for.

ls -Sh **/*(.Lm+100) | tail -5
2013-03-21 20:22:11
User: khayyam
Functions: ls tail
Tags: tail ls zsh

zsh: list of files sorted by size, greater than 100mb, head the top 5. '**/*' is recursive, and the glob qualifiers provide '.' = regular file, 'L' size, which is followed by 'm' = 'megabyte', and finally '+100' = a value of 100

(echo -e "HTTP/1.1 200 Ok\n\r"; tail -f /var/log/syslog) | nc -l 1234
2013-02-09 06:15:42
User: adimania
Functions: echo tail

This one is tried and tested for Ubuntu 12.04. Works great for tailing any file over http.

/usr/bin/tail -fn0 /path/to/apache_error.log | while read line; do /usr/local/bin/growlnotify --title "Apache Notice" --message "$line"; done &
2013-01-22 05:25:41
User: jhyland87
Functions: read

Simply add this to whatever apache startup script you have, or if you are on a MAC, create a new automator application. This will show a pretty growl notification whenever theres a new Apache error log entry. Useful for local development

ssh -t HOSTNAME 'tail -f LOGFILE' | while read; do growlnotify -t "TITLE" -m "$REPLY"; done
end_w_nl() { [[ $(tail -c1 $1 | xxd -ps) == 0a ]] }
2012-09-18 20:11:29
User: xro
Functions: tail
Tags: tail xxd zsh
end_w_nl filename

will check if the last byte of filename is a unix newline character. tail -c1 yields the file's last byte and xxd converts it to hex format.

tail -f logfile | logtop
2012-06-24 19:18:30
User: Sizeof
Functions: tail
Tags: tail

logtop show number of lines per second, also classify them so you can show a "top" of every aspect of your logfile :

tail -f access.log | awk '{print $1; fflush();}' | logtop

tail -F /var/log/nginx/access.log | python -c 'exec("import sys,time\nl=0\ne=int(time.time())\nfor line in sys.stdin:\n\tt = int(time.time())\n\tl += 1\n\tif t > e:\n\t\te = t\n\t\tprint l\n\t\tl = 0")'
2012-05-15 21:56:46
User: pykler
Functions: python tail

Realtime lines per second in a log file using python ... identical to perl version, except python is much better :)

cal 04 2012 | awk 'NF <= 7 { print $7 }' | grep -v "^$" | tail -1
2012-05-03 16:57:45
User: javidjamae
Functions: awk cal grep tail

This is a little trickier than finding the last Sunday, because you know the last Sunday is in the first position of the last line. The trick is to use the NF less than or equal to 7 so it picks up all the lines then grep out any empty lines.

tail() { thbin="/usr/bin/tail"; if [ "${1:0:1}" != "-" ]; then fc=$(($#==0?1:$#)); lpf="$((($LINES - 3 - 2 * $fc) / $fc))"; lpf="$(($lpf<1?2:$lpf))"; [ $fc -eq 1 ] && $thbin -n $lpf "$@" | /usr/bin/fold -w $COLUMNS | $thbin -n $lpf || $thbin -n $lpf...
2012-03-23 19:00:30
User: fpunktk
Functions: tail
tail() { thbin="/usr/bin/tail"; if [ "${1:0:1}" != "-" ]; then fc=$(($#==0?1:$#)); lpf="$((($LINES - 3 - 2 * $fc) / $fc))"; lpf="$(($lpf<1?2:$lpf))"; [ $fc -eq 1 ] && $thbin -n $lpf "$@" | /usr/bin/fold -w $COLUMNS | $thbin -n $lpf || $thbin -n $lpf "$@"; else $thbin "$@"; fi; unset lpf fc thbin; }

This is a function that implements an improved version of tail. It tries to limit the number of lines so that the screen is filled completely. It works with pipes, single and multiple files. If you add different options to tail, they will overwrite the settings from the function.

It doesn't work very well when too many files (with wrapped lines) are specified.

Its optimised for my three-line prompt.

It also works for head. Just s/tail/head/g

Don't set 'thbin="tail"', this might lead to a forkbomb.

alias tail='tail -n $((${LINES:-`tput lines 2>/dev/null||echo -n 80`} - 7))'
2012-03-22 02:44:11
User: AskApache
Functions: alias echo

Run the alias command, then issue

ps aux | tail

and resize your terminal window (putty/console/hyperterm/xterm/etc) then issue the same command and you'll understand.

${LINES:-`tput lines 2>/dev/null||echo -n 12`}

Insructs the shell that if LINES is not set or null to use the output from `tput lines` ( ncurses based terminal access ) to get the number of lines in your terminal. But furthermore, in case that doesn't work either, it will default to using the default of 80.

The default for TAIL is to output the last 10 lines, this alias changes the default to output the last x lines instead, where x is the number of lines currently displayed on your terminal - 7. The -7 is there so that the top line displayed is the command you ran that used TAIL, ie the prompt.

Depending on whether your PS1 and/or PROMPT_COMMAND output more than 1 line (mine is 3) you will want to increase from -2. So with my prompt being the following, I need -7, or - 5 if I only want to display the commandline at the top. ( http://www.askapache.com/linux/bash-power-prompt.html )


[7995:7993 - 0:186] 06:26:49 Thu Apr 08 [askapache@n1-backbone5:/dev/pts/0 +1] ~

In most shells the LINES variable is created automatically at login and updated when the terminal is resized (28 linux, 23/20 others for SIGWINCH) to contain the number of vertical lines that can fit in your terminal window. Because the alias doesn't hard-code the current LINES but relys on the $LINES variable, this is a dynamic alias that will always work on a tty device.

ls -t | head
2012-01-17 16:28:32
User: scottlinux
Functions: ls
Tags: tail ls head,

This will quickly display files last changed in a directory, with the newest on top.

tcpflow -c port 80 | grep Host
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -print0 | xargs -0 wc -l | tail -1
ls -lFart |tail -n1
2011-10-17 19:49:14
User: jambino
Functions: ls tail
Tags: tail pipe ls

List all files in a directory in reverse order by modified timestamp. When piped through tail the user will see the most recent file name.

multitail -l 'ssh machine1 "tail -f /var/log/apache2/error.log"' -l 'ssh machine2 "tail -f /var/log/apache2/error.log"'
2011-10-12 10:05:18

this way you have the multitail with all its options running on your own machine with the tails of the two remote machines inside :)

tail -n +<N> <file> | head -n 1
2011-09-30 08:30:30
User: qweqq
Functions: head tail

Tail is much faster than sed, awk because it doesn't check for regular expressions.

tail -f LOGFILE | awk '{system("say \"" $0 "\"");}'
2011-09-16 06:20:06
User: tamouse
Functions: awk tail
Tags: awk tail say

like #9295, but awkish instead of perlish