LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-10-2014, 08:40 AM   #1
a.abdulna
Member
 
Registered: Feb 2013
Location: Bangalore
Distribution: Rhel
Posts: 86

Rep: Reputation: Disabled
command rm -rf


Hello Team,

I need your help for whenever user trying to use rm -rf command system need to confirm like below.

# rm -rf text.txt
Are you sure [Y/n]

Please let me know if anyone knows this.

B. R.
Abdul
 
Old 01-10-2014, 08:49 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
What is the question? it just appears that 'rm' has an alias for "rm -i".
 
Old 01-10-2014, 08:51 AM   #3
a.abdulna
Member
 
Registered: Feb 2013
Location: Bangalore
Distribution: Rhel
Posts: 86

Original Poster
Rep: Reputation: Disabled
Yes, while trying 'rm' system asking confirmation but doing forcefully remove like 'rm -rf' we need confirmation by system like below.

# rm -rf text.txt
Are you sure [Y/n]
 
Old 01-10-2014, 08:59 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
The -f option overrides the -i option.

Solution is simple: Don't use the -f option.

BTW: The -r option, in your example, is also not needed. You remove a specific file, using -r (recursive) is pointless.

Last edited by druuna; 01-10-2014 at 09:11 AM.
 
1 members found this post helpful.
Old 01-10-2014, 03:38 PM   #5
zcarlile
LQ Newbie
 
Registered: Dec 2013
Location: Longview tx
Posts: 5

Rep: Reputation: Disabled
It is should use a simple rm -i file will kick off the interaction.
 
Old 01-10-2014, 03:38 PM   #6
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Quote:
Originally Posted by jpollard View Post
What is the question? it just appears that 'rm' has an alias for "rm -i".
to verify this just type alias at your $ prompt. this sounds like a RH or a fork there of system. RH has the -i set for several options, rm is one of them.
 
Old 01-10-2014, 03:46 PM   #7
Smokey_justme
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 534

Rep: Reputation: 203Reputation: 203Reputation: 203
Like jpollard said, you have an alias created that forces rm to execute 'rm -i' or 'rm -I' (where -i comes from interactive)

You can do 'rm -rf --interactive=never text.txt' to suppress the confirmation or reset the alias (search for it in ~/.bashrc or add 'unalias rm' to ~/.bashrc)

However, be very careful when using -rf options.. Don't use them if you really, really don't have to..
 
Old 01-10-2014, 04:37 PM   #8
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,818

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
so !!!!
what is the problem

it is a SAFETY measure
are you REALLY 100% SURE !!! that you want to do something that is NOT UNDOABLE
you can NOT go back and undo this so it is asking are YOU SURE !!!

and you really DO NOT !!!! want to remove that alias
it is there to PROTECT YOU !!!! FROM A TYPO !!!!

without it you can do this and REALLY FUBAR your install
Code:
su -
rm -rf / home/me/testfile.txt
see that blank space before home !!!!!!!!!!!!!!

Last edited by John VV; 01-10-2014 at 04:41 PM.
 
Old 01-10-2014, 04:45 PM   #9
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998
Quote:
Originally Posted by a.abdulna View Post
Hello Team,

I need your help for whenever user trying to use rm -rf command system need to confirm like below.

# rm -rf text.txt
Are you sure [Y/n]

Please let me know if anyone knows this.

B. R.
Abdul
I think I read this differently than others.

To me it seems that you are saying that it does NOT offer the confirmation, and you are saying that "system need to confirm like below".

If that is the case then do not use the -f option. The -f option explicitly tells it to NOT confirm. If you want it to confirm anyway, even with -f you can alias rm -rf to rm -ri.
 
Old 01-10-2014, 05:21 PM   #10
Smokey_justme
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 534

Rep: Reputation: 203Reputation: 203Reputation: 203
Ohhh.. Yes, astrogeek, I think you're right about what he meant..

But it is possible.. -f and -i/-I contradict each other but no one superseeds the other.. So, if -I is the last argument, -f will be canceled

Put this in the users ~/bashrc (or system wide alternative) .. This will work even if rm is already aliased..

Code:
function rm {
   /usr/bin/rm $@ -I
}
This will always print a prompt if more then 3 files are to be deleted or if recursion will be used..

Last edited by Smokey_justme; 01-10-2014 at 05:22 PM.
 
Old 01-10-2014, 05:49 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
It means rm has been aliased to 'rm -i'. You can just specify the actual cmd
Code:
alias r='rm -i'

r t.t
rm: remove regular empty file `t.t'? 
.
.
which rm
/bin/rm
/bin/rm t.t
Note that in the 2nd case it doesn't ask for confirmation ...


The alias may be in the user's .bashrc, or it may be in one of the global files /etc/bashrc.
Personally I always remove the alias; I've been doing this a loonngg time and it just gets in the way. Of course it does mean I have to be careful aka use at your own risk.
 
Old 01-13-2014, 03:27 AM   #12
a.abdulna
Member
 
Registered: Feb 2013
Location: Bangalore
Distribution: Rhel
Posts: 86

Original Poster
Rep: Reputation: Disabled
Hello Smokey_justme,

i have tried below command in .bashrc and its working fine but after removing the same from .bashrc again its asking confirmation, so how to revert old level.

function rm {
/usr/bin/rm $@ -I
}



B.R.
Abdul
 
Old 01-13-2014, 05:04 AM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
.bashrc is not read dynamically, you'd have to logout & back in again to clear it from memory.
 
Old 01-13-2014, 05:09 AM   #14
a.abdulna
Member
 
Registered: Feb 2013
Location: Bangalore
Distribution: Rhel
Posts: 86

Original Poster
Rep: Reputation: Disabled
Thank you Chris,

its fine now.. Dear All thanks for ur valuable suggestions.

B.R.
Abdul.
 
Old 01-13-2014, 01:07 PM   #15
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian
Posts: 1,054

Rep: Reputation: 276Reputation: 276Reputation: 276
Or instead of logging out, just use
Code:
source .bashrc
. That forces bash to reread .bashrc.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cygwin simple tar command fails when issues on command line deannad Linux - General 1 06-12-2013 11:22 AM
Command/Script required to send an email alert in case command will not respond rajaniyer123 Linux - General 1 05-19-2012 02:12 PM
Executing shell command from JSP file with command line arg from URL orcusomega Programming 2 01-13-2012 04:38 PM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 12:21 PM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 07:30 PM


All times are GMT -5. The time now is 10:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration