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

Commands using grep from sorted by
Terminal - Commands using grep - 1,375 results
find . -name "*.pdf" -exec pdftk {} dump_data output \; | grep NumberOfPages | awk '{s+=$2} END {print s}'
aptitude purge $(dpkg -l|grep ^rc|awk '{ print $2 }')
ps -xaw -o state,ppid | grep Z | grep -v PID | awk '{ print $2 }' | xargs kill -9
2013-01-09 04:21:54
User: terrywang
Functions: awk grep kill ps xargs
-4

Did some research and found the previous command wrong, we don't kill a zombie but its parent. Just made some modifcation to khashmeshab's command.

curl -s -L http://nytm.org/made-in-nyc | grep "(hiring)" | sed -re 's/<([^>]+)>//g;s/^([ \t]*)//g'
apt-get --ignore-hold --allow-unauthenticated -s dist-upgrade | grep ^Inst | cut -d ' ' -f2
ls -l /dev/disk/by-id | egrep ata-.*`hdparm -i /dev/sda | grep SerialNo | sed 's/.*SerialNo=//' | tr -d "\n"`.*sda$ | sed -e 's/.*ata-/ata-/' -e 's|[ ].*||' | tr -d "\n"
2013-01-07 10:20:25
Functions: egrep grep ls sed tr
Tags: Ubuntu
-1

This was tested on Ubuntu 12.04 (Precise) LTS Server. It returns the name of the symlink within /dev/disk/by-id for the physical drive you specify. Change /dev/sda to the one you want, and replace ata- with scsi- or the appropriate type for your drive.

I used this to pre-configure grub-pc during a non-interactive install because I had to tell it which disk to install grub on, and physical disks don't have a UUID such as that blkid provides.

curl http://en.m.wikipedia.org/wiki/List_of_Internet_top-level_domains | grep "<tr valign=\"top\">" | awk -F">" '{ print $5 }' | awk -F"<" '{ print $1 }'
2012-12-24 21:00:36
User: sxiii
Functions: awk grep
-3

Oneliner to get domain names list of all existing domain names (from wikipedia)

find -type f | xargs file | grep ".*: .* text" | sed "s;\(.*\): .* text.*;\1;"
/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
sudo dmidecode | grep Product
2012-12-18 12:31:39
User: joaquindlz
Functions: grep sudo
0

Command used to know if we are working on a virtual or physical machine. This command will use the dmidecode utility to retrieve hardware information of your computer via the BIOS. Run this command as root or with sudo.

grep -l 'flags.*\<lm\>' /proc/cpuinfo && (getconf LONG_BIT | grep '64') && java -version
2012-12-17 16:39:55
Functions: getconf grep
Tags: java 32bit 64bit
0

Let's you examine, for example, whether infrastructure folks really provisioned the correct setup.

Java 64-bit checklist

1. check if hardware is 64-bit capable by looking for lm flag

grep -l 'flags.*\<lm\>' /proc/cpuinfo

2. check if kernel is 64-bit

getconf LONG_BIT | grep '64'

3. check if java is 64-bit (simply look for 64-bit in output - if present, then it is, if absent, then it is 32-bit)

java -version
ps axu | grep [a]pache2
2012-12-15 19:37:19
User: EBAH
Functions: grep ps
11

Trick to avoid the form:

grep process | grep - v grep

48 function gbl() { git for-each-ref --sort=-committerdate --format='%(committerdate) %(authorname) %(refname)' refs/remotes/origin/|grep -e ".$@"|head -n 10; }
find . -type d | while read dir ; do num=`ls -l $dir | grep '^-' | wc -l` ; echo "$num $dir" ; done | sort -rnk1 | head
for line in `wget --referer='http://500px.com/' --quiet -O- http://500px.com/popular | grep "from=popular" | sed -n 's/.*<img src="\([^"]*\)".*/\1/p' | sed s/"3.jpg"/"4.jpg"/ | sed s/"?t".*$//`; do wget -O $RANDOM.jpg --quiet "$line"; done
2012-12-07 16:14:36
User: bugmenot
Functions: grep sed
0

This command downloads the actual 20 most popular pictures from the website 500px. It uses a random name due to the fact the the pictures in 500px are stored with the same name.

UPDATED: doesn't work if no referrer is specified: --referer='http://500px.com/'

grep postfix /var/log/messages | audit2allow -M mypolicy
ifconfig | grep inet
2012-12-05 20:54:07
User: Karunamon
Functions: grep ifconfig
Tags: Linux ifconfig
0

Returns the IP, broadcast, and subnet mask of your interfaces absent any other extraneous info.

I know it's a bit lame, but I've created an alias for this when I *quickly* want to know what a system's IP is. Small amounts of time add up :)

ifconfig |grep broadcast | awk '{print $2}'
2012-12-05 03:57:51
User: fotoflo
Functions: awk grep ifconfig
-12

get the ip address on your LAN

ifconfig |grep broadcast | awk '{print $2}'
${execi 300 lynx --dump http://www.commandlinefu.com/commands/random/plaintext | grep .}
2012-12-05 03:42:52
User: xyy_xx
Functions: grep
0

command for conky. To update a random command for each 300 sec from commandline.com

find . -name "*.[ch]" -exec grep -i /dev/null "search pharse" {} \;
2012-12-04 20:51:04
User: MikeGoerling
Functions: find grep
Tags: find grep
0

Old Sys5 system and SUN computers don't have the -H option. Adding /dev/null forces grep to use the multi-file output and report the file name.

ifconfig eth0 | grep HW | cut -d " " -f 11
scrotit(){ echo "Screenshot in $1 seconds...";scrot -d $1 '%Y%m%d%h.png' -e 'curl -sF file1=@- http://ompldr.org/upload < $f | grep -P -o "(?<=File:).*(http://ompldr.org/.*)\<\/a\>";rm $f'| sed -r 's@.*(http://ompldr.org/\w{1,7}).*@\1@';}
2012-12-03 01:21:19
User: dzup
Functions: echo grep rm sed
0

Take a screenshot, give $1 seconds pause to choose what to screenshot, then upload and get URI of post in ompdlr.org

omp(){ $*|convert label:@- png:-|curl -sF file1=@- http://ompldr.org/upload | grep -P -o "(?<=File:).*(http://ompldr.org/.*)\<\/a\>" | sed -r 's@.*(http://ompldr.org/\w{1,7}).*@\1@';}
2012-12-02 19:35:29
User: dzup
Functions: grep sed
1

Create a .png from output command or whatever, the upload and give URI from ompdlr.org

dig @resolver1.opendns.com myip.opendns.com | grep ^myip.opendns.com | tr '\t' : | cut -d: -f5