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



Protect directory from an overzealous rm -rf *

Terminal - Protect directory from an overzealous rm -rf *
cd <directory>; touch ./-i
2011-05-12 11:01:58
User: ljmhk
Functions: cd touch
Protect directory from an overzealous rm -rf *

Forces the -i flag on the rm command when using a wildcard delete.


There are 4 alternatives - vote for the best!

Terminal - Alternatives
sudo chattr -R +i dirname
2011-05-17 05:05:49
User: mamue
Functions: chattr sudo
Tags: touch

-R Recursively change attributes of directories and their contents.

+i to set the immutable bit to prevent even root from erasing or changing the contents of a file.

Know a better way?

If you can do better, submit your command here.

What others think


Comment by kaedenn 247 weeks and 3 days ago


But why should you change directory? Just do the:

touch /path/-i
Comment by netizen 247 weeks and 2 days ago

I'm constantly tripping over the 'alias rm="rm -i"' that gets forced on me with Fedora/Debian Linux distros. I like this idea for a per-directory molly-guard.

Comment by Mozai 247 weeks and 2 days ago

Unfortunately it doesn't save from

rm -fr ./*

or when deleting parent dirs:

touch ./path/-i rm -fr *
Comment by aikikode 247 weeks and 2 days ago

Very interesting but doesn't seem to work here on a Mac nor a CentOS 5.3 machine using bash 3.2

david@host /tmp $

cd a

david@host /tmp/a $

mkdir ta tb tc

david@host /tmp/a $

touch ta/-i

david@host /tmp/a $

rm -rf *

david@host /tmp/a $


david@host /tmp/a $

Comment by DaveQB 247 weeks and 2 days ago

DaveQB ... did you read aikikode's comment?

Works fine for me on Mac OSX.

Comment by unixmonkey21519 247 weeks and 2 days ago

My vote is up, but still it will not protect against rm -rf -- *

Nice thinking though.

Comment by RanyAlbeg 247 weeks and 2 days ago

safe-rm (http://www.safe-rm.org.nz) is another way of preventing accidental deletions through a blacklist of paths you don't want to delete (e.g. /bin, /usr/lib or ~/important_file.gpg)

Comment by fmarier 247 weeks and 2 days ago

fmarier, that looks interesting I'll take a look. oh and thanks for the up votes guys, its not perfect but handy when training the junior sys admins.

Comment by ljmhk 247 weeks and 2 days ago

If you really want to protect files from being deleted or change, even by root,

use the chattr command:

chattr +i


Only works on ext2 systems.

Comment by laebshade 247 weeks and 1 day ago

@unixmonkey21519 aikikode Must have posted seconds before me as I did not see it just before or I posted (or even after actually)

Comment by DaveQB 246 weeks and 6 days ago

Your point of view

You must be signed in to comment.