Hide

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.

Hide

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:

Hide

News

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.
Hide

Tags

Hide

Functions

Commands using tail from sorted by
Terminal - Commands using tail - 231 results
watch 'ls -tr1 | tail -n1 | xargs tail'
2013-05-09 11:37:59
User: batandwa
Functions: tail watch xargs
Tags: tail ls xargs watch
-5

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
0

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
-9

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
1

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

ls -lT -rt | grep "^-" | awk 'BEGIN {START=2002} (START <= $9){ print $10 ;START=$9 }' | tail -1
2013-02-24 23:39:22
User: Glamdring
Functions: awk grep ls tail
Tags: ls date osx
0

On the Mac, the 'ls' function can sort based on month/day/time, but seems to lack ability to filter on the Year field (#9 among the long listed fields). The sorted list continuously increases the 'START' year for the most recently accessed set of files. The final month printed will be the highest month that appeared in that START year. The command does its magic on the current directory, and suitably discards all entries that are themselves directories. If you expect files dating prior to 2002, change the START year accordingly.

(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
4

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

while true; do (date | tr "\n" ";") && ping -q -c 1 www.google.com|tail -1|cut -d/ -f5 ;sleep 1; done >> uptime.csv
2013-02-06 22:06:09
User: fanchok
Functions: cut date ping sleep tail tr
0

Used in OS X.

tr "\n" ";"

may be replaced by

echo ";"

with linux versions of date.

I reused

ping -q -c 1 www.google.com|tail -1|cut -d/ -f5

largest() { dir=${1:-"./"}; count=${2:-"10"}; echo "Getting top $count largest files in $dir"; du -sx "$dir/"* | sort -nk 1 | tail -n $count | cut -f2 | xargs -I file du -shx file; }
2013-01-21 09:45:21
User: jhyland87
Functions: cut du echo file sort tail xargs
1

You can simply run "largest", and list the top 10 files/directories in ./, or you can pass two parameters, the first being the directory, the 2nd being the limit of files to display.

Best off putting this in your bashrc or bash_profile file

find . -type f -printf "%T@ %Tc %p\n" |sort -n |cut -d' ' -f2- |tail -n20
tail -1000 `ls -ltr /var/log/CF* |tail -1|awk '{print $9}'`|cut -d "," -f 17|sort|uniq -c |sort -k2
2012-11-30 16:30:41
User: raindylong
Functions: awk cut sort tail uniq
0

count & sort one field of the log files , such as nginx/apache access log files .

tail -F logfile
tail -f /var/log/messages.log | while read line ; do echo $line | cut -d \ -f5- | sed s/\\[[0-9]*\\]// | espeak ; done
tail +56 file > newfile
2012-10-26 03:04:12
User: basic612
Functions: file tail
0

'newfile' will have content of 'file' minus first 55 lines

to delete first line only do:

tail +2 file > newfile

du -sm /home/* | sort -n | tail -10
end_w_nl() { [[ $(tail -c1 $1 | xxd -ps) == 0a ]] }
2012-09-18 20:11:29
User: xro
Functions: tail
Tags: tail xxd zsh
0
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 -n +2 foo.txt
ls -rt | tail -n 1
lsmod | tail -n +2 | cut -d' ' -f1 | xargs modinfo | egrep '^file|^desc|^dep' | sed -e'/^dep/s/$/\n/g'
ifconfig | grep "inet" | tail -1 | awk '{print $2}'
systemctl --failed | head -n -6 | tail -n -1
find . -name "fullcalib4.csv" -exec tail -n1 \{\} \; >>all.csv
amixer -c 0 set Master toggle | tail -1 | awk '{print $4}' | sed "s/[^0-9]//g" ; amixer -c 0 set Speaker toggle >/dev/null; amixer -c 0 set Front toggle >/dev/null
tail -f logfile | logtop
2012-06-24 19:18:30
User: Sizeof
Functions: tail
Tags: tail
-1

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

curl -s kernel.org | grep '<strong>' | head -3 | tail -1 | cut -d'>' -f3 | cut -d'<' -f1
cp $(find /media/ -type f -name "*.wav" -printf "%T@ %h/%f\n" | sort | tail -1 | awk '{ print $2 }') .
2012-06-01 12:45:43
User: hamoid
Functions: awk cp find sort tail
0

Watch out if you have several USB drives plugged in: it scans the whole /media/ folder !!! You can replace /media/ by the path of a specific USB drive (something like /media/F77A-530B/)

I use a sound recorder and I want to plug the recorder and grab the most recent sound.

That's what this command does.

Use mv instead of cp to move instead of copy.

Change *.wav to the required file type.