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 - 609 results
ps -fea | grep PATTERN | awk {'print $2'} | xargs kill -9
mount|grep -e '//'|cut -d ' ' -f3| xargs -I {} umount {}
2012-01-17 01:20:09
Functions: cut grep mount umount xargs
Tags: samba
0

This is a handy command to put into ~/.bash_logout to automatically un-mount windows shares whenever the user logs out. If you use this on as a non-root account then you'll need to append sudo before umount and the user will need to have the appropriate sudoer rights to run the /bin/umount command.

echo 474e552773204e6f7420556e697821 | sed -e 's/\(.\{2\}\)/\\\\x\1/g' | xargs echo -e
find . -type f -print0 | xargs -0r awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}'
ssh root@remote.host "rpm -qa" | xargs yum -y install
recoll -t -q "keyword" | grep message/rfc822 | sed -s 's,^.*\('$MAILDIR'[^]]*\)\].*$,\"\1\",' | xargs ln -sft $MAILDIR/bingo/cur/
identify -format '%w %h %f\n' *.jpg | awk 'NF==3&&$1<500&&$2<500{print $3}' | xargs -r rm
find . -iregex ".+\.\(c\|cpp\|h\)" | xargs -I{} perl -e "system(\"iconv -f SHIFT_JIS -t UTF-8 {} > temp; mv temp {} \");" ;
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -print0 | xargs -0 wc -l | tail -1
watch -tn1 'date +%T | xargs banner'
2011-11-20 04:46:02
User: kev
Functions: watch xargs
Tags: banner
5

# ### ### # # ### ### # # #

## # # ### # # # # ### ## # #

# # # # ### # # # # ### # # # #

# ### ##### # # #####

# # # ### # # ### # #

# # # ### # # ### # #

##### ### ### # ##### ### ##### #

zenity --list --width 500 --height 500 --column 'Wallpapers' $(ls) | xargs xsetbg -center -smooth -fullscreen
2011-11-15 02:44:48
User: TheShadowFog
Functions: xargs
-1

Assuming you have zenity installed, and assuming that you keep your backgrounds in ~/backgrounds, then this should work for you! :)

ls -1 $PATH*/* | xargs file | awk -F":" '!($2~/PDF document/){print $1}' |xargs rm -rf
find $SDIR -name '${f}.*' -mtime +$n -maxdepth 1 | xargs -n 10 rm -vf
lxc-ls | sort -u | xargs -i sudo lxc-info -n {}
2011-10-28 11:10:02
User: Rhonda
Functions: sort sudo xargs
Tags: status lxc
0

This short snippet outputs the state of all containers available on your system. It is quite helpful to see which ones are running and which are stopped. Please notice that the "sort -u" is needed, otherwise running containers will be reported twice (see output of "lxc-ls" on its own for why)

function whichpkg() { readlink -f "$(which $1)" | xargs --no-run-if-empty dpkg -S; }
2011-10-28 02:53:19
User: b_t
Functions: readlink xargs
6

This revision to my command (command #8851) was called for when it failed to find the parent

package of 'rlogin', which is really a deep symbolic link to /usr/bin/ssh.

This revision fixes this newfound issue, while ensuring fixes of other older issues work too.

find . -type f -print0 | xargs -0 rename 's/\ //g'
2011-10-25 21:46:36
Functions: find rename xargs
1

delete file name space

the rename is rename perl version

unzip -l filename.zip |awk '{ if($4 != "Name" && $4 != "----") print $4}'|xargs -t rm -rf {}
2011-10-20 18:54:15
User: hk0i
Functions: awk rm xargs
Tags: awk xargs unzip rm
0

Sometimes you unzip a file that has no root folder and it spews files all over the place. This will clean up all of those files by deleting them.

grep -rlZ oldstring . | xargs -0 sed -i -e 's/oldstring/newstring/'
2011-10-18 19:14:02
Functions: grep sed xargs
Tags: sed
1

Using -Z with grep and -0 with xargs handles file names with spaces and special characters.

#!/bin/bash find | grep -P -v "(class)|(zip)|(png)|(gz)|(gif)|(jpeg)|(jpg)" | xargs -I @ grep -H $1 @
2011-10-14 13:28:49
User: kirdie
Functions: find grep xargs
Tags: find grep
-1

calls grep on all non-binary files returned by find on its current working directory

for each in /usr/bin/*; do echo $each | sed 's/\/usr\/bin\///' | xargs touch; done
2011-10-13 19:14:34
User: evil
Functions: echo sed xargs
1

This will make a false directory with the same file names as whatever directory you choose. This is wise to use when testing scripts that alter contents, filenames, or move files. I wrote this after an OOPS I made when renaming a directory of JPGs, PNGs, PSDs that were mixed. I recommend this as I lost over 2000 vacation pictures and some graphics I designed for software and web sites. :(

NOTE: This only creates name copies, that data itself is not copied.

svn status|grep -iR '^!'|sed 's/!/ /g'|xargs -i svn rm '{}'
2011-10-06 08:11:25
User: erdeszt
Functions: grep rm sed xargs
Tags: svn sed xargs grep
0

Helps if you accidentally deleted files from an svn repo with plain rm and you would like to mark them for svn to delete too.

LC_ALL=C diff -q dir1 dir2 | grep differ | awk '{ print $2, $4 }' | xargs -n 2 gvim --nofork -d
2011-09-06 11:50:33
User: brock
Functions: awk diff grep xargs
0

LC_ALL=C is here to always grep on "differ" whatever your language env.

xargs -n 2 to run gvim -d with 2 arguments

gvim --nofork to use only one instance of gvim

find . -type f | xargs grep -n "Old Text" | tee filesChanged.txt | sed 's/:.*$//' | xargs sed -i 's/Old Text/New Text/g
find -iname \*.pdf -print0 | xargs -0 pdfgrep -i "my search text"
svn st -q | cut -c 2- | tr -d ' ' | xargs tar -czvf ../backup.tgz
2011-08-31 10:30:29
User: titus
Functions: cut tar tr xargs
1

This works more reliable for me ("cut -c 8-" had one more space, so it did not work)