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 egrep from sorted by
Terminal - Commands using egrep - 196 results
egrep '(expr1|expr2)' file
2011-07-14 14:22:11
User: evandrix
Functions: egrep

to find occurances of expr1 OR expr2

egrep -in "this|that" *.dat
2011-07-06 09:42:26
User: evandrix
Functions: egrep

grep - Search file for character string

Search for one or more strings in one or more files. Examples:-

grep that myfile.txt

Look for the string ``that'' in the file called ``myfile.txt'' and print out each line that matches.

egrep -in "this|that" *.dat

Extended grep search *.dat files for ``this'' or ``that'' case insensitive (-i) and where found print line number (-n) along with the line contents.

function summpkg { dpkg -s $(dpkg -S $1 | egrep -w $(which $1)$ | awk -F: '{print $1}') ; }
2011-07-05 23:06:37
User: b_t
Functions: awk egrep which
Tags: which dpkg

This version builds on my command 8776 (Find the package a command belongs to on debian-based distros). So if you use that command to find package name then you could alternatively use following for

package summary:

function summpkg { dpkg -s $(whichpkg $1 | awk -F: '{print $1}'); }
function whichpkg { dpkg -S $1 | egrep -w $(which $1)$; }
make -d | egrep --color -i '(considering|older|newer|remake)'
2011-06-03 01:55:08
User: b_t
Functions: egrep make
Tags: make

Say your dependencies specified in your Makefile (or dates on your source files) is causing 'make' to

skip some source-files (that it should not) or on the other other end, if it is causing make to always build some source-files regardless of dates of target, then above command is handy to find out what 'make' thinks of your date v/s target date-wise or what dependencies are in make's view-point.

The egrep part removes the extra noise, that you might want to avoid.

egrep -v "^$|^#" file
watch 'netstat -anptu |egrep "^Proto|:80 "'
2011-05-18 15:05:52
User: Mozai
Functions: egrep watch

Shows updated status in a terminal window for connections to port '80' in a human-friendly form. Use 'watch -n1' to update every second, and 'watch -d' to highlight changes between updates.

If you wish for status updates on a port other than '80', always remember to put a space afterwards so that ":80" will not match ":8080".

alias screenr='screen -r $(screen -ls | egrep -o -e '[0-9]+' | head -n 1)'
egrep -ie "<*HREF=(.*?)>" index.html | cut -d "\"" -f 2 | grep ://
2011-03-29 18:20:50
User: fanfani
Functions: cut egrep grep

you can also use cut instead of awk. less powerful but probably faster. ;)

svn st | grep -e [MA] | egrep -ve '.project|.classpath|.properties|.sh|.number' | awk -F' ' '{ print $2}' | xargs svn ci -m "message"
egrep '__NR_' /usr/include/asm/unistd_`getconf -a | awk '$1~/^WORD/{print $2}'`.h | sed -e 's/^#define __NR_//' | column -t
ps ax | egrep "*.exe|*exe]" | awk '{ print $1 }' | xargs kill
ps ax > processes && cat processes | egrep "*.exe |*exe]" | awk '{ print $1 }' > pstokill && kill $(cat pstokill) && rm processes && rm pstokill
2011-02-26 16:13:58
User: sxiii
Functions: awk cat egrep kill ps rm
Tags: kill wine exe

This command kills all wine instances and each EXE application working on a PC.

Here is command info:

1) ps ax > processes = save process list to file named "processes" (we save it because we don't wont egrep to be found in the future)

2) cat processes | egrep "*.exe |*exe]" = shows the file "processes" and after greps for each *.exe and *exe] in it

3) | awk '{ print $1 }' > pstokill = saves processes PID's to file "pstokill" using awk filter

4) kill $(cat pstokill) = kills each PID in file pstokill, which is shown by cat program

5) rm processes && rm pstokill = removes temporary files

egrep -i " connected|card detect|primary dev" /var/log/Xorg.0.log
2011-02-24 18:04:04
User: axelabs
Functions: egrep
Tags: video egrep xorg

The above one liner can be used to determine what card/driver is Xorg currently using. For additional information, see http://goo.gl/mDnWu

curl -Ls "http://support.dell.com/support/DPP/Index.aspx?c=us&cs=08W&l=en&s=biz&ServiceTag=$(dmidecode -s system-serial-number)"|egrep -i '>Your Warranty<|>Product Support for'|html2text -style pretty|egrep -v 'Request|View'|perl -pane 's/^(\s+|\})//g;'
2011-02-18 22:29:05
User: din7
Functions: egrep perl

The dates in the output are Start Date, End Date, Days Remaining in warranty, respectively. This will only work if you are running it on a dell machine. You can substitute the dmidecode command with a service tag if you are not using a dell. Also, you have to either allow your user to run sudo dmidecode with no password or run this command as root.

dd if=FILE | pv -s $(stat FILE | egrep -o "Size: [[:digit:]]*" | egrep -o "[[:digit:]]*") | dd of=OUTPUT
2011-02-09 22:21:06
User: andrepuel
Functions: dd egrep stat

Will automatically take the size of the file but longer, usefull only if in an function.

lsof -nP -c COMMAND | egrep -o '(TCP|UDP).*$' | sort -u
2011-01-25 12:04:13
User: forcefsck
Functions: egrep sort
Tags: egrep lsof udp tcp

Where COMMAND is the process(es) name. I prefer to get all states but you may add ESTABLISHED in the grep regex.

lsof -c apache2 | egrep -o 'TCP.*ESTABLISHED.*$'

-nP flags are optional and UDP is irrelevant for established connections

Similar but using the process id:

lsof -nP -p PID | egrep -o '(TCP|UDP).*$'
df /media/mountpoint |egrep -o '^[/a-z0-9]*'
2011-01-24 21:14:55
User: DaveQB
Functions: df egrep
Tags: grep,df

Shorter way to find the device for a given mountpoint

scrot $1 /tmp/screenshot.png && curl -s -F file1=@/tmp/screenshot.png -F submit="OMPLOAD\!" http://ompldr.org/upload | egrep '(View file: <a href="v([A-Za-z0-9+\/]+)">)' | sed 's/^.*\(http:\/\/.*\)<.*$/\1/' | xsel -b -i ? (full in a sample output)
egrep -i "^[0-9a-f]{4,} .*$*" $(locate CharName.pm) | while read h d; do /usr/bin/printf "\U$(printf "%08x" 0x$h)\tU+%s\t%s\n" $h "$d"; done
2010-12-31 16:47:59
User: hackerb9
Functions: egrep locate read

[Update! Thanks to a tip from ioggstream, I've fixed both of the bugs mentioned below.]

You, yes, 𝙔𝙊𝙐, can be the terror of the Internet! Why use normal, boring bullet points in your text, when you could use a ROTATED HEAVY BLACK HEART BULLET (❥)!? (Which would also be an awesome band name, by the way).

This script makes it easy to find unusual characters from the command line. You can then cut and paste them or, if you're using a GTK application, type Control+Shift+U followed by the code point number (e.g., 2765) and then a SPACE.

USAGE: Put this script in a file (I called mine "ugrep") and make it executable. Run it from the command line like so,

ugrep heart

The output will look like this,












You can, of course, use regular expressions. For example, if you are looking for the "pi" symbol, you could do this:

ugrep '\bpi\b'

REQUIREMENTS: Although this is written in Bash, it assumes you have Perl installed because it greps through the Perl Unicode character name module (/usr/lib/perl5/Unicode/CharName.pm). Note that it would not have made more sense to write this in Perl, since the CharName.pm module doesn't actually include a subroutine for looking up a character based on the description. (Weird.)

BUGS: In order to fit this script in the commandlinefu limits, a couple bugs were added. ① Astral characters beyond the BMP (basic multilingual plane) are not displayed correctly, but see below. ② Perl code from the perl module being grepped is sometimes extraneously matched.

MISFEATURES: Bash's printf cannot, given a Unicode codepoint, print the resulting character to the terminal. GNU's coreutils printf (usually "/usr/bin/printf") can do so, but it is brokenly pedantic about how many hexadecimal digits follow the escape sequence and will actually die with an error if you give the wrong number. This is especially annoying since Unicode code points are usually variable length with implied leading zeros. The CharNames.pm file represents BMP characters as 4 hexits, but astral characters as 5. In the actual version of this script that I use, I've kludged around this misfeature by zero-padding to 8 hexits like so,

/usr/bin/printf "\U$(printf "%08x" 0x$hex)"

TIP 1: The author recommends "xsel" for command line cut-and-paste. For example,

ugrep biohazard | xsel

TIP 2: In Emacs, instead of running this command in a subshell, you can type Unicode code points directly by pressing Control-Q first, but you'll likely want to change the default input from octal to hexadecimal. (setq read-quoted-char-radix 16).

TIP 3: Of course, if you're using X, and you want to type one of the more common unusual characters, it's easiest of all to do it with your Compose (aka Multi) key. For example, hitting [Compose] <3 types ♥.

alias duh='dulist=$(du -sh */); for i in T G M K; do printf "$dulist"|egrep "^[0-9\.]+$i" | sort -rn; done'
2010-12-07 11:11:26
User: forcefsck
Functions: alias du egrep printf sort
Tags: disk usage

Alias to produce a list of all subdir sizes in current dir, in reverse order and human readable units. du is executed only once. Remove the slash after the asterisk to include files.

cat /etc/services | egrep [[:blank:]]<port_number>/
find | egrep "\.(ade|adp|bat|chm|cmd|com|cpl|dll|exe|hta|ins|isp|jse|lib|mde|msc|msp|mst|pif|scr|sct|shb|sys|vb|vbe|vbs|vxd|wsc|wsf|wsh)$"
2010-11-23 16:53:55
User: poulter7
Functions: egrep find

Returns any file in the folder which would be rejected by Gmail, if you were to send zipped version.

(Yes, you could just zip it and knock the extension off and put it back on the other side, but for some people this just isn't a solution)

lynx -dump http://www.domain.com | awk '/http/{print $2}' | egrep "^https{0,1}"
ping -c 1 google.com | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'