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
function rm { workingdir=$( pwdx $$ | awk '{print $2}' ) /usr/bin/rm $* echo "rm $* issued at $(date) by the user $(who am i| awk '{print $1} ') in the directory ${workingdir}" >> /tmp/rm.out }
2011-06-22 14:47:38
User: soulonfire
Functions: awk echo rm
1

Sometimes, it is annoying to find your files or directories missing. If you want to log all the rm commands you can put this in /etc/profile.

adobenospy() { for I in ~/.adobe ~/.macromedia ; do ( [ -d $I ] && rm -rf $I ; ln -s -f /dev/null $I ) ; done }
2011-06-08 14:34:52
User: Timothy
Functions: ln rm
0

A safer way to block adobe and macromedia flash tracking and spyware

git ls-files -z -d | xargs -0 git rm --
rm -rf /bin/laden
for arq in *.png; do size=$(identify $arq | cut -f3 -d" "); [ $size == "280x190" ] || rm $arq ; done
2011-04-22 20:00:05
Functions: cut rm
Tags: ImageMagick
1

Removes all png files whose geometry is not 280x190 pixels

yt-pl2mp3() {umph -m 50 $1 | cclive -f mp4_720p; IFS=$(echo -en "\n\b"); for track in $(ls | grep mp4 | awk '{print $0}' | sed -e 's/\.mp4//'); do (ffmpeg -i $track.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 $track.mp3); done; rm -f *.mp4}
2011-03-20 14:43:20
User: sattellite
Functions: awk echo grep ls rm sed
0

umph is parsing video links from Youtube playlists ( http://code.google.com/p/umph/ )

cclive is downloading videos from Youtube ( http://cclive.sourceforge.net/ )

Example:

yt-pl2mp3 7AB74822FE7D03E8
locate munin | xargs rm -r
rm -r .[!.]*
rm -rf .[!.]*
rm -rf .??*
2011-03-11 07:21:58
User: greggster
Functions: rm
Tags: rm dot
0

rm -rf .* matches ".." and thus one goes up a level and wipes out more than intended.

In bash, .??* safely accomplishes what one intends - remove those .files

The ? matches most characters except "/", thus .?? does not match ../ and so one is safe.

find . -maxdepth 1 -type d | grep -Pv "^.$" | sort -rn --field-separator="-" | sed -n '3,$p' | xargs rm -rf
git filter-branch --index-filter 'git rm --cached --ignore-unmatch FileToRemove' HEAD
mv .git .. && rm -rf * && mv ../.git . && mv .git/* . && rmdir .git && git config --bool core.bare true
2011-02-28 17:58:14
User: dinomite
Functions: mv rm rmdir
1

If you want to turn a Git repo into the origin that folks can push to, you should make it a bare repository. See: http://stackoverflow.com/questions/2199897/git-convert-normal-to-bare-repository

ps ax > processes && cat processes | egrep "*.exe |*exe]" | awk '{ print $1 }' > pstokill && kill $(cat pstokill) && rm processes && rm pstokill
2011-02-26 16:13:58
User: sxiii
Functions: awk cat egrep kill ps rm
Tags: kill wine exe
-4

This command kills all wine instances and each EXE application working on a PC.

Here is command info:

1) ps ax > processes = save process list to file named "processes" (we save it because we don't wont egrep to be found in the future)

2) cat processes | egrep "*.exe |*exe]" = shows the file "processes" and after greps for each *.exe and *exe] in it

3) | awk '{ print $1 }' > pstokill = saves processes PID's to file "pstokill" using awk filter

4) kill $(cat pstokill) = kills each PID in file pstokill, which is shown by cat program

5) rm processes && rm pstokill = removes temporary files

site="http://gifbin.com/"; for i in $(wget -qO- "$site"random| sed -r "s/^.*(bin\/.+\.gif).*$/\1/m" | grep "^bin"); do wget -c "$site$i"; filename=`basename $i`; [ `identify $filename | wc -l` -gt 1 ] || rm -f $filename; done
2011-02-15 10:05:37
User: az
Functions: grep rm sed wc wget
-2

Download a bunch of random animated gifs from http://gifbin.com/

ls > ls; paste ls ls > ren; nano ren; sed 's/^/mv /' ren|bash; rm ren ls
2011-02-08 17:07:13
User: romulusnr
Functions: ls paste rm sed
-2

Instead of tedious manual mv commands and tabbing, this routine creates a file listing all the filenames in the PWD twice, edit the second instance on each line to the new name, then save the file, the routine does the rest. Feel free to replace nano with your holy war editor of choice.

You will get a lot of "mv: 'x' and 'x' are the same file" warnings, these could be cleaned up but the routine works.

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|...))