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 xargs from sorted by
Terminal - Commands using xargs - 610 results
find . -name "*.php" -print | xargs sed -i 's/foo/bar/g'
ps -fu $USER | awk {'print $2'} | xargs kill [-9]
ps auxww | grep application | grep processtobekilled | gawk '{print $2}' | grep -v grep | xargs kill -9
2012-07-03 20:37:56
User: j0sh10
Functions: gawk grep kill ps xargs
0

You can also use gawk:

ps auxww | gawk '/application/' | gawk '/processtobekilled/' | gawk '{print $2}' | grep -v grep | xargs kill -9

find . -type f -print0 | xargs -0 du -h | sort -hr | head -10
find . -type f -print0 | xargs -0 du -h | sort -hr | head
git submodule status | awk '{print $2}' | xargs -P5 -n1 git submodule update --init
find /path/to/dir -type f -print0 | xargs -0 grep -l "foo"
grep -r -Z -l "<text>" . | xargs -0 echo rm
2012-06-14 08:09:46
User: limonte
Functions: echo grep xargs
Tags: grep
4

-r recursively

-Z zero byte after each file name instead of the usual newline

-l only filenames

find . -type f -print0 | xargs -0 chmod a-x
2012-06-11 07:28:30
User: jlaunay
Functions: chmod find xargs
-2

Using xargs is usually much quicker as it does not have to execute chmod for every file

ls -ltr |grep 'May 12'|awk '{print $9;}'|xargs rm -v
git ls-files | xargs -n1 git blame --line-porcelain | sed -n 's/^author //p' | sort -f | uniq -ic | sort -nr
2012-06-02 22:04:36
User: hugopeixoto
Functions: sed sort uniq xargs
Tags: statistics git
1

Uses line-porcelain in git blame, which makes it easier to parse the output.

for foo in <list of directories>; do while find $foo -type d -empty 2>/dev/null| grep -q "."; do find $foo -type d -empty -print0 | xargs -0 rmdir; done; done
2012-05-23 08:09:16
Functions: find grep xargs
0

This will check if there are any empty directories, or newly emptied directories, in a list of directories. It will then delete all of those directories. It works with gnu find and OSX/BSD find.

seq 1 5 | xargs -I"#" date --date="today -# days" +'%Y-%m-%d'
find . -name '.svn' -type d | xargs rm -rf
2012-05-18 10:26:55
User: luckymurari
Functions: find rm xargs
0

This simple command removes all the .svn directories recursively. Useful when you want to get a clean code excluding .svn files.

Check what is getting delete through this command

" find . -name '.svn' -type d | xargs echo "

find -type l | xargs ls -l
cat urls.txt | xargs -n1 curl -O --max-time 10 --retry 3 --retry-delay 1
lsof -i tcp:22 | grep 192.168.10.10 | awk "{print $2}" |xargs kill
find . | xargs xattr -d com.apple.quarantine
2012-05-09 23:06:51
User: brockangelo
Functions: find xargs
-2

When downloading files on a Mac, Apple adds the x-attribute: com.apple.quarantine. Often, this makes it so you can't even run a ./configure. This command gets rid of the quarantine for all files in the current directory.

find . -iname ".svn" | xargs rm -r $1
find . -type f -name *.MP3 -print0 | xargs -0 -i rename .MP3 .mp3 {}
2012-04-29 02:44:44
User: pibarnas
Functions: find rename xargs
0

Using a for loop, rename all files with .MP3 extension to .mp3.

ps afx | grep defunct -B 1 | grep -Eo "[0-9]{3,}" | xargs kill -9
2012-04-27 16:16:34
User: pholz
Functions: grep kill ps xargs
0

defunct processes (zombies) usually have to be killed by killing their parent processes. this command retrieves such zombies and their immediate parents and kills all of the matching processes.

wget -O - http://www.reddit.com/r/wallpapers.rss | grep -Eo 'http://i.imgur.com[^&]+jpg' | head -1 | xargs wget -O background.jpg
2012-04-25 11:15:26
User: untitaker
Functions: grep head wget xargs
0

Doesn't depend on curl and doesn't use thumbnails as wallpaper (which has the unfortunate effect of only allowing imgur links)

find . -user root | xargs sudo chown me:me
2012-04-24 18:29:13
Functions: chown find sudo xargs
-2

be careful where you execute this from

do a 'sudo ls' beforehand to prime sudo to not ask for your password

ls -s|grep -E "^ *0"|sed "s/^ *0 //g"|xargs -i rm "{}"
2012-04-18 14:50:46
User: glaudiston
Functions: grep ls rm sed xargs
-8

Remove all zero size files from current directory. Its a not recursive option like:

find . -size 0c -exec rm {} \;

git remote -v | grep fetch | sed 's/\(.*github.com\)[:|/]\(.*\).git (fetch)/\2/' | awk {'print "https://github.com/" $1'} | xargs open
2012-04-15 20:48:46
User: brockangelo
Functions: awk grep sed xargs
1

Written for Mac OSX. When you are working in a project and want to open it on Github.com, just type "gh" and your default browser will open with the repo you are in. Works for submodules, and repo's that you don't own.

You'll need to copy / paste this command into a gh.sh file, then create an alias in your bash or zsh profile to the gh.sh script. Detailed instructions here if you still need help:

http://gist.github.com/1917716