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 tagged less from sorted by
Terminal - Commands tagged less - 24 results
info foo |less
2013-09-12 16:49:08
Functions: info
Tags: less info
0

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
3

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
0

# 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
15

Add the followin to ~/.bashrc

#colour

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

Use the following key binding to search

----------------------------------------------------------------

ng

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

nG

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

/pattern

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

n

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

N

: Go to previous match.

mletter

: Mark the current position with letter.

'letter

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

'^ or g

: Go to start of file.

'$ or G

: Go to end of file.

s

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

= or Ctrl+g

: File information.

F

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

-option

: Toggle command-line option -option.

h

: 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
0

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

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
1

Show all commands having the part known by you.

Eg:

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
0

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
1

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
6
SH
cat mod_log_config.c | shmore

or

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

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

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

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
7

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

\bTERM\b
2009-04-11 22:05:12
User: kFiddle
Tags: less regex
5

Although less behaves more or less like vim in certain aspects, the vim regex for word boundaries (\< and \>) do not work in less. Instead, use \b to denote a word boundary. Therefore, if you want to search for, say, the word "exit", but do not want to search for exiting, exits, etc., then surround "exit" with \b. This is useful if you need to search for specific occurrences of a keyword or command. \b can also be used at just the beginning and end, if needed.

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