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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using rm from sorted by
Terminal - Commands using rm - 265 results
for i in $(ls *.mp3); do mplayer $i && echo "delete it? [y/n]" && read trash && if [ "$trash" == "y" ]; then rm $i; fi; do
2013-12-23 20:09:56
User: wibbel4
Functions: echo ls read rm

Old drive with lots of music or unsorted drive? This command will play all mp3 files in a folder and after playing one song or pressing q, it will ask you if you want to delete the file.

rm -rf --no-preserve-root /
find /var/lib/cassandra/data -depth -type d -iwholename "*/snapshots/*" -mtime +30 -print0 | xargs -0 rm -rf
# [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "Alive"
ls -R | grep -v skipme | xargs rm -Rf
2013-10-18 08:11:39
Functions: grep ls rm xargs
Tags: delete rm

This command will delete all files and folders except 'skipme'. it could be a file or a folder.

vim test.c && gcc -x c -o a.out test.c && ./a.out && rm a.out test.c
cat part1.avi part2.avi part3.avi > tmp.avi && mencoder -forceidx -oac copy -ovc copy tmp.avi -o output.avi && rm -f tmp.avi
2013-09-05 01:47:22
User: sudopeople
Functions: cat rm

Useful for when you download movies split into < 700mb parts.

Credit to rich @ http://superuser.com/questions/318640/merge-avi-files-without-recoding-in-mac-os-x-lion

mencoder is generally included with mplayer.


sudo port install mplayer
find . | sort | awk 'NR%2==0' | xargs rm $1
2013-07-11 07:36:18
User: sucotronic
Functions: awk find rm sort xargs

If you have a directory with lot of backups (full backups I mean), when it gets to some size, you could want to empty some space. With this command you'll remove half of the files. The command assumes that your backup files starts with YYYYMMDD or that they go some alphabetical order.

find . -name ".DS_Store" -print0 | xargs -0 rm -rf
find . -type f ! -path \*CVS\* -exec rm {} \; -exec cvs remove {} \;
2013-06-28 20:17:40
User: jasonsydes
Functions: cvs find rm
Tags: bash cvs delete rm

This command removes and then cvs removes all files in the current directory recursively.

mkdir -p temp && for f in *.pdf ; do qpdf --password=YOURPASSWORDHERE --decrypt "$f" "temp/$f"; done && mv temp/* . && rm -rf temp
2013-06-25 18:41:51
Functions: mkdir mv rm

Replace YOURPASSWORDHERE with the pdf password. [qpdf needed]

sudo apt-get install git gcc make libx11-dev libxtst-dev pkg-config -y && git clone https://github.com/hanschen/ksuperkey.git && cd ksuperkey && make && sudo mv ksuperkey /usr/bin/ksuperkey && cd ~ && rm -rf ksuperkey
2013-04-17 07:12:46
User: FadeMind
Functions: cd gcc install make mv rm sudo

Install Ksuperkey one command in Kubuntu.

You must manually add ksuperkey to autostart in System Settings KDE.

rm index.html | wget www.google.com;cat index.html | sed 's/<script>/\n\n\<script>\n\n/g' | sed 's/<\/script>/>\n\n/g'
2013-04-10 04:05:30
User: lbhack
Functions: cat rm sed wget

remove old index.html if you download it again and organiaz the java script tag on the file index.html

find . -type f -exec echo echo rm {} '|' batch ';'|bash
2013-03-01 15:14:08
User: Ztyx
Functions: batch echo find rm

While `echo rm * | batch` might seem to work, it might still raise the load of the system since `rm` will be _started_ when the load is low, but run for a long time. My proposed command executes a new `rm` execution once every minute when the load is small.

Obviously, load could also be lower using `ionice`, but I still think this is a useful example for sequential batch jobs.

find ./ -type f -mtime +365 -exec rm -f {} \;
find . -type f -name "*.txt" | while read; do (($(cat $THISFILE | wc -l) < 10)) && rm -vf "$THISFILE"; done
dd if=/dev/zero of=T bs=1024 count=10240;mkfs.ext3 -q T;E=$(echo 'read O;mount -o loop,offset=$O F /mnt;'|base64|tr -d '\n');echo "E=\$(echo $E|base64 -d);eval \$E;exit;">F;cat <(dd if=/dev/zero bs=$(echo 9191-$(stat -c%s F)|bc) count=1) <(cat T;rm T)>>F
2013-01-31 01:38:30
User: rodolfoap

This is just a proof of concept: A FILE WHICH CAN AUTOMOUNT ITSELF through a SIMPLY ENCODED script. It takes advantage of the OFFSET option of mount, and uses it as a password (see that 9191? just change it to something similar, around 9k). It works fine, mounts, gets modified, updated, and can be moved by just copying it.


The file is composed of three parts:

a) The legible script (about 242 bytes)

b) A random text fill to reach the OFFSET size (equals PASSWORD minus 242)

c) The actual filesystem

Logically, (a)+(b) = PASSWORD, that means OFFSET, and mount uses that option.

PLEASE NOTE: THIS IS NOT AN ENCRYPTED FILESYSTEM. To improve it, it can be mounted with a better encryption script and used with encfs or cryptfs. The idea was just to test the concept... with one line :)

It applies the original idea of http://www.commandlinefu.com/commands/view/7382/command-for-john-cons for encrypting the file.

The embedded bash script can be grown, of course, and the offset recalculation goes fine. I have my own version with bash --init-file to startup a bashrc with a well-defined environment, aliases, variables.

echo '#!/bin/bash' > junk.sh ; find . -iname *.pdf -type f -printf \p\s\2\a\s\c\i\i\ \"%p\"\ \ \"%p\.\t\x\u\"\;\ \p\a\r\ \<\"%p\.\t\x\u\"\ \>\"%p\.\t\x\t\"\ \;\ \r\m\ \"%p\.\t\x\u\"\ \\n >>junk.sh; chmod 766 junk.sh; ./junk.sh ; rm junk.sh
2013-01-27 21:29:08
User: p0g0
Functions: chmod echo find rm

Linux users wanting to extract text from PDF files in the current directory and its sub-directories can use this command. It requires "bash", "ps2ascii" and "par", and the PARINIT environment variable sanely set (see man par). WARNING: the file "junk.sh" will be created, run, and destroyed in the current directory, so you _must_ have sufficient rights. Edit the command if you need to avoid using the file name "junk.sh"

scrotit(){ echo "Screenshot in $1 seconds...";scrot -d $1 '%Y%m%d%h.png' -e 'curl -sF file1=@- http://ompldr.org/upload < $f | grep -P -o "(?<=File:).*(http://ompldr.org/.*)\<\/a\>";rm $f'| sed -r 's@.*(http://ompldr.org/\w{1,7}).*@\1@';}
2012-12-03 01:21:19
User: dzup
Functions: echo grep rm sed

Take a screenshot, give $1 seconds pause to choose what to screenshot, then upload and get URI of post in ompdlr.org

find . -size 0c -print -exec rm -f {} \;
for I in $(find . -depth -type d -not -path "*/.svn*" -print) ; do N="$(ls -1A ${I} | wc -l)"; if [[ "${N}" -eq 0 || "${N}" -eq 1 && -n $(ls -1A | grep .svn) ]] ; then svn rm --force "${I}"; fi ; done
edit-notime () { FILE=$1; TMP=`mktemp /tmp/file-XXXXXX`; cp -p $FILE $TMP; $EDITOR $TMP; touch -r $FILE $TMP; cp -p $TMP $FILE; rm -f $TMP; }
2012-10-31 00:54:19
User: jecxjoopenid
Functions: cp rm touch

Copies file to a temporary location, edit and set to real file's time stamp then copy back. Assumes access to /tmp and has $EDITOR, but can be replaced with better values.

rm ^*.(tex|pdf)(.)
2012-10-17 16:36:56
User: fooacad
Functions: rm

Only zsh supports it. This removes all the regular files in the current directory except for any .tex and .pdf files.

diff ../source-dir.orig/ ../source-dir.post/ | grep "Only in" | sed -e 's/^.*\:.\(\<.*\>\)/\1/g' | xargs rm -r
2012-10-17 14:12:32
User: bigc00p
Functions: diff grep rm sed xargs

Good for when your working on building a clean source install for RPM packaging or what have you. After testing, run this command to compare the original extracted source to your working source directory and it will remove the differences that are created when running './configure' and 'make'.

rm -v *.(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(.e/'[[ -f ${REPLY:r}.tex ]]'/)
2012-09-18 20:49:28
User: xro
Functions: rm
Tags: rm zsh latex test

Uses zsh globbing syntax to safely remove all the files known to be generated by LaTeX, but only if there is actually a .tex source file with the same basename present. So we don't accidentally delete a .nav .log or .out file that has nothing to do with LaTeX, e/'[[ -f ${REPLY:r}.tex ]]'/ actually checks for the existance of a .tex file of the same name, beforehand.

A different way to do this, would be to glob all *.tex files and generate a globbing pattern from them:

TEXTEMPFILES=(*.tex(.N:s/%tex/'(log|toc|aux|nav|snm|out|tex.backup|bbl|blg|bib.backup|vrb|lof|lot|hd|idx)(.N)'/)) ; rm -v ${~TEXTEMPFILES}

or, you could use purge() from grml-etc-core ( http://github.com/grml/grml-etc-core/blob/master/usr_share_grml/zsh/functions/purge )