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 - 257 results
rmall_but() { declare -A keep;for arg;do keep[${arg%/}]=1;done;for file in *;do [[ ${keep[$file]} ]] || rm -rf "$file";done; }
ls -ai | grep filename | find . -inum `awk '{print $1}'` -exec rm {} \;
2011-02-04 10:29:54
User: YogiBare
Functions: find grep ls rm
-1

This command, when run from the directory containing "filename", will remove the file and any hard or symbolic links to the file.

wget http://www.discogs.com/search?q=724349691704 -O foobar &> /dev/null ; grep \/release\/ foobar | head -2 | tail -1 | sed -e 's/^<div>.*>\(.*\)<\/a><\/div>/\1/' ; rm foobar
2011-01-30 23:34:54
User: TetsuyO
Functions: grep head rm sed tail wget
-1

Substitute that 724349691704 with an UPC of a CD you have at hand, and (hopefully) this oneliner should return the $Artist - $Title, querying discogs.com.

Yes, I know, all that head/tail/grep crap can be improved with a single sed command, feel free to send "patches" :D

Enjoy!

rm *[!teste0,teste1,teste2]
2011-01-25 22:00:29
Functions: rm
Tags: grep rm
-2

Remove all arquives except the list.

Can't have space between the commas.

rm *[!abc]
2011-01-25 19:41:41
User: Vilemirth
Functions: rm
Tags: grep rm
0

Bash method to remove all files but "abc".

It would be 'rm *~abc' in Zsh.

unjar () { mkdir -p /tmp/unjar/$1 ; unzip -d /tmp/unjar/$1 $1 *class 1>/dev/null && find /tmp/unjar/$1 -name *class -type f | xargs jad -ff -nl -nonlb -o -p -pi99 -space -stat ; rm -r /tmp/unjar/$1 ; }
echo '<?php echo str_rot13 ("Hello World") ?>' > hw.php && php hw.php && rm hw.php
2011-01-04 21:15:19
User: IsraelTorres
Functions: echo rm
-2

created and tested on:

ProductName: Mac OS X

ProductVersion: 10.6.5

BuildVersion: 10H574

for i in ~/.adobe ~/.macromedia ; do ( rm $i/ -rf ; ln -s /dev/null $i ) ; done
2010-12-29 13:23:48
User: mhs
Functions: ln rm
18

Brute force way to block all LSO cookies on a Linux system with the non-free Flash browser plugin. Works just fine for my needs. Enjoy.

rm -rf !(@(file1|file2|...))
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
Tags: sudo iptables
0

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

mv * .[0-9a-Z]* ../; cd ..; rm -r $OLDPWD