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 rm from sorted by
Terminal - Commands using rm - 248 results
find . -depth -name .svn -type d -exec rm -fr {} \;
2010-12-16 17:16:23
User: tebeka
Functions: find rm
Tags: find rm
5

-depth argument will cause find to do a "depth first" tree search, this will eliminate the "No such file or directory" error messages

find . -name .svn -type d |xargs rm -rf
find . -name .svn -type d -exec rm -rf '{}' +
2010-12-15 19:14:24
User: minnmass
Functions: find rm
3

With the plus instead of semicolon, find builds the (eg.) rm command like xargs does - invokes as few extra processes as possible.

find . -name .svn -type d -exec rm -rf {} \;
2010-12-15 18:51:08
Functions: find rm
-1

Removing .svn directories without a pipe

rm !(file_to_keep_undeleted)
2010-12-15 13:31:06
User: strzel_a
Functions: rm
6

Go to tmp :

cd /tmp; mkdir retmp; cd retmp

Create 10 files :

for i in {1..10}; do touch test$i; done

Remove all files except test10 :

rm !(test10)

shopt -s globstar; rm -rfv **/.svn
find . -name .svn -print0 | xargs -0 rm -rf
rm **/*.htm
2010-11-25 17:28:55
Functions: rm
Tags: find rm
-2

expands through shell and not find

but may hits the limit of max argument size for rm

(thus: for f in **/*.htm;do rm $f;done

but then I prefer the find command ;)

rm -rf *.htm
rm -rf `find . -type f -name *.htm`
find . -empty -type f -execdir rm -f {} +
2010-11-17 14:15:47
User: maffo7
Functions: find rm
-1

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
-2

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
User: Alz
Tags: sudo iptables
0

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
24

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
0

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
11

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
4

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