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 less from sorted by
Terminal - Commands using less - 45 results
LESSOPEN="| /usr/bin/lesspipe %s" less file.jar
2010-10-13 12:57:08
User: stubby
Functions: less
0

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"

or

eval "$(lesspipe)"

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

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
0

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

directions:

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
11

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
1

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:

Usage:

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
37

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
2

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
7

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
30

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

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

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
2

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
2

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
110

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
2

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.