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 tagged less from sorted by
Terminal - Commands tagged less - 27 results
pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R
2016-01-25 14:29:31
User: hute37
Functions: grep less paste python
Tags: less paste pacman

Alternative1 (grep support):

pacman -Ss python | paste - - | grep --color=always -e '/python' | less -R

Alternative2 (eye-candy, no grep):

pacman --color=always -Ss "python" | paste - - | less -R

in ~/.bashrc:

pkg-grep() { pacman -Ss "$1" | paste - - | grep --color=always -e "${2:-$1}" | less -R ; }

pkg-search() { pacman --color=always -Ss "python" | paste - - | less -R; }

xmlpager() { xmlindent "$@" | awk '{gsub(">",">'`tput setf 4`'"); gsub("<","'`tput sgr0`'<"); print;} END {print "'`tput sgr0`'"}' | less -r; }
2015-07-12 09:22:10
User: hackerb9
Functions: awk less

Don't want to open up an editor just to view a bunch of XML files in an easy to read format? Now you can do it from the comfort of your own command line! :-) This creates a new function, xmlpager, which shows an XML file in its entirety, but with the actual content (non-tag text) highlighted. It does this by setting the foreground to color #4 (red) after every tag and resets it before the next tag. (Hint: try `tput bold` as an alternative). I use 'xmlindent' to neatly reflow and indent the text, but, of course, that's optional. If you don't have xmlindent, just replace it with 'cat'. Additionally, this example shows piping into the optional 'less' pager; note the -r option which allows raw escape codes to be passed to the terminal.

curl 'LINK' | pdftotext - - | less
2014-06-21 00:47:02
User: snipertyler
Tags: less pdf convert

Probably will not work very well with scanned documents.

info foo |less
2013-09-12 16:49:08
Functions: info
Tags: less info

This command is similar to the above, but is much simpler to remember. Sure, it's isn't as precise as the parent command, but most people aren't going to remember those --flags anyways unless you stick it into your .bashrc on every single system that you manage.

info --subnodes -o - <item> | less
2013-06-11 01:23:23
Functions: info
Tags: less info

This makes GNU info output menu items recursively and pipe its contents to less, allowing one to use GNU info in a manner similar to 'man'.

less -XF
pygmentize -l pytb myapp.log | less -SR
grep --color=always -nr 'setLevel' --include=*py | less -SRqg
export LESS='-x4FRSXs'
2012-05-25 16:46:15
User: SEJeff
Functions: export

# s = combine multiple lines of whitespace into 1

# x4 = set the tabstop to 4 instead of 8

# F = Exit if the output fits on 1 screen. This is similar to git diff

# R = Raw control chars. This allows you to pipe colordiff straight to less. ie: alias sdi="svn diff | colordiff | less"

# S = Chop off long lines

# X = Dont send termcap init and deinit scrings to the terminal

echo "export LESS_TERMCAP_mb=$'\E[01;31m'" >> ~/.bashrc
2011-10-20 17:34:14
User: totti
Functions: echo
Tags: man less color

Add the followin to ~/.bashrc


export LESS_TERMCAP_mb=$'\E[01;31m'

export LESS_TERMCAP_md=$'\E[01;37m'

export LESS_TERMCAP_me=$'\E[0m'

export LESS_TERMCAP_se=$'\E[0m'

export LESS_TERMCAP_so=$'\E[01;44;33m'

export LESS_TERMCAP_ue=$'\E[0m'

export LESS_TERMCAP_us=$'\E[01;32m'

less file.ext
2011-09-13 10:29:27
User: totti
Functions: less
Tags: less text search

Use the following key binding to search



: Jump to line number n. Default is the start of the file.


: Jump to line number n. Default is the end of the file.


: Search for pattern. Regular expressions can be used. [/ = slash] Press / and then Enter to repeat the previous search pattern. Press ESC and then u to undo search highlighting.


: Go to next match (after a successful search).


: Go to previous match.


: Mark the current position with letter.


: Return to position letter. [' = single quote]

'^ or g

: Go to start of file.

'$ or G

: Go to end of file.


: Save current content (got from another program like grep) in a file.

= or Ctrl+g

: File information.


: continually read information from file and follow its end. Useful for logs watching. Use Ctrl+c to exit this mode.


: Toggle command-line option -option.


: Help.

zcat /usr/share/man/man1/man.1.gz | nroff -man | less
2011-09-07 01:13:57
User: atoponce
Functions: zcat
Tags: man less zcat nroff

As odd as this may be, I know of servers where the man(1) command is not installed, and there is not enough room on / to install it. However, zcat(1), nroff(1) and less(1) are. This is a way to read those documents without the proper tool to do so, as sad as this may seem. :)

less file.lst | head -n 50000 > output.txt
2011-09-05 05:26:04
User: Richie086
Functions: head less

Useful for situations where you have word lists or dictionaries that range from hundreds of megabytes to several gigabytes in size. Replace file.lst with your wordlist, replace 50000 with however many lines you want the resulting list to be in total. The result will be redirected to output.txt in the current working directory. It may be helpful to run wc -l file.lst to find out how many lines the word list is first, then divide that in half to figure out what value to put for the head -n part of the command.

apropos <part_rember> | less
2011-08-19 19:34:57
User: totti
Functions: apropos
Tags: less apropos

Show all commands having the part known by you.


apropos pdf | less
function ds { echo -n "search : "; read ST; EST=`php -r "echo rawurlencode('$ST');"`; B64=`echo -n $ST| openssl enc -base64`; curl -s "http://www.commandlinefu.com/commands/matching/$EST/$B64/plaintext" | less -p "$ST"; } ; bind '"\C-k"':"\"ds\C-m\""
2011-02-20 23:46:16
User: cparker
Functions: echo less read
Tags: bash less curl PHP

This is a simple bash function and a key binding that uses commandlinefu's simple and easy search API. It prompts for a search term, then it uses curl to search commandline fu, and highlights the search results with less.

info gpg |less
2010-07-01 23:44:15
Functions: gpg info
Tags: less info

I like man pages, and I like using `less(1)` as my pager. However, most GNU software keeps the manual in the 'GNU Texinfo' format, and I'm not a fan of the info(1) interface. Just give me less.

This command will print out the info(1) pages, using the familiar interface of less!

shmore(){ local l L M="`echo;tput setab 4&&tput setaf 7` --- SHMore --- `tput sgr0`";L=2;while read l;do echo "${l}";((L++));[[ "$L" == "${LINES:-80}" ]]&&{ L=2;read -p"$M" -u1;echo;};done;}
2010-04-21 00:40:37
User: AskApache
Functions: echo read
cat mod_log_config.c | shmore


shmore < mod_log_config.c

Most pagers like less, more, most, and others require additional processes to be loaded, additional cpu time used, and if that wasn't bad enough, most of them modify the output in ways that can be undesirable.

What I wanted was a "more" pager that was basically the same as running:

cat file

Without modifying the output and without additional processes being created, cpu used, etc. Normally if you want to scroll the output of cat file without modifying the output I would have to scroll back my terminal or screen buffer because less modifies the output.

After looking over many examples ranging from builtin cat functions created for csh, zsh, ksh, sh, and bash from the 80's, 90s, and more recent examples shipped with bash 4, and after much trial and error, I finally came up with something that satisifed my objective. It automatically adjusts to the size of your terminal window by using the LINES variable (or 80 lines if that is empty) so

This is a great function that will work as long as your shell works, so it will work just find if you are booted in single user mode and your /usr/bin directory is missing (where less and other pagers can be). Using builtins like this is fantastic and is comparable to how busybox works, as long as your shell works this will work.

One caveat/note: I always have access to a color terminal, and I always setup both the termcap and the terminfo packages for color terminals (and/or ncurses and slang), so for that reason I stuck the

tput setab 4; tput setaf 7

command at the beginning of the function, so it only runs 1 time, and that causes the -- SHMore -- prompt to have a blue background and bright white text.

This is one of hundreds of functions I have in my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html">.bash_profile at http://www.askapache.com/">AskApache.com, but actually won't be included till the next update.

If you can improve this in any way at all please let me know, I would be very grateful! ( Like one thing I want is to be able to continue to the next screen by pressing any key instead of now having to press enter to continue)

tree -C | less -R
man <COMMAND> | less +'/pattern'
function lsless() { ls "$@" | less; }
2009-11-13 17:28:06
User: argherna
Functions: ls
Tags: less ls function

This is useful for paging through long directories, mulitple directories, etc. I put this in my ~/.bash_aliases file and alias 'lsl' to it.

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")

du -ms * | sort -nk1
du -ms * .[^.]*| sort -nk1
2009-07-01 13:38:13
User: ioggstream
Functions: du sort

using mb it's still readable;) a symbol variation

$ du -ms {,.[^.]}* | sort -nk1

function duf { du -k $@ | sort -rn | perl -ne '($s,$f)=split(/\t/,$_,2);for(qw(K M G T)){if($s<1024){$x=($s<10?"%.1f":"%3d");printf("$x$_\t%s",$s,$f);last};$s/=1024}' }
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.