427

I'm trying to install PyQt4 so I can mess around with it. The installation guide said I had to install Sip. The last step to installing Sip is to use the make install command. Windows doesn't have that, so I looked it up and everything I saw said to install Cygwin. So I did. But...sip is in C:\Python31\sip.

Can I run this from the Cygwin command? If so, how would I do that?

Or can I run this from the normal windows command prompt? If so, how would I go about that?

Lii
  • 11,553
  • 8
  • 64
  • 88
Andrew
  • 12,172
  • 16
  • 46
  • 61

13 Answers13

825

Use:

cd /cygdrive/c
Otávio Décio
  • 73,752
  • 17
  • 161
  • 228
213

I'll add something that helps me out a lot with cygwin. Whenever setting up a new system, I always do this

ln -s /cygdrive/c /c

This creates a symbolic link to /cygdrive/c with a new file called /c (in the home directory)

Then you can do this in your shell

cd /c/Foo
cd /c/

Very handy.

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
karoberts
  • 9,828
  • 4
  • 39
  • 39
  • 1
    Note that this prevents you from having files/directories named `c` with the ability of referencing them normally. – Raj Sep 30 '16 at 14:54
  • 1
    I recently installed MSYS2 and this was the default behavior, with `/cygdrive` in-fact not working... – itsmejoeeey Sep 20 '17 at 01:11
142

cd c: is supported now in cygwin

p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
netawater
  • 15,214
  • 4
  • 24
  • 21
54

You already accepted an answer, but I just thought I'd mention that the following also works in Cygwin:

cd "C:\Foo"

I think the cd /cygdrive/c method is better, but sometimes it's useful to know that you can do this too.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
12

You can just use

cd C:/Users/../..
Pang
  • 9,564
  • 146
  • 81
  • 122
Praveen Kishor
  • 2,413
  • 1
  • 23
  • 28
6

As you'll probably want to do this often, add aliases into your .bashrc file, like:

alias cdc='cd /cygdrive/c'
alias cdp='cd /cygdrive/p'

Then you can just type on the command line:

cdc
Ellis
  • 395
  • 3
  • 8
3

Define a variable in .bashrc :

export C=/cygdrive/c

then you can use

cd $C/

and the tab autocompletes correctly (please include the / at the end)

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
Paco Zarate
  • 1,925
  • 1
  • 15
  • 13
2

On a related note, you may also like:

shopt -s autocd

This allows you to cd a dir by just typing in the dir

[user@host ~]$ /cygdrive/d
cd /cygdrive/d
[user@host /cygdrive/d]$ 

To make is persistent you should add it to your ~/.bashrc

1

you can try this

/cygdrive/c/directoryname
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
tionne jones
  • 133
  • 1
  • 5
1

The one I like is: cd C:

To have linux like feel then do:

ln -s /cygdrive/c/folder ~/folder

and use this like: ~/folder/..

John Tribe
  • 1,407
  • 14
  • 26
1

$cd C:\

> (Press enter when you see this line)

You are now in the C drive.

wwei23
  • 11
  • 1
0

Create a file named "overrideBashCdForWindowsPaths" in your HOME folder. Paste the following lines into that file and save it:

#!/bin/bash

function cd() {
    CD_PATH="$(history | tail -1 | sed -e "s,.*${FUNCNAME[0]}\s*,,g")"

    if [ -z "${CD_PATH}" -o "${CD_PATH}" = "~" ]; then
        CD_PATH="${HOME}"
    fi

    builtin cd "$(cygpath "$CD_PATH")"
}

Next, type the following command in a terminal, while you are in your HOME folder:

echo ". overrideBashCdForWindowsPaths" >> .bashrc

Close your terminal and open a new one. You can now easily change into that Windows folder by simply typing

cd C:\Python31\sip

The script reads the last command, extracts the path and passes it to Cygwin's path-conversion tool. By naming the function "cd" we sort of 'override' Bash's builtin "cd" and delegate the actual call to it in the very last line.

KoenigGunther
  • 130
  • 1
  • 8
  • Thanks @KoenigGunther, it works! But a little bit slow though for changing directory. Is there a way to make it faster just like using quote? e.g. `cd "C:\Python31\sip"` –  Jan 22 '20 at 23:33
0

Something that is worth mentioning here is that Cygwin's cygpath, still does not handle spaced Windows paths properly, especially in Bash scripts running under Cygwin. The trick is to understand how Cygwin interprets quotes in Bash scripts.

The following does not work:

#!/bin/bash
TBDIR="/cygdrive/c/Program\ Files\ \(x86\)/MyDir/"

if [ -d "${TBDIR}" ]; then 
    echo "Found MyDir directory at: ${TBDIR}"
    cd "$TBDIR"
else 
    echo "MyDir program directory not found!"
    echo "Wrong DIR path: ${TBDIR}"
    exit 1
fi

But this does work:

#!/bin/bash
# Cygwin-ism: No quotes!
TBDIR=/cygdrive/c/Program\ Files\ \(x86\)/MyDir/

if [ -d "${TBDIR}" ]; then 
...

As far as I know, there is currently no known workaround using cygpath, that can properly handle spaces in the bash scripting context but you can use quotes in your scripts.

Florian
  • 24,425
  • 4
  • 49
  • 80
not2qubit
  • 14,531
  • 8
  • 95
  • 135