Interactive & safe removal

In windows when we want to delete a file or something else we were asked before delete.Thats a very useful thing bcoz we again ensure whether we delete it or not.

In linux when we want to delete a file or directory we use rm command.

and the two common switches we use

-r remove directories and their contents recursively(used when we want to delete directory)

-f for force delete (used for file and directory)

But the problem is when we execute a command like

$ rm -r docs (it will delete all the contents of docs without prompt but after delete you think that you need a file there)

$ rm * (what will happen suppose you want to delete all files under /home/david/docs but your pwd is /home/david now and b4 runinng rm cmd you forgot to check your pwd)

So two things you must check b4 delete

1.)Your current working directory (run pwd command)

2.) before delete one thing you must ensure that what exactly you want to delete it (run rm with -i option)

Now what is advantage of -i, suppose u didn’t check your pwd but you used rm -i then at least u will got a prompt asking you the file name either you want to delete or not.

N.B. A very few linux distribution (may be RedHat or Fedora) by default give a prompt when you run rm command.But this article for those distribution where prompt is not given.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: