Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/…;. – alpert 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 – Iancovici 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
@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
up vote 24 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 $?

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

For file

rm -f fileName
rm -rf Directory


rm -rf FolderName
share|improve this answer

Your Answer


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.