-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.

4
  • 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
    Mar 13, 2013 at 17:02
  • @mpy : I want to use Windows prompt for certain reason, not bash terminal.
    – user
    Mar 13, 2013 at 18:06
  • "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
    Mar 13, 2013 at 18:10
  • 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
    Mar 13, 2013 at 18:11

2 Answers 2

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 %*.

0
-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?

3
  • I want to use Windows command prompt ... how will bash alias work in it? Where do I specify it?
    – user
    Mar 13, 2013 at 18:08
  • 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
    Mar 14, 2013 at 8:23
  • 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. Mar 14, 2013 at 12:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .