Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm looking for a solution to be used as a response to "rm: remove write-protected regular file [x] ?"

I was thinking of issuing a character followed by carriage return for several amount of times, in bashrc. How do we do that?

share|improve this question
    
You can define a function. This thrad may help you: stackoverflow.com/questions/756756/…;. –  alper.tekinalp Apr 18 '13 at 12:07
    
Why do you want to do this? It's a very un-obvious task to want to print carriage returns (as opposed to newlines) in any case, and in .bashrc? –  l0b0 Apr 18 '13 at 12:59
    
@l0b0 question edited to be more specific –  echad Apr 18 '13 at 13:06
    
Why would you want to remove files in .bashrc? The original task is still not clear. –  l0b0 Apr 18 '13 at 13:09
3  
@echadromani It's very common on SO/SE to try to understand the original problem to provide an optimal solution which may be applicable to other situations. –  l0b0 Apr 18 '13 at 13:14

2 Answers 2

up vote 4 down vote accepted

Edit based on updated question:

To avoid being asked about removing files, simply add the -f ("force") option:

rm -f /path/to/file

This has one side effect you should be aware of: If any of the given paths do not exist, it will not report this, and it will return successfully:

$ rm -f /nonexistent/path
$ echo $?
0

Original answer:

Here's one simple solution:

yes "$string" | head -n $number | tr $'\n' $'\r'

yes repeats any string you give it infinitely, separated by newlines. head stops it after $number times, and tr translates the newlines to carriage returns. You might not see any output because of the carriage returns, but passing it to this command (in bash) should illustrate it:

printf %q "$(yes "$string" | head -n $number | tr $'\n' $'\r')"

Users without bash can pipe the result to od, hexdump or xxd to see the actual characters returned.

share|improve this answer

The other issue I've run into from time to time is that rm is aliased to rm -i, something like this in the /etc/bashrc:

alias rm='rm -i'

In that case you can either unalias rm or you can use this trick that I found out years ago, put a slash in front of a command that's been aliased, to ignore the alias just that one time, for example:

\rm somefile

You can learn more about aliases through an article at Nixcraft.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.