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,520 results
awk '/Dec\/2012/ {print $1,$8}' logfile | grep -ivE '(.gif|.jpg|.png|favicon|.css|.js|robots.txt|wp-l|wp-term)' | sort | uniq -c | sort -rn | head -n 20
find /etc -exec grep '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;
history | tail -100 | grep cmd
2013-04-22 03:49:43
User: datamining
Functions: grep tail
0

this also can find the old command you used before

dmesg | grep -i sata | grep 'link up'
2013-04-18 15:41:33
User: FadeMind
Functions: dmesg grep
Tags: ssd hdd sata
0

Check SATA controller type.

6.0 Gbps - SATA III

3.0 Gbps - SATA II

1.5 Gbps - SATA I

grep -nisI <pattern> * .[!.]*
2013-04-18 14:33:41
User: lajarre
Functions: grep
0

options: -n line nbrs, -i ignore case, -s no "doesn't exist", -I ignore binary

args: * for all files of current dir (not hidden), .[!.]* for all hidden files

I don't include by default the -R (recursive) option, which is not always useful. You add it by hand when needed.

cat .bash_history | tail -100 | grep {command}
2013-04-10 10:40:52
User: techie
Functions: cat grep tail
-9

I know how hard it is to find an old command running through all the files because you couldn't remember for your life what it was. Heres the solution!! Grep the history for it. depending on how old the command you can head or tail or if you wanted to search all because you cannot think how long ago it was then miss out the middle part of the command. This is a very easy and effective way to find that command you are looking for.

for i in $(objdump -d binary -M intel |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo
grep -E/egrep 'word1.*word2|word2.*word1' "$@"
function google { Q="$@"; GOOG_URL='https://www.google.de/search?tbs=li:1&q='; AGENT="Mozilla/4.0"; stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}${Q//\ /+}" | grep -oP '\/url\?q=.+?&amp' | sed 's|/url?q=||; s|&amp||'); echo -e "${stream//\%/\x}"; }
2013-04-05 08:04:15
User: michelsberg
Functions: echo grep sed
Tags: google
12

Put it in your ~/.bashrc

usage:

google word1 word2 word3...

google '"this search gets quoted"'

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
find ./public_html/ -name \*.php -exec grep -HRnDskip "\(passthru\|shell_exec\|system\|phpinfo\|base64_decode\|chmod\|mkdir\|fopen\|fclose\|readfile\) *(" {} \;
2013-04-03 12:42:19
User: lpanebr
Functions: find grep
0

Searched strings:

passthru, shell_exec, system, phpinfo, base64_decode, chmod, mkdir, fopen, fclose, readfile

Since some of the strings may occur in normal text or legitimately you will need to adjust the command or the entire regex to suit your needs.

Q="YOURSEARCH"; GOOG_URL="http://www.google.com/search?q="; AGENT="Mozilla/4.0"; stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}\"${Q/\ /+}\"" | grep -oP '\/url\?q=.+?&amp' | sed 's/\/url?q=//;s/&amp//'); echo -e "${stream//\%/\x}"
2013-04-03 09:56:41
User: techie
Functions: echo grep sed
Tags: google
8

I found this command on a different site and thought you guy might enjoy it. Just change "YOURSEARCH" to what ever you want to search. Example, "Linux Commands"

ps aux | grep [process] | awk '{print $2}' | xargs -I % ls /proc/%/fd | wc -l
lsof -i -n | grep ESTABLISHED
2013-04-03 09:14:09
User: techie
Functions: grep
2

Fast and easy way to find all established tcp connections without using the netstat command.

for a in $(seq 5 8); do cat twit.txt | cut -d " " -f$a | grep "^@" | sort -u; done > followlst.txt
2013-03-29 21:07:09
User: xmuda
Functions: cat cut grep seq sort
-6

Go to "https://twitter.com/search/realtime?q=%23TeamFollowBack&src=hash" and then copy al the text on the page. If you scroll down the page will be bigger. Then put al the text in a text file called twit.txt

If you follow the user there is a high probability the users give you follow back.

To follow all the users you can use an iMacros script.

grep -qIm1 . $file
2013-03-28 14:11:51
User: anon1251
Functions: grep
0

This command produces no output, but its exit status is 0 ("true") if $file is text, non-0 ("false") if $file is binary (or is not accessible).

Explanation:

-q suppresses all the output of grep

-I is the trick: if a binary file is found, it is considered a non-match

-m 1: limit "output" to first match (speed up for big files)

.: the match string, "." stands for any character

Usage: e.g. run editor only on text files

grep -qIm 1 . $file && vi $file
git log | grep Date | awk '{print " : "$4" "$3" "$6}' | uniq -c
grep -Fvxf $(file1) $(file2) | wc -l
dpkg -l |grep i386 | awk '{ print "apt-get -y remove --purge "$2 }' | sh
if wget https://twitter.com/users/username_available?username=xmuda -q -O - | grep -q "\"reason\":\"taken\""; then echo "Username taken"; else echo "Free / Banned Name"; fi
2013-03-23 17:39:15
User: Joschasa
Functions: echo grep wget
0

Reason can be: taken, available, contains_banned_word

if lynx --dump http://twitter.com/xmuda | grep -q "Sorry, that page does"; then echo "Dont Exist"; else echo "Exist"; fi
2013-03-23 16:12:24
User: xmuda
Functions: echo grep
-4

I use these command to validate twitter accounts, we can use a "for a in $(cat list.txt)" to validate a complete list of twitter accounts.

lsof -i -P +c 0 +M | grep -i "$1"
netstat -an | grep --color -i -E 'listen|listening'
tcpdump -l -s0 -w - tcp dst port 25 | strings | grep -i 'MAIL FROM\|RCPT TO'
2013-03-18 18:55:20
User: ene2002
Functions: grep strings tcpdump
3

This works just as well for SMTP. You could run this on your mail server to watch e-mail senders and recipients:

tcpdump -l -s0 -w - tcp dst port 25 | strings | grep -i 'MAIL FROM\|RCPT TO'

find /some/path -type f -printf '%f\n' | grep -o '\..\+$' | sort | uniq -c | sort -rn
2013-03-18 14:42:29
User: skkzsh
Functions: find grep sort uniq
2

Get the longest match of file extension (Ex. For 'foo.tar.gz', you get '.tar.gz' instead of '.gz')