Andrew
Andrew

Reputation: 12412

How to navigate to a directory in C:\ with Cygwin?

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?

Upvotes: 434

Views: 518292

Answers (13)

Praveen Kishor
Praveen Kishor

Reputation: 2523

You can just use

cd C:/Users/../..

Upvotes: 13

wwei23
wwei23

Reputation: 11

$cd C:\

> (Press enter when you see this line)

You are now in the C drive.

Upvotes: 1

John Tribe
John Tribe

Reputation: 1622

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

Upvotes: 1

not2qubit
not2qubit

Reputation: 16912

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.

Upvotes: 0

karoberts
karoberts

Reputation: 9938

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.

Upvotes: 213

KoenigGunther
KoenigGunther

Reputation: 130

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.

Upvotes: 0

Paco Zarate
Paco Zarate

Reputation: 1995

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)

Upvotes: 3

Ellis
Ellis

Reputation: 429

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

Upvotes: 6

tionne jones
tionne jones

Reputation: 133

you can try this

/cygdrive/c/directoryname

Upvotes: 1

BenValjean
BenValjean

Reputation: 407

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

Upvotes: 2

netawater
netawater

Reputation: 15844

cd c: is supported now in cygwin

Upvotes: 142

Mark Byers
Mark Byers

Reputation: 837926

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.

Upvotes: 55

Otávio Décio
Otávio Décio

Reputation: 74250

Use:

cd /cygdrive/c

Upvotes: 839

Related Questions