LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 07: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, 07:49 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
What is the question? it just appears that 'rm' has an alias for "rm -i".
 
Old 01-10-2014, 07: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, 07:59 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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 08:11 AM.
 
1 members found this post helpful.
Old 01-10-2014, 02: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, 02:38 PM   #6
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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, 02: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, 03:37 PM   #8
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
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 03:41 PM.
 
Old 01-10-2014, 03:45 PM   #9
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
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, 04: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 04:22 PM.
 
Old 01-10-2014, 04:49 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 02: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, 04:04 AM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
.bashrc is not read dynamically, you'd have to logout & back in again to clear it from memory.
 
Old 01-13-2014, 04: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, 12:07 PM   #15
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian Stable and Unstable
Posts: 1,943

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


Reply



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 10:22 AM
Command/Script required to send an email alert in case command will not respond rajaniyer123 Linux - General 1 05-19-2012 01:12 PM
Executing shell command from JSP file with command line arg from URL orcusomega Programming 2 01-13-2012 03:38 PM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 11:21 AM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 06:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01: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
Open Source Consulting | Domain Registration