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 grep from sorted by
Terminal - Commands using grep - 1,531 results
ps aux | grep $(echo $1 | sed "s/^\(.\)/[\1]/g")
2013-07-16 10:10:51
User: opexxx
Functions: echo grep ps sed
Tags: sed grep ps
1

grep по ps aux

grep enabled /sys/firmware/acpi/interrupts/*
2013-07-16 03:46:23
User: m33600
Functions: grep
0

Goto phase 2 to clobber the interrupt that is problematic.

curl --silent http://www.census.gov/population/international/ | grep wclocknum | sed -r 's@^.*>([0-9,]+)<.*$@\1@'
2013-07-15 22:35:05
User: malathion
Functions: grep sed
Tags: curl
0

Deprecated due to a change in the site design: see alternatives.

qdbus | grep kscreenlocker_greet | xargs -I {} qdbus {} /MainApplication quit
2013-07-11 10:50:03
User: Murz
Functions: grep xargs
1

Do the unlock KDE screen saver locked session with lightdm display manager used in Kubuntu 12.10 +

while curl -dsL example.com 2>&1 | grep 503;do sleep 8;done;echo server up
while true; do curl -vsL -o /dev/null example.com 2>&1 | grep 503 > /dev/null || echo "OK: server is up."; sleep 8; done
sudo dumpe2fs /dev/sda1 | grep superblock
leo() { lang=en; IFS=+; Q="${*// /%20}"; curl -s "https://dict.leo.org/${lang}de/?search=${Q//+/%20}" | html2text | grep -EA 900 '^\*{5} ' | grep -B 900 '^Weitere Aktionen$';}
2013-06-24 22:35:46
User: michelsberg
Functions: grep
4

Translate strings from non-german to german (and vice versa) using LEO. Put it in your ~/.bashrc.

Usage:

leo words

To support languages other than english, change the lang variable:

lang=ch # chinese

lang=en # english

lang=es # spanish

lang=fr # french

lang=it # italian

lang=pl # polish

lang=pt # portuguese

lang=ru # russian

The other language will always be german!

grep -aEio '([[:alnum:]_.-\+\-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'
2013-06-23 21:52:14
User: binarynomad
Functions: grep
Tags: grep email
1

This will catch most separators in the section of the email:

dot .

dash -

underscore _

plus + (added for gmail)

... and the basic dash '-' of host names.

salt -G 'os_family:Debian' cmd.run 'apt-get dist-upgrade --dry-run | grep ^Inst | cut -d" " -f2'
wget -qO - whatismyipaddress.com/ip/<type ip address> | grep -E "City:|Country:" | sed 's:<tr><th>::'| sed 's</th>::' | sed 's:</td>::' | sed 's:</tr>::' | sed 's:<img*::'
2013-06-21 03:27:09
User: pentester
Functions: grep sed wget
0

This command will help you to get Ip address origin of city and country.

I will be happy if someone can shrink the sed command

fb.me/josenirmal

watch -t -c -n30 'wget -q -O- "http://wwwapps.ups.com/WebTracking/processInputRequest?TypeOfInquiryNumber=T&InquiryNumber1=1Z4WYXXXXXXXXXX" | html2text | sed -n "/Shipment Progress/,/Shipping Information/p" | grep -v "*" | ccze -A'
while true; do netstat -a|grep WAIT|wc -l; sleep 5; done
2013-06-19 09:19:41
User: adimania
Functions: grep netstat sleep wc
Tags: netstat tcp
0

This has saved me many times while debugging timeout issues to "too many open files" issues. A high number of the order of thousand, indicates that somewhere connection is not being closed properly.

mysql -uuser -ppass -e 'use information_schema; SELECT table_name FROM tables where table_schema="DB-NAME" and table_name NOT LIKE "PREFIX";' | grep -v table_name | xargs mysqldump DB-NAME -uuser -ppass > dump.sql
2013-06-17 13:44:15
User: moosak
Functions: grep xargs
0

Required : information_schema

** Only replace the "DB-NAME" and "PREFIX" with your DB-name and wildcard prefix match.

** Also replace with your own username and password for mysql server.

This command uses the information_schema to wildcard match tables that we donot need from a database and than pipes the remaining tables out through "xargs" command to the mysqldump utility which than dumps those remaining tables into a sql dump file.

find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -print0 | xargs -0 cat | grep -v "^ *$" | grep -v "^ *//" | grep -v "^ */\*.*\*/" | wc -l
2013-06-17 08:37:37
Functions: cat find grep wc xargs
1

Count your source and header file's line numbers. This ignores blank lines, C++ style comments, single line C style comments.

This will not ignore blank lines with tabs or multiline C style comments.

svn st | grep ! | cut -c 9- | while read line;do svn resolved $line;done
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
cvs -q status | grep ^[?F] | grep -v 'to-date'
sudo /usr/sbin/exim -bp | sed -n '/\*\*\* frozen \*\*\*/,+1!p' | awk '{print $1}' | tr -d [:blank:] | grep @ | sort | uniq -c | sort -n
sudo lsof -p `sudo ps aux | grep -i neo4j | grep -v grep | awk '{ print $2 }'`
2013-06-02 10:15:30
User: andycunn
Functions: awk grep ps sudo
0

Inner "ps...grep..." command searches for a process matching the specified .

"lsof -p lists all file descriptors owned by . Includes open files, sockets, devices, etc...

grep -aEio '([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'
2013-05-30 07:17:32
User: nabil_kadimi
Functions: grep
0

The -a option in -aEio tells grep to treat binary files as text files.

du -mx [directory] | grep -P '^\d{4}' | sort -rn
2013-05-24 09:52:41
User: mc0e
Functions: du grep sort
Tags: bash Linux du
0

I don't like doing a massive sort on all the directory names just to get a small set of them. the above shows a sorted list of all directories over 1GB. use head as well if you want.

du's "-x" flag limits this to one file system. That's mostly useful when you run it on "/" but don't want "/proc" and "/dev" and so forth. Remember though that it will also exclude "/home" or "/var" if those are separate partitions.

the "-a" option is often useful too, for listing large files as well as large directories. Might be slower.

for i in *.pdf; do echo --------$i-------; echo; pdftotext $i - | grep -i Yourpattern; done
2013-05-22 05:36:06
User: fangfufu
Functions: echo grep
Tags: grep pdf
0

This command is useful for searching through a whole folder worth of pdf files.

grep '.tag =' <file> | awk '{print $3}' | awk 'sub(/[;]/, x)' | sort -n
2013-05-21 15:58:16
User: pbriggeman
Functions: awk grep sort
0

I use this one-liner to search my sourcecode to find out where tags are named and since there's no easy way in XCode to see what values have already been used.

url=http://mirrors.mageia.org/api/mageia.4.i586.list; wget -q ${url} -O - | grep rsync:
2013-05-20 16:19:05
User: mpb
Functions: grep wget
1

Need to find a Mageia Linux mirror server providing Mageia 4 via rsync?

Modify the "url=" string for the version you want. This shows i586 which is the 32bit version.

If you want the 64bit version it is:

url=http://mirrors.mageia.org/api/mageia.4.x86_64.list; wget -q ${url} -O - | grep rsync: