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
ls -R | grep : | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''
2009-02-09 22:32:01
User: scw
Functions: grep ls sed
-3

Shows the current directory and those below it in a simple tree structure. Recommended use:

alias lt='$command_above'

grep -lir "text to find" *
grep -r "sampleString" . |uniq | cut -d: -f1 | xargs sed -i "/sampleString/d"
2009-02-09 20:21:30
User: sk1418
Functions: cut grep sed xargs
-2

checking files in current and sub directories, finding out the files containing "sampleString" and removing the containing lines from the file.

* Beware that The command will update the original file [no backup].

The command can be extended if play with 'find' command together,

e.g. it is possible to execute on certain type of files: *.xml, *.txt... (find -name "*.xml" | grep....)

if anybody knows a better solution on that, please drop a comment. thx.

find . \( -name '*.h' -o -name '*.cc' \) | xargs grep . | wc -l
2009-02-09 11:44:35
User: dgomes
Functions: find grep wc xargs
3

Counts number of lines of code in *.h and *.cc files

alias pfind='ps aux | grep '
df -x tmpfs | grep -vE "(gvfs|procbususb|rootfs)"
2009-02-09 01:54:05
User: bones7456
Functions: df grep
-1

show physical disk using, except tmpfs, gvfs, and so on.

ldconfig -p | grep <somenewlib.so>
2009-02-07 23:15:38
User: al3x
Functions: grep ldconfig
0

Allows to check if shared library could be dynamically loaded

find /path -name \*.php -user nobody -exec grep -nH whatever {} \;
2009-02-07 20:53:56
User: al3x
Functions: find grep
0

allows to grep very narrow subset of files

alias grep 'gnu grep -i --color=auto'
2009-02-07 18:54:56
User: mnikhil
Functions: alias grep
1

Alias the grep command to show colored results by default.

alias nsl 'netstat -f inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail +2'
find $(pwd) -type f -exec grep -l "$(echo "\r")" {} \;
2009-02-07 18:53:00
User: mnikhil
Functions: find grep
1

its useful to run dos2unix command later on them.

last | awk '{ print $1 }' | sort | uniq -c | grep -v wtmp
kill -HUP ` ps -aef | grep -i firefox | sort -k 2 -r | sed 1d | awk ' { print $2 } ' `
mount | grep : | tr -s ' ' -d 3 | xargs umount -v
tail -f <filename> | grep -C <# of lines to show above and below> <text>
cflow file.c | grep ':$' | sed 's/ <.*//'
guid(){ lynx -nonumbers -dump http://www.famkruithof.net/uuid/uuidgen | grep "\w\{8\}-" | tr -d ' '; }
sed "s/^ABC/+ABC/" <file | sed "s/DEF$/DEF+/" | tr "\n" "~" | tr "+" "\n" | grep "^ABC" | tr "~" "\n"
2009-02-06 11:29:29
User: poboxy
Functions: grep sed tr
2

If the file content is :

-

Blah blah blah

ABC

hello blah blah blah

bloh bloh bloh

DEF

Bah bah bah

-

You'll get:

-

ABC

hello blah blah blah

bloh bloh bloh

DEF

find . -exec grep "test" '{}' /dev/null \; -print
grep -r -l xxxxx . | xargs perl -i -pe "s/xxxxx/yyyyy/g"
2009-02-06 08:18:50
User: hassylin
Functions: grep perl xargs
-1

This script first find all files which contains word xxxxx recursively. Then replace the word xxxxx to yyyyy of the files.

Use case:

- Web site domain change

- Function name change of the program

find DIR -name "FILE" -exec grep -IHn STRING {} \;
kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'`
2009-02-06 02:42:14
User: liupeng
Functions: awk grep kill
-1

You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service.

You can kill zombie process using PID obtained from the above command. For example kill zombie proces having PID 4104:

# kill -9 4104

Please note that kill -9 does not guarantee to kill a zombie process.

ps aux | awk '{ print $8 " " $2 " " $11}' | grep -w Z
cleartool co -nc `cleartool ls -recurse | grep "hijacked" | sed s/\@\@.*// | xargs`
cvs -Q status | grep -i locally