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 - 599 results
find / -type f -name IMG_????.JPG -print0 |xargs -0 exiv2 -g Exif.Canon.ModelID '{}' |grep A520 |rev |cut --complement -d " " -f1-40 |rev |xargs -I {} cp --parents {} /where
2012-03-10 03:01:01
User: fladam
Functions: cp cut find grep rev xargs
-1

You must spezify /where folder and / folder

If you have another camera you must experiment with Exif data (after -g and after grep) and mask of your photo files IMG_????.JPG

I have do it on Knoppix 6.7.0

You must have installed exiv2.

aptitude -F "%p" search \!~M~i~T | xargs apt-mark markauto
2012-03-09 13:44:00
User: gspadari
Functions: xargs
0

Marks all manually installed deb packages as automatically installed. Usefull to combine with

apt-get install <all manually packages that we want>

to have a clean installed debian-based system.

find -name *.lock |xargs rm -f
2012-03-07 04:48:03
User: mpax
Functions: find rm xargs
0

This command removes *.lock or files from a folder.

adb shell ps | grep <process name> | awk '{print $2}' | xargs adb shell kill
2012-03-03 01:03:39
Functions: awk grep ps xargs
0

This is great when you need to reboot the system-server, or your own daemon that has gone crazy

find <directory> -type f -printf "%T@\t%p\n"|sort -n|cut -f2|xargs ls -lrt
ls -ltr --directory $(find . -regex "./.*[^/]*\'" -type f | xargs -n 1 dirname | sort | uniq)
2012-03-02 03:48:47
User: pdkl95
Functions: dirname find ls sort xargs
0

This let me find some a set of modifications that were made to a rather large tree of files, where the file-names themselves were not unique (actually: insanely redundant and useless. "1.dat 2.dat ..."). Pruning down to last-branch brough things back to the "project-name" scope, and it's then easy to see which branches of the tree have recently changed, or any other similar search.

Ideally, it should sort the directories by the mtime of the most recent *file* *inside* the directory, but that's probably outside the scope of a (sane...) command line.

sudo find . -name "syslog*.gz" -type f | xargs gzip -cd | grep "Mounted"
cat z.log | cut -d ':' -f1 | sort | uniq | xargs -l1 -iFF echo 'echo FF $(cat z.log | grep -e "^FF" | grep -e Timeout | wc -l )' | bash
PID=httpd ; ps aux | grep $PID | grep -v grep | awk '{print $2}' | xargs kill -9
2012-02-21 23:27:47
User: esaenz
Functions: awk grep kill ps xargs
-4

# define user pid to kill

PID=httpd ;

# kill all pids

ps aux | grep $PID | grep -v grep | awk '{print $2}' | xargs kill -9

ldd file | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' /destination
2012-02-11 17:50:10
User: rickard2
Functions: awk cp file grep ldd xargs
0

When working with jailed environments you need to copy all the shared libraries to your jail environment. This is done by running ldd on a binary which needs to run inside the jail. This command will use the output from ldd to automatically copy the shared libraries to a folder of your choice.

git remote | xargs -n 1 git push
curl -s ifconfig.me|tee >(xargs geoiplookup)
2012-02-09 20:30:26
Functions: tee xargs
Tags: tee curl geoip
0

Show external IP and geolocation information.

Primary feature is the use of tee to echo IP _and_ send to geoiplookup command...Use IP as input for as many commands as you want with more >( [command] )

Thanks to http://www.commandlinefu.com/commands/view/6334/

Requires MaxMind DB and geoiplookup tool.

Sample output has IP obfuscated on first line, lines 2-4 from having MaxMind Country && MaxMind City DBs installed

find /protocollo/paflow -type f -mtime +5 | xargs tar -cvf /var/dump-protocollo/`date '+%d%m%Y'_archive.tar`
2012-02-03 16:24:08
User: 0disse0
Functions: find tar xargs
1

Finally, we can make the file "unchangeable"

sudo chattr +i

fdupes -R -1 path | while read -r line; do (echo $line | xargs -n 1 | (first="true"; firstfile=""; while read file; do if [ "$first" == "true" ]; then first="false"; firstfile=$file; else ln --force "$firstfile" "$file"; fi; done)); done
2012-02-01 15:08:18
User: eclewis
Functions: echo ln read xargs
1

This variation can handle file paths containing spaces.

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! :)