"rm -i" alias equivalent on Cygwin/Windows Command Line

-2

I'm using Windows command prompt with Cygwin. Is it possible to define a bash like alias i.e. alias rm='rm -i' to prevent accidental damage from rm command? (Other than using doskey)

Update : All the wise downvoters, please read carefully despite the question being concise, I "want" to use Windows command prompt, not bash etc. & I want to use Cygwin commands with it.

user

Posted 2013-03-13T15:11:14.693

Reputation: 949

If you are using Cygwin, you can define that alias exactly as you describe it, because in Cygwin you can use (and this is the default) bash?! Am I missing some point? – mpy – 2013-03-13T17:02:01.793

@mpy : I want to use Windows prompt for certain reason, not bash terminal. – user – 2013-03-13T18:06:32.010

"I want to use Windows prompt" -- that is absolutely not clear from your question. The Windows command line interpreter cmd has nothing to do with cygwin. – mpy – 2013-03-13T18:10:16.390

First line of my question says "I'm using Windows command prompt with Cygwin". Cygwin is there for the "rm/cp/mv" commands & more – user – 2013-03-13T18:11:15.193

Answers

1

If you don't want to use doskey, you can create a batch file named rm.bat with the following content

C:\cygwin\bin\rm.exe -i %*

Change the cygwin path above according to your environment, then put rm.bat under %SystemRoot%\system32\ or any path in %PATH% environment variable.

This solution will make rm survived after a reboot.

Example

C:\>rm AUTOEXEC.BAT CONFIG.SYS

C:\>c:\cygwin\bin\rm -i AUTOEXEC.BAT CONFIG.SYS
/usr/bin/rm: remove regular empty file `AUTOEXEC.BAT'? n
/usr/bin/rm: remove regular empty file `CONFIG.SYS'? n

You can suppress command echoing by insert @ in front of the command line: @C:\cygwin\bin\rm.exe -i %*.

LiuYan 刘研

Posted 2013-03-13T15:11:14.693

Reputation: 1 929

-1

The equivalent of a bash alias in a GNU/Linux environment is the exact same bash alias in Cygwin environment. This would not apply if the alias involved a command that interacts with the kernel, which are generally not present in Cygwin.


The Cygwin command prompt in Windows runs bash. Your question title is confusing because it asks for aliases in Cygwin (I changed it). The way to define aliases in the native windows shell (cmd) is doskeys, and the equivalent argument of rm -i (interactive) for the windows del command is /P (prompt for confirmation).

So you could use:

doskey rm=del /P $* 

or

doskey rm=C:\cygwin\bin\rm.exe -i $*

Why is that not satisfactory? What are the benefits of using something other than doskey?

Ярослав Рахматуллин

Posted 2013-03-13T15:11:14.693

Reputation: 9 076

I want to use Windows command prompt ... how will bash alias work in it? Where do I specify it? – user – 2013-03-13T18:08:23.180

Don't mean to be rude, but you need to learn to read the question carefully. I specifically wanted a solution that can turn Cygwin "rm" to "rm -i" without using doskey. My question title isn't confusing, you are trying to mold it to what you know. – user – 2013-03-14T08:23:35.657

What is "Cygwin/Windows Command Line"? There is either Cygwin bash (or other shell) and there is Windows cmd or PowerShell. "Using the windows command prompt with Cygwin" is ambiguous. The most natural iterp. is that you are running a Cygwin shell in the windows cmd-terminal as opposed to running a Cygwin shell in urxvt or mintty. Your question is confusing. There is no reason not to use doskeys (you give none), so the whole basis of your question is personal whim and uninteresting - to me. I don't mean to bait you, but try using slashes to your advantage and writing precise questions. – Ярослав Рахматуллин – 2013-03-14T12:43:43.890