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,519 results
lsmod | grep -io MODULENAME| xargs modinfo | grep -iw version
2013-03-18 07:52:14
User: adriano
Functions: grep lsmod modinfo xargs
Tags: kernel modules
1

Returns the version of the kernel module specified as "MODULENAME", when available.

wget -O - "[PICASA ALBUM RSS LINK]" |sed 's/</\n</g' | grep media:content |sed 's/.*url='"'"'\([^'"'"']*\)'"'"'.*$/\1/' |awk -F'/' '{gsub($NF,"d/"$NF); print $0}'|wget -i -
dpkg --list | grep '^rc\b' | awk '{ print $2 }' | xargs sudo dpkg -P
grep -hor ofx[a-zA-Z]*.h src/ | grep -o ofx[^\.]* >> addons.make
pwd|grep -o '/'|perl -ne '$x.="./.";print`readlink -f $x`'|xargs -tn1 chmod 755
2013-03-14 12:03:44
Functions: chmod grep perl pwd xargs
0

`pwd` returns the current path

`grep -o` prints each slash on new line

perl generates the paths sequence: './.', './../.', ...

`readlink` canonicalizes paths (it makes the things more transparent)

`xargs -tn1` applies chmod for each of them. Each command applied is getting printed to STDERR.

lynx --dump http://en.trending-topic.com/countries/Mexico/ | grep "62]#" | sed 's/\[62\]//g'
2013-03-12 16:25:14
User: xmuda
Functions: grep sed
0

In these command i use lynx to get the top trend topic of Mexico, if you replace Mexico with other country, you will get the #1 Trending topic

cat /var/lib/dpkg/info/*.md5sums|grep usr/sbin/sshd|sed 's,usr,/usr,'|md5sum -c
2013-03-12 11:20:48
User: Ztyx
Functions: cat grep md5sum sed
0

Replace "user/sbin/sshd" with the file you would like to check. If you are doing this due to intrusion, you obviously would want to check size, last modification date and md5 of the md5sum application itself. Also, note that "/var/lib/dpkg/info/*.md5sums" files might have been tampered with themselves. Neither to say, this is a useful command.

file -i `find . -name '*.jpg' -print` | grep "application/msword"
2013-03-10 16:53:23
User: genghisdani
Functions: file grep
0

Created to deal with an overzealous batch rename on our server that renamed all files to .jpg files.

ls -l | grep ^d
find ./ -type f -name "*.php" | xargs grep -n "name" -r {}
machinfo | grep -i memory
2013-03-07 16:22:49
User: giorger
Functions: grep
0

Get the amount of physical memory in an HP-UX v11 OS when following are NOT available:

- root account

- no privileges in /proc

- no privileges in /dev/mem

grep -Po '^sub (\w+)' file.pm | cut -d' ' -f2
2013-03-07 12:31:34
Functions: cut grep
0

instead of printing the whole line, print just the capture matched, but with the "cut" pipe :( I'm so sad with grep.

curl http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 2>/dev/null | grep '^<h3' | grep -v '^\d' | perl -pe 's/^.*(?<=(\d\d\d)) (.*)<\/h3>$/$1 : $2/' | grep -v h3
2013-03-06 01:49:08
User: klg
Functions: grep perl
0

When you need a quick ref guide while troubleshooting Apache|NGINX error|access logs.

gpg --export 0xDEADBEEF | gpg --list-packets | grep -Pzao ':signature packet:.*\n\t.*sigclass 0x20(\n\t.*)*'
2013-03-05 14:11:11
User: claudius
Functions: gpg grep
Tags: GPG revocation
0

Shows a sigclass 0x20 (Key revocation) signature packet on a key, including all subpackets. Subpacket 2 is the date of revocation, subpacket 26 the relevant policy, subpacket 29 the reason of revocation (cf. http://rfc.askapache.com/rfc4880/rfc4880.html#section-5.2.3.23 ) and subpacket 16 the issuer of the revocation certificate (usually should be the same as the revoked key).

grep . filename >filename1
nmap -sP 192.168.0.* | grep Host | tr "(" ")" | cut -d\) -f2
ps aux | grep <process> | grep -v grep | awk '{print $2}' | xargs -i -t kill -9 {}
ls -lT -rt | grep "^-" | awk 'BEGIN {START=2002} (START <= $9){ print $10 ;START=$9 }' | tail -1
2013-02-24 23:39:22
User: Glamdring
Functions: awk grep ls tail
Tags: ls date osx
0

On the Mac, the 'ls' function can sort based on month/day/time, but seems to lack ability to filter on the Year field (#9 among the long listed fields). The sorted list continuously increases the 'START' year for the most recently accessed set of files. The final month printed will be the highest month that appeared in that START year. The command does its magic on the current directory, and suitably discards all entries that are themselves directories. If you expect files dating prior to 2002, change the START year accordingly.

grep '^[^#]' squid.conf
2013-02-21 18:51:06
User: Flow
Functions: grep
Tags: regex grep,
-5

grep '^[^#]' sample.conf

\__/ |||| \_________/

| |||| |

| |||| \- Filename

| ||||

| |||\- Only character in group is '#'

| |||

| ||\- Negate character group (will match any cahracter *not* in the

| || group)

| ||

| |\- Start new character group (will match any character in the

| | group)

| |

| \- Match beginning of line

|

\- Run grep

Empty lines will also be not matched, because there has to be at least one non-hash-sign character in the line.

grep " lm " /proc/cpuinfo > /dev/null && echo "64-bit" || echo "32-bit"
ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace -f
2013-02-19 19:14:57
User: msealand
Functions: awk grep ps strace xargs
1

This version also attaches to new processes forked by the parent apache process. That way you can trace all current and *future* apache processes.

more blast.out| grep virus | awk '{print $1}' > virus_id.txt
sudo ifconfig wlan0 | grep inet | awk 'NR==1 {print $2}' | cut -c 6-
2013-02-18 14:10:07
User: mouths
Functions: awk cut grep ifconfig sudo
-1

On wired connections set 'eth0' instead of 'wlan0'

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | grep "\-dev" | sort -n | awk '{ sum+=$1} END {print sum/1024 "MB"}'
dpkg -l | grep ^rc | awk '{ print $2}' | xargs apt-get -y remove --purge
2013-02-15 01:34:37
User: Richzendy
Functions: awk grep xargs
0

completely remove those packages that leave files in debian / ubuntu marked with rc and not removed completely with traditional tools