RSS



Quicktip – How to get Linux to prompt before removing a file in the CLI

Tue, Jan 2, 2007

Linux, Quicktips, Ubuntu

Talk about it in our Forums

oops!
I help out a bunch of folks with Ubuntu machines who are not exactly Linux savvy but who are learning quick.

The most interesting and dangerous phase of this learning experience is when the start mucking about in the Command Line Interface (CLI). It’s exciting for them to suddenly feel powerful on their own computer. They can make sweeping changes with the tap of a few keys.
Sadly, they do this. A lot.

Before they really know what they’re doing. So I’ve implemented a few quick changes to their machines to always prompt before removing, copying or moving files.

When they know enough about their system, they can change it back. As you may have guessed, I’m not a paid admin to any of them. :)

Does this foolproof their systems? No, but it does add an extra layer of though (I hope) to their actions. One of my biggest problems with users is making changes to or removing key files without backing them up.
Here’s what you do. Fire up a CLI session yourself. We’re going to edit your bash.bashrc in the /etc directory to tell it to always prompt before removing a file. First, we’re going to back it up.

sudo cp /etc/bash.bashrc bash.bashrc.bak

Now let’s fire up gedit and make some changes.

gksudo gedit /etc/bash.bashrc

Skip down to the bottom of the file and add these three lines.

alias rm=’rm -i’

alias cp=’cp -i’

alias mv=’mv -i’

The -i switch will cause these programs to execute interactively. This means they’ll prompt before acting.

Popularity: 1% [?]

Share and Enjoy:
  • Digg
  • del.icio.us
  • MisterWong
  • Reddit
  • Technorati
  • BlinkList
  • Facebook
  • Fark
  • Mixx
  • Slashdot

This post was written by:

arsgeek - who has written 1989 posts on ArsGeek.


Contact the author

8 Comments For This Post

  1. Mike Says:

    Great tip.

    But how can I have linux to prompt me before deleting a file in the graphical environment (Nautilus)?

  2. arsgeek Says:

    Hey Mike,

    Well, you have two options in Nautilus.

    1. Send it to the trash. This way, it’s not gone until you empty your trash. You can go into Edit-> Preferences in any Nautilus window. Then go to the Behavior tab where you can control how Nautiuls handles warning you about both sending a file to the Trash, and then emptying the Trash.

    2. If you include a Delete command that bypasses the trash, you get no warning/prompt/bells/whistles. So use this with caution or uncheck it if it bothers you or is a danger to some users.

  3. floor jacks Says:

    I must say, that I can not agree with you in 100%, but that’s just my opinion, which could be wrong.
    p.s. You have an awesome template for your blog. Where did you find it?

  4. Ex zurueckgewinnen Says:

    Sau gut! Endlich mal jemand der meiner Meinung ist.

  5. Glendora Judie Says:

    I’d come to give the go-ahead with you here. Which is not something I typically do! I enjoy reading a post that will make people think. Also, thanks for allowing me to comment!

  6. Kristin Cavallari Says:

    Wow, It has been quite a while needed to take some notes on. Well another article that will work out just fine. I need something like this just finishing up, and it is on the same topic as this post. Glad, great share.

  7. Armanda Kilcrease Says:

    Useful post, this is. It is definitely great to see a post that is valuable.

  8. mortgage calculator Says:

    For the quarter ended June 30, 2009, the Company’s revenues were $22.6 million, an increase of 71.2% year-over-year from $13.2 million in 2Q2008.

1 Trackbacks For This Post

  1. Quicktip - How to get Linux to prompt before removing a file in the CLI : Tech Tips Says:

    [...] Quicktip – How to get Linux to prompt before removing a file in the CLI [...]

Leave a Reply