1

I want to make my windows command prompt cmd+cygwin. I should be able to run both windows cmd commands and cygwin commands from my windows cmd prompt. If I add C:\cygwin64\bin to my PATH variable i can run some cygwin commands like ls and clear and some more through cmd prompt, but cygwin style paths don't work in this case.

D:\>cd /cygdrive/d
The system cannot find the path specified.

Is there a clean way to do this?

UPDATE: Based on suggestions I tried it in Powershell.

PS C:\GIT_Repo> ls -lrt
Get-ChildItem : A parameter cannot be found that matches parameter name 'lrt'.
At line:1 char:4
+ ls -lrt
+    ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

This command works in CMD prompt:

C:\GIT_Repo>ls -lrt
total 752
-rw-rw-r--+ 1 Ashish None    931 Jun 26 23:39  Mp3_Properties.py
-rwxrwxr-x+ 1 Ashish None 763247 Jun 26 23:44 'My_mp3_File.mp3'

Path don't work in Powershell too:

PS C:\GIT_Repo> cd /cygdrive/c
cd : Cannot find path 'C:\cygdrive\c' because it does not exist.
At line:1 char:1
+ cd /cygdrive/c
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\cygdrive\c:String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

Still no success.

  • 1
    The windows command prompt does not understand / in paths. Period. I would suggest trying a Powershell prompt instead. It does understand / in paths. Be careful though because it already has some aliases to mimic linux commands with powershell cmdlets (ls -> Get-ChildItem). Overall though, it is a better choice than cmd. – EBGreen Jul 13 '18 at 14:44
  • So as I stated, Some commands will already have an alias in powershell. ls is even the example I literally used. As stated in the answer, Windows and Linux have different file structures. Really, if you want a bash experience just stay in cygwin. What is your ultimate goal? What are you trying to accomplish by not using the shell in cygwin? – EBGreen Jul 13 '18 at 16:25
  • I think we can't make windows cmd prompt cmd+cygwin, cygwin is a software which gives us some UNIX like functionality if used from its own cygwin terminal. If anyone is able to achieve it do post your answers. – Ashish Shirodkar Jul 13 '18 at 16:47
  • I am well aware of what cygwin is. I'm just wondering why you want to try to do bash style commands/activities in a windows specific shell? If you want a bash experience stay in the cygwin terminal. – EBGreen Jul 13 '18 at 16:50
3

Answer is YES. I was able to do it with suggestions from @Nathan.Eilisha Shiraini

Following care should be taken:

1=> Add C:\cygwin64\bin to your PATH variable.

2=> All /cygdrive/c paths should be replaced with c:/

C:\>cd C:/Software_Development/Examples
C:\Software_Development\Examples>
C:\Software_Development\CPP>cd ../Examples
C:\Software_Development\Examples>

3=> All the third party softwares should be used from windows installations and not from cygwin.(perl,python etc.). Because cygwin supplied softwares use /cygdrive/c style paths. Cygwin should be used as driver which will trigger windows installed software.

4=> Executables should be executed in windows style ./Executable.o will not work.

C:\Software_Development\CPP>g++ MyTest.cpp -o MyTest.o
C:\Software_Development\CPP>ls
MyTest.cpp -o MyTest.o 
C:\Software_Development\CPP>MyTest.o
This program is compiled on windows

5=> All cygwin linux like commands return paths in /cygdrive/c/ style you need to convert them to c:/ wherever necessary.

C:\Software_Development\Examples>which python
/cygdrive/c/Python/Python36/python

Some more commands:

C:\Software_Development\CPP>cat MyTest.cpp
#include<iostream>

using namespace std;

int main()
{
        cout << "This program is compiled on windows";
        return 0;
}


C:\Software_Development\CPP>rm MyTest.cpp

C:\Software_Development\CPP>

Important to note here is all cygwin software will give you path in /cygdrive/c form which you need to convert them as c:/

0

TL;DR, no.

The way a file system is organized is extremely different between Windows and Linux, and it does not limit itself to using back- or forward slashes. For instance, only Windows is organized in drives, Linux only has its root directory.

Some Windows commands allow the use of forward slashes in paths, but most use them as the flag prefix (e.g. ping -t is equivalent to ping /t under Windows).


EDIT As suggested by EBGreen in their comment, you can try to use Powershell. I know by experience that it is slightly interoperable with Bash, as long as you don't do anything fancy (or anything at all). You can't do command chaining/piping, file redirections, strings with escaped characters, variables, and the list goes on...

  • I don't know about using cygwin commands in powershell, but powershell most definitely does support piping, file redirections, strings with escaped characters, and variables. – EBGreen Jul 13 '18 at 14:53
  • @EBGreen It does... just not with the same syntax as Bash. – Nathan.Eilisha Shiraini Jul 13 '18 at 14:54
  • @EBGreen For instance, a newline in bash is \n. In Powershell, it's `` `n``. – Nathan.Eilisha Shiraini Jul 13 '18 at 14:56
  • That is a windows vs. Linux issue not Powershell vs. Bash. The pipe character is the same for both. With the exception that Powershell pipes objects and Bash pipes strings, the concept of how the pipe works is the same for both. The redirection characters are the same and work the same. It is true that the escape character is different between the two but both of them support escaping characters in strings. Both have variables. Basically if you want the most bash-like experience, stay in cygwin. Neither cmd nor Powershell will give you as close an experience to bash as it will. – EBGreen Jul 13 '18 at 15:01
  • 1
    @AshishShirodkar Even though you can use forward slashes in Powershell paths, they remain Windows paths. That means there is no / directory, and instead of /cygdrive/c you should use c:/ like you would with backslashes. – Nathan.Eilisha Shiraini Jul 14 '18 at 11:35
0

Of course it is possible.

As of cygwin version 2.11.0. launched in 2018

When execution of linux command is necessary through windows default Command Prompt simply change the directory to C:\cygwin\bin> (if cygwin is installed on C:) whereas windows user level command line directory remains unchanged.

For example:

After installing cygwin, in windows command prompt as a user you shall execute all windows command like

C:\Users\My Username> where /r C:\\Users\pictures myimage.png

On the other hand you shall execute all linux command at

C:\cygwin\bin>

If you install cygwin at C:/cygwin, to change the command line directory from C:\Users\My Username> to C:\cygwin\bin> simply use windows cd command in command prompt like,

C:\Users\My Username> cd C:/cygwin/bin

and run linux command like,

C:\cygwin\bin> find C:/Users/pictures -name myimage.png

This way you can execute both windows commands in global scope and linux command in path scope from windows default terminal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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