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.

Universal configuration monitoring and system of record for IT.

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 less from sorted by
Terminal - Commands using less - 50 results
Command in description (Your command is too long - please keep it to less than 255 characters)
2011-02-03 08:25:42
User: __
Functions: command less
yt2mp3(){ for j in `seq 1 301`;do i=`curl -s gdata.youtube.com/feeds/api/users/$1/uploads\?start-index=$j\&max-results=1|grep -o "watch[^&]*"`;ffmpeg -i `wget youtube.com/$i -qO-|grep -o 'url_map"[^,]*'|sed -n '1{s_.*|__;s_\\\__g;p}'` -vn -ab 128k "`youtube-dl -e ${i#*=}`.mp3";done;}

squeezed the monster (and nifty ☺) command from 7776 from 531 characters to 284 characters, but I don't see a way to get it down to 255. This is definitely a kludge!

Command in description (Your command is too long - please keep it to less than 255 characters)
2011-02-01 17:36:32
User: m1cawber
Functions: command less
yt-mp3chanrip() { for count in 1 51 101 151 201 251 301; do for i in $(curl -s http://gdata.youtube.com/feeds/api/users/"$1"/uploads\?start-index="$count"\&max-results=50 | grep -Eo "watch\?v=[^[:space:]\"\'\\]{11}" | uniq); do ffmpeg -i $(wget http://youtube.com/"$i" -qO- | sed -n "/fmt_url_map/{s/[\'\"\|]/\n/g;p}" | sed -n '/^fmt_url_map/,/videoplayback/p' | sed -e :a -e '$q;N;5,$D;ba' | tr -d '\n' | sed -e 's/\(.*\),\(.\)\{1,3\}/\1/') -vn -ab 128k "$(youtube-dl -e http://youtube.com/"$i").mp3"; done; done; unset count i; }

create the function and run with

yt-mp3chanrip YoutubeUsername

Great for channels like ukfDrumAndBass that only post music. No more need for third party browser plugins or websites that only convert one vid one at a time. It'll convert and save to CWD up to 300 of a user's videos to mp3s, one at a time. To increase, just increment the $count pattern. This is a concoction from commands #7718 and #7752, so it uses ffmpeg wget, curl, sed, and youtube-dl -- youtube-dl is only used to get the title of the video which it uses to name the mp3 file. You can use a different naming method if you want and the function should still work.

In MySQL client, \P less -S
2011-01-19 09:44:43
User: maxmanders
Functions: less

Instead of dumping the entire query to the screen, it will use 'less -S' to handle pagination. This means you can move back and forward through the result set, and instead of wrapping rows at screen boundaries, the table will extend off the screen, and can be scrolled left and right with arrow keys.

zcat file.gz | less +/search_pattern
2011-01-14 21:29:40
User: gwchamb
Functions: less zcat

This command enables the user to append a search pattern on the command line when using less as the PAGER. This is especially convenient (as the example shows) in compressed files and when searching man pages (substituting the zcat command with man, however).

hexdump -e '8/1 "%02X ""\t"" "' -e '8/1 "%c""\n"' /dev/sda1 | less /mystring
LESSOPEN="| /usr/bin/lesspipe %s" less file.jar
2010-10-13 12:57:08
User: stubby
Functions: less

This of course assumes that lesspipe is installed. You can view the contents of many, many types of files in this way. Once lesspipe is installed, add to your .bashrc

export LESSOPEN="| /usr/bin/lesspipe %s" less file.jar

export LESSCLOSE="/usr/bin/lesspipe %s %s"


eval "$(lesspipe)"

tt(){tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> "}
2010-10-12 10:53:33
User: strzel_a
Functions: grep less

Usage : tt [OCCURRENCE]

tt will display a tree from your actual path

tt .svn will display only line containing .svn

read -p "enter url:" a ; w3m -dump $a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ $b = "y" ] ; then read -p "enter path with filename:" c && touch $(eval echo "$c") ; mv /dev/shm/e1q $(eval echo "$c") ; fi ; echo DONE
2010-07-13 22:36:38
User: LinuxMan
Functions: c++ echo eval less mv read touch

Thanks th John_W for suggesting the fix allowing ~/ to be used when saving a directory.


Type in a url, it will show a preview of what the file will look like when saved, then asks if you want to save the preview and where you want to save it. Great for grabbing the latest commandlinefu commands without a full web browser or even a GUI. Requires: w3m

tree -C | less -R
curl -s "http://feeds.delicious.com/v2/json?count=5" | python -m json.tool | less -R
2010-03-24 09:15:12
User: keimlink
Functions: less python

Validates and pretty-prints the content fetched from the URL.

man <COMMAND> | less +'/pattern'
argv=("$@"); rest=${argv[@]:1}; less -JMN +"/$1" `grep -l $1 $rest`
2009-10-16 17:36:16
User: lassel
Functions: less
Tags: bash less log grep

Really useful way to combine less and grep while browsing log files.

I can't figure out how to make it into a true oneliner so paste it into a script file called lgrep:


lgrep searchfor file1 [file2 file3]

Advanced example (grep for an Exception in logfiles that starts with qc):

lgrep Exception $(find . -name "qc*.log")

id=<XXXX>; find /var/spool/postfix/ -name $id -exec less {} \;
< /var/log/syslog ccze -A | less -R
ps awwfux | less -S
2009-07-04 09:39:28
User: ToyKeeper
Functions: less ps

If you want a visual representation of the parent/child relationships between processes, this is one easy way to do it. It's useful in debugging collections of shell scripts, because it provides something like a call traceback.

When a shell script breaks, just remember "awwfux".

less -Rf <( cat <(ls -l --color=always) <(ls -ld --color=always .*) )
2009-05-30 23:51:16
User: asmoore82
Functions: cat less ls

To sort hidden files first, simply switch the two inner `ls` commands.

I have this aliased to `dira`

`dir` is aliased to the simpler version with no hidden files:

ls -l --color=always | less -R
pstree -Gap | less -r
2009-05-21 05:15:16
User: mbirk
Functions: less
Tags: less pstree

The "pstree" command uses special line-drawing characters. However, when piped into the "less" pager, these are normally disabled.

grep --color=always | less -R
2009-05-20 20:30:19
User: dinomite
Functions: grep less

Get your colorized grep output in less(1). This involves two things: forcing grep to output colors even though it's not going to a terminal and telling less to handle those properly.

less textfile.gz
2009-03-15 23:51:17
User: allbad
Functions: less

There is no need to 'zcat textfile.gz | less' with newer distros. This is useful for reading archived log files without having to extract, read, and zip when done.

less file.tar.gz
2009-03-15 23:00:05
User: allbad
Functions: less

This will print out the files and directories in a gzipped tarball.

less +G <filename>
2009-03-02 23:34:21
User: leper421
Functions: less

The same as typing 'less filename' then 'G' or '>' or the END key. Comes in handy with shell scripts or aliases:

alias weblog='less +G /var/log/httpd/access_log'

alias errlog='less +G /var/log/httpd/error_log'

less -r <some file>
2009-03-01 21:19:53
User: prayer
Functions: less
Tags: less

It allows customizing by means of lesspipe. You need to write a ~/.lessfilter script and put this into your ~/.bashrc:

eval $(lesspipe)

export LESS=-r

less =rcsyslog
less +F somelogfile
2009-02-19 14:33:46
User: adamm9
Functions: less

Using +F will put less in follow mode. This works similar to 'tail -f'. To stop scrolling, use the interrupt. Then you'll get the normal benefits of less (scroll, etc.).

Pressing SHIFT-F will resume the 'tailling'.

svn diff $* | colordiff | less -r
2009-02-18 16:19:08
User: introp
Functions: diff less

I put this in a shell script called "svndiff", as it provides a handy decorated "svn diff" output that is colored (which you can't see here) and paged. The -r is required so less doesn't mangle the color codes.