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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands using xargs from sorted by
Terminal - Commands using xargs - 630 results
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
2010-06-10 20:33:32
User: mitzip
Functions: sed sudo xargs

This will remove all installed kernels on your debian based install, except the one you're currently using.



find ~/.thunderbird/*.default/ -name *.msf -print0 | xargs --no-run-if-empty -0 rm;
find ~/.thunderbird/*.default/ -name *.msf | sed 's/ /\\ /g' | xargs rm {} \;
2010-06-04 12:35:24
User: allrightname
Functions: find rm sed xargs

The thunderbird message datastores get corrupt some times causing random failures, compaction to fail and general suck in thunderbird. Removing them causes thunderbird to rebuild the indexes and makes things quick again.

find directory -maxdepth 1 -type f | xargs ls -l | awk 'BEGIN { SUM=0} { SUM+=$5 } END { print SUM/2^20 }'
top -bn 1 | awk '{if($1 ~ /^[0-9]+$/ && $9 > 97) {print $1;exit}}'|xargs kill
2010-06-02 13:51:40
User: chx
Functions: awk top xargs

I found Flash eating one of my CPUs after resume, the command above will help with that. For optional kicks you can put it into a script in /etc/pm/sleep.d/ (aspect in #swhack wrote this for me)

od -An -w999 -t xC <<< "$1" | sed 's/[ ]\?\(c[23]\) \(..\)/%\1%\2/g;s/ /\\\\\x/g' | xargs echo -ne
2010-05-31 16:35:52
Functions: echo od sed xargs

It only encodes non-Basic-ASCII chars, as they are the only ones not well readed by UTF-8 and ISO-8859-1 (latin-1).

It converts all

* C3 X (some latin symbols like ASCII-extended ones)

and * C2 X (some punctuation symbols like inverted exclamation)

...UTF-8 double byte symbols to escaped form that every parser understands to form the URLs. I didn't encode spaces and the rest of basic punctuation, but supposedly, space and others are coded as \x20, for example, in UTF-8, latin-1 and Windows-cp1252.... so its read perfectly.

Please feel free to correct, the application to which I designe that function works as expected with my assumption.

Note: I specify a w=999, I didn't find a flag to put unlimited value.

I just suppose very improbable surpass the de-facto 255 (* 3 byte max) = 765 bytes length of URL

find -type f -print0 | xargs -r0 stat -c %y\ %n | sort
2010-05-29 13:40:18
User: dooblem
Functions: find stat xargs

Works with files containing spaces and for very large directories.

find . -type f | xargs ls -ltrhg
2010-05-28 01:23:53
User: emacs
Functions: find ls xargs

find and normal files and list them sorting with modification time without group

l: with detailed information

t: sort with modification time

r: reverse order

h: show file's size in human-readable format, such as K(kilobytes), M(megabyes) etc.

g: do not show group

grep -R usepackage * | cut -d']' -f2 | cut -s -d'{' -f 2 | sed s/"}"/.sty"}"/g | cut -d'}' -f1 | sort | uniq | xargs dpkg -S | cut -d':' -f1 | sort | uniq
find * -type f -not -name ".*" | xargs wc -l
2010-05-21 21:03:31
User: Leechael
Functions: find wc xargs

We use `-not -name ".*"` for the reason we must omit hidden files (which unnecessary). We can only show up total lines like this:

find * -type f -not -name ".*" | xargs wc -l | tail -1
watch 'find -maxdepth 1 -mindepth 1 -type d |xargs du -csh'
2010-05-19 13:13:57
User: shadycraig
Functions: du watch xargs

This command shows the size of directories below here, refreshing every 2s.

It will also track directories created after running the command (that what the find bit does).

rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; }
2010-05-13 09:28:56
User: sata
Functions: grep ls rm xargs
rm-but() { ls -Q | grep -v "$1" | xargs rm -r ; }

Add this to your .bashrc file.

Then whenever you need to remove all files/directories but one from present working directory. Run:

rm-but <important-file-or-directory>


1. This doesn't affect the hidden files.

2. Argument is actually as string. And all files/directories having this string in there name are left untouched.

find / -type f -size +512000 | xargs ls -lh | awk '{ print $5 " " $6$7 ": " $9 }'
2010-05-12 17:21:12
User: johnss
Functions: awk find ls xargs

This is an updated version that some one provided me via another "find" command to find files over a certain size. Keep in mind you may have to mess around with the print values depending on your system to get the correct output you want. This was tested on FC and Cent based servers. (thanks to berta for the update)

pgrep rouge-process | xargs sudo kill -9
2010-05-09 22:30:05
User: mheadd
Functions: kill sudo xargs
Tags: xargs pgrep

Find and kill multiple instances of a process with one simple command.

find . \( -iname '*.[ch]' -o -iname '*.php' -o -iname '*.pl' \) | xargs wc -l | sort -n
2010-04-30 12:21:28
User: rbossy
Functions: find sort wc xargs
Tags: find count

find -exec is evil since it launches a process for each file. You get the total as a bonus.

Also, without -n sort will sort by lexical order (that is 9 after 10).

zenity --list --width 500 --height 500 --column 'radio' --column 'url' --print-column 2 $(curl -s http://www.di.fm/ | awk -F '"' '/href="http:.*\.pls.*96k/ {print $2}' | sort | awk -F '/|\.' '{print $(NF-1) " " $0}') | xargs mplayer
2010-04-28 23:45:35
User: polaco
Functions: awk sort xargs

This is a very simple and lightweight way to play DI.FM stations

For a more complete version of the command with proper strings in the menu, try: (couldnt fit in the command field above)

zenity --list --width 500 --height 500 --title 'DI.FM' --text 'Pick a Radio' --column 'radio' --column 'url' --print-column 2 $(curl -s http://www.di.fm/ | awk -F '"' '/href="http:.*\.pls.*96k/ {print $2}' | sort | awk -F '/|\.' '{print $(NF-1) " " $0}') | xargs mplayer

This command line parses the html returned from http://di.fm and display all radio stations in a nice graphical menu. After the radio is chosen, the url is passed to mplayer so the music can start


- x11 with gtk environment

- zenity: simple app for displaying gtk menus (sudo apt-get install zenity on ubuntu)

- mplayer: simple audio player (sudo apt-get install mplayer on ubuntu)

find . -maxdepth 1 -type f | xargs stat
2010-04-26 20:51:54
User: asolkar
Functions: find xargs

Possible simplification of egrep-awk-sort with find and -exec with xargs.

more xx.m3u |grep -v "^#" |xargs -i cp {} target
S='<iframe src=\"http:\/\/\/bad\/index.php\" width=\"1\" height=\"1\" frameborder=\"0\"><\/iframe>' && R=''; find . -name "*.html" -exec grep -l "$S" {} \; | xargs sed -i -e "s/$S/$R/g"
2010-04-12 21:45:16
User: rexington
Functions: find grep sed xargs

Removes the given string from all files under the given path - in this case the path given is "." This demonstrates the characters that must be escaped for the grep and sed commands to do their work correctly. Very handy for fixing hacked html files.

ps aux|grep -i [p]rocessname|awk '{ print $2 }'|xargs kill
sudo deborphan | xargs sudo apt-get -y remove --purge
find . -name 'pattern'| xargs du -hc
ls | egrep -v "[REGULAR EXPRESSION]" | xargs rm -v
2010-04-01 02:40:40
User: Saxphile
Functions: egrep ls rm xargs
Tags: files rm

This is a slight variation of an existing submission, but uses regular expression to look for files instead. This makes it vastly more versatile, and one can easily verify the files to be kept by running ls | egrep "[REGULAR EXPRESSION]"

find . -name file.txt | xargs -e grep "token" -o | wc -l
curl http://www.reddit.com/r/wallpapers.rss | grep -Eo 'http:[^&]+jpg' | head -1 | xargs feh --bg-seamless
2010-03-27 00:08:40
Functions: grep head xargs

You'll need "feh" to set the background from the commandline. Install with "apt-get install feh"

Thanks to the Redditors on this thread: http://www.reddit.com/r/linux/comments/bira4/is_there_a_linux_version_of_this_preferably_a/