I dont see this resolved as rm -if prefers -i over -f and asks for user confirmation while when i try to do the same thing by setting alias rm='rm -i' and then rm -f then it does not prefer -i over -f and does not ask for user confirmation which is strange / unexplained.
I take your word that -i and -f should not be used together but if used together why would the behaviour of what is being prefered change when using and not using aliases ?
Note: i m using single qoutes for setting alias and not double quotes. Could that be a problem ?
I will need another 8 hrs before i can paste the output from the terminal. But like i said you can test this issue yrself by registering and loggin to the online terminal -> Join
I can't confirm this claim; tested on Linux and FreeBSD - no confirmation if -f is present, neither when using the alias nor stating the -i explicitly.
---------- Post updated at 14:52 ---------- Previous update was at 14:50 ----------
According to the standards, if rm is invoked with both -i and -f , the last one of those two options specified takes effect and the other option will be ignored. So:
rm -if other_options operands
should be treated exactly the same as:
rm -f other_options operands
and:
rm -fi other_options operands
and:
rm -f -i -f -ififif -i other_options operands
should be treated exactly the same as:
rm -i other_options operands
One of the reasons the standards require this is to allow a user to override one of these options set by an alias by just adding the desired option as an option when the alias is invoked.
I make no claims as to whether or not the version of rm you are using conforms to the standards.
I have final question after learning how flags work.
i m on Linux fedori 2.6.35.14 GNU/Linux
So, i can confirm that on my OS that which ever flag come later takes precedence. So
rm -fi works and asks for confirmation rm -if does not work and force deletes the file.
Now when i set alias rm='rm -i' and then try rm -f it does not ask for confirmation and force deletes the file; meaning it populates the final command as rm -if
Do you know of any trick by which i can force interactive -i flag to kick in by setting it in the alias ? Somehow please ?
No. An alias cannot override what follows it on the command line.
You could write a replacement script for rm and install it in your PATH before the standard rm and have it examine its arguments and insert a -i before the first operand and then invoke the standard rm utility. But, if someone using your alias explicitly asks for -f to be used, why do you want to override that???
Sorry, i did not get what you are trying to say here.
My question is that irrespective to the order of -i or -f flags the rm should always prefer -i and ask for confirmation. Can i somehow enforce this to happen ? Yes or No ? If Yes, How ?
No. And, there is no logical reason to want to do so.
Why do you think it is important to override a user not wanting the output produced by -i when that user explicitly asks for the behavior afforded by -f ?
If this is for an alias you are defining for your own use, why does it matter? Just don't type -f when you use the alias if you don't want to use -f ! If this is an alias you are creating for others to use, DO NOT ATTEMPT to thwart a user's attempt to get the behavior they need for the job they are doing.
@Cragun: We have naive users who are given access to our servers. They do not understand the significance of -f option and due to overlook they may specify a folder instead of a file becoz they overlooked the space charecter in the path to the file making it a folder path.
rm -irf /tmp/hello /output/bob.txt
This will accidentally delete the folder "hello" instead of the file "bob.txt" as they copy paste these path from word documents or emails.
So if i can impose the -i option for others as we use the same id they will be prompted and thus they can correct their mistake rather than the -f option doing the damage.
Your suggestions please... to my concern ?
Also, i was wondering where the same behavior of a later flag over riding the behavior of the previous flag could be tested.
I tried grep "Sunday" -wi hello.txt and grep "Sunday" -iw hello.txt but i get the same output where as grep "Sunday" -w hello.txt and grep "Sunday" -i hello.txt yields different results.
Can you tell me other commands and the flags that override each others behavior like the -i and -f flag over rides each other in case of rm command.