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 rm from sorted by
Terminal - Commands using rm - 262 results
find . -empty -type f -execdir rm -f {} +
2010-11-17 14:15:47
User: maffo7
Functions: find rm

This command will remove only files, not directories: if you wish to remove both directories and files, just remove '-type f' from command above

ls | grep .gz >> list.txt && cat list.txt | while read x ; do gunzip -d $x ; done && rm -rf list.txt
rm -f `find ./ | grep "\.\_.*"`
2010-11-16 20:52:33
User: edfuh
Functions: grep rm

Mac OSX creates resource forks (http://en.wikipedia.org/wiki/Resource_fork) for every file, which are extremely annoying when transferring projects over to an Ubuntu server for instance

find . -type d -name .svn -execdir rm -rf {} +
iptables-save > firewall.conf; rm -f /etc/network/if-up.d/iptables; echo '#!/bin/sh' > /etc/network/if-up.d/iptables; echo "iptables-restore < firewall.conf" >> /etc/network/if-up.d/iptables; chmod +x /etc/network/if-up.d/iptables
2010-11-13 23:58:28
Tags: sudo iptables

a simple command in order to make iptables rules permanent, run @ sudo!

mv * .[0-9a-Z]* ../; cd ..; rm -r $OLDPWD
rm *.txt <TAB> <TAB>
2010-11-04 13:58:15
User: boschi
Functions: rm

alternative for "echo rm *.txt". Just doubletab the command you are willing to use and it will show you the affected files.

ps -u $USER -lf | grep -vE "\-bash|sshd|ps|grep|PPID" > .tmpkill; if (( $(cat .tmpkill | wc -l) > 0 )); then echo "# KILL EM ALL"; cat .tmpkill; cat .tmpkill | awk '{print $4}' | xargs kill -9; else echo "# NOTHING TO KILL"; fi; cat .tmpkill; rm .tmpkill;
2010-11-04 04:16:50
User: zsugiart
Functions: awk cat echo grep kill ps rm wc xargs

Kills all process that belongs to the user that runs it - excluding bash, sshd (so putty/ssh session will be spared). The bit that says grep -vE "..." can be extended to include ps line patterns that you want to spare.

If no process can be found on the hitlist, it will print # NOTHING TO KILL. Otherwise, it will print # KILL EM ALL, with the cull list.

for i in $(file * | grep broken | cut -d : -f 1); do rm $i; done
echo rm *.txt
2010-10-27 07:26:26
User: alperyilmaz
Functions: echo rm

if you're using wildcards * or ? in your command, and if you're deleting, moving multiple files, it's always safe to see how those wildcards will expand. if you put "echo" in front of your command, the expanded form of your command will be printed. It's better safe than sorry.

find ~ -name "*.pyc" -exec rm {} \;
rm -f !(survivior.txt)
ram() { for i in /tmp /altroot;do mount -t tmpfs tmpfs $i;done&& for i in /var /root /etc $HOME; do find -d $i |cpio -pdmv /tmp&& mount -t tmpfs tmpfs $i&& mv -v /tmp$i/* $i&& rm -vrf /tmp$i ; done ;} usage: (in rc sequence) ram
2010-08-31 08:25:55
User: argv
Functions: cpio find mount mv rm

if you use disk-based swap then it can defeat the purpose of this function.

wget http://forums.dropbox.com && wget $(cat index.html|grep "Latest Forum Build"|cut -d"\"" -f2) && wget $(cat topic.php*|grep "Linux x86:"|cut -d"\"" -f2|sort -r|head -n1) && rm -rf ~/.dropbox* && rm index.html *.php* && tar zxvf dropbox-*.tar.gz -C ~/
cat b1.avi b2.avi b3.avi b4.avi b5.avi b6.avi b7.avi > output.avi; mencoder -forceidx -oac copy -ovc copy output.avi -o output_final.avi; rm output.avi
find $HOME -name '*.sol' -exec rm {} \;
2010-08-27 06:38:16
User: Tungmar
Functions: find rm

Maybe you want first check which files will be deleted:

find $HOME -name '*.sol' -exec echo rm {} \;
rm ^'name with spaces'
2010-08-21 02:24:17
User: dbbolton
Functions: rm
Tags: rm zsh glob

This is for zsh with extended globbing.

rm -f **/Thumbs.db
2010-08-18 07:09:19
User: Seebi
Functions: rm
Tags: thumbnails rm zsh

An alternative which uses the advanced zsh globbing (pattern matching)

rm -fr `find . -name Thumbs.db`
find ./ -name Thumbs.db -exec rm -rf '{}' +
tar tfz filename.tgz |xargs rm -Rf
find -type f -size +0 -mtime +1 -print0|xargs -0r rm -f
today=`date +%d`; ls -ltr | rm -f `nawk -v _today=$today '{ if($5 != 0 && $7 < _today) { print $9 } }'`
2010-07-29 13:47:19
User: alex__
Functions: ls rm

Delete all files that its size it's different than 0 and older than actuall day.

for i in {a..z};do sudo rm /usr/share/doc/$i*/*;done
2010-07-23 01:52:25
User: LinuxMan
Functions: rm sudo

Never read the documentation? No, then why have that ~ 20 MB sit there and take up space? This command preserves directory structure wile removing all of those unnecessary help and documentation files. Works on Ubuntu, Debian, and most related systems. Gives a lot of directory errors, I'll fix those later.

rm $( ls | egrep -v 'abc|\s' )
2010-07-18 10:59:15
User: dbbolton
Functions: egrep ls rm
Tags: grep rm

Really, you deserve whatever happens if you have a whitespace character in a file name, but this has a small safety net. The truly paranoid will use '-i'.