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 using less from sorted by
Terminal - Commands using less - 53 results
less -X /var/log/insecure
2016-06-24 13:53:49
User: sonic
Functions: less

From the manpage:

man less

-X or --no-init

Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.


If you want to clear the screen after viewing a file this way that had sensitive information, hit or just type clear. Since is readily available, I don't know why less bothers to automatically clear. If you're viewing the file at all, chances are you want to see the output from it after you quit.

exa -glhrSuU -s size --group-directories-first -@ | less -R
2016-02-27 17:19:43
User: wires
Functions: less size
Tags: ls color exa

nothing fancy

`ls` alternative `exa`, with most info printed and passed through less with the `-R` (raw) option, to preserve colour output https://github.com/ogham/exa

You can add or remove `-@` to print extended attributes for files that have them.

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.

less +F <file>
col_look(){ column -nts$'\t' "$1" | less -SN#2 }
2015-05-11 18:17:29
User: razerwolf
Functions: column less

Opens up a tab separated file in less with columns printed prettily

less -S somefile
grep -E -rn --color=always --exclude-dir=".svn" --exclude-dir="packages" --exclude="*.swp" "(emit|on)\([\'\"]leader" ~/project/ | less -R
2014-12-23 20:08:25
User: hochmeister
Functions: grep less

grep for specific function invocations in this case, wither "emit" or "on" with "leader".

man foobar | less +/searched_string
2013-11-06 18:50:11
User: mcescalante
Functions: less man

This will open the manpage for "foobar", and display all instances of "searched_string". You can traverse through them by pressing "n"

less -XF
less -p pattern file.txt
pygmentize -l pytb myapp.log | less -SR
grep --color=always -nr 'setLevel' --include=*py | less -SRqg
git diff -U10|dwdiff --diff-input -c|less -R
git diff -U10 |wdiff --diff-input -a -n -w $'\e[1;91m' -x $'\e[0m' -y $'\e[1;94m' -z $'\e[0m' |less -R
2012-08-15 01:42:16
Functions: diff less

I've been using colordiff for years. wdiff is the new fav, except its colors. Word delimited diffs are more interleaved, easing the chore of associating big blocks of changes.

show_code() { pygmentize $1 | less -N }
2012-05-12 09:18:33
User: Flow
Functions: less

Uses pygments ( http://pygments.org/ ) to highlight the source code and a less pipe to scroll and show line numbers of the code.

compgen -c | sort -u > commands && less commands
less `kpsewhich scrartcl.cls`
2012-04-15 11:10:41
User: Stefan
Functions: less
Tags: latex tex

kpsewhich is a tool for path and file lookup. It is a front-end of the kpathsea library. For one or more given package or file names it returns the complete path from within the TeX installation, that one which the compiler would actually use. Via backticks we can use it as argument to less, more, or any editor. For example:

gedit `kpsewhich hyperref.sty`
dng(){ local a;a=$(sed '/'"$1"'/!d' /etc/hosts |sed '=;'"${2-1,$}"'!d'|sed '/ /!d');echo $a|tr '\040' '\n'|nl -bp'[0-9]$'|less -E;export dn=$(echo $a|sed 's,.* ,,');export ip=$(echo $a|sed 's, .*,,');echo \$dn=$dn;echo \$ip=$ip;}
2012-04-01 23:57:09
User: argv
Functions: echo export less nl sed tr

usage: dng BRE [selection]

default selection is the last match

DNS is ok, but although domainnames may be easier to remember than IP numbers, it still requires typing them out. This can be error-prone. Even more so than typing IPv4 numbers, depending on the domainname, its length and complexity.

pygmentize -l sh ~/.bashrc | less -R
2012-01-27 03:27:37
User: captaincomic
Functions: less sh

On Debian/Ubuntu the pygments script is called pygmentize and can be found in the python-pygments package.

For an overview of all available lexers, formatters, styles and filters use

pygmentize -L

Here is an example using more options

pygmentize -f 256 -l sh -F whitespace:spaces=True,tabs=True -O style=borland ~/.bashrc | less -R
cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext" --silent | sed "s/\(^#.*\)/\x1b[32m\1\x1b[0m/g" | less -R }
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.

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.

cat file.csv | perl -pe 'if($. == 1) [email protected] = split(/;/); $i = 1 ; map { $_ = $i; $i++ } @h; print join(" ;", @h) , "\n"} ; s/(^|;);/$1 ;/g' | column -ts\; | less -S
mount |tail -1 | less -p "/dev/[^ ]*"