How to change directory under git bash - windows

Could you tell me please how to change directory using git bash?
Exactly I want go to C:/Program Files
I type cd c:/ - move to c:/.
I type cd Program Files and I get message that "there is no such directory Program".
So the problem is how to go to the directory name of which consists of two words that are separated by whitespaces.
I'm using Windows 7 operating system.

cd gets just one argument, so if you say cd Program Files it does cd Program. So you need to quote Program Files if you want cd to it as just one argument:
cd "Program Files"
otherwise it is trying to find the directory Program.

You could also type the space as escape seqence:
cd /c/Program\ Files/Git/

Please find below to add windows path in git bash or in unix
export PATH=$PATH:/c/Program\ Files/Java/jdk1.8.0_221/bin:/c/Program\ Files/apache-maven-3.6.1/bin

Related

Change directory in bash script in windows

How can I change my working directory in bash script in windows. I have
~dp0 = C:\test\docker\windows and I want to change my directory to C:\test\build
So it means 2 levels up and then int o build folder
Thanks
Since C:\ is mounted by default into /mnt/c this will work.
Create a .bashrc in your home path by following command:
echo "BUILDDIR=/mnt/c/test/build" >> ~/.bashrc;source ~/.bashrc
cd $BUILDDIR
# Do your work below for example ./configure.
./configure
On my system in Git bash the C:\ root is just /c/ and other dirs from there are whatever they are, so it would be cd /c/test/build/.
You could also still say cd ../../build/.
Good luck.
To change the directory using a bash script is just like you would using normal bash.
cd "C:/test/build"
echo "You're now in the folder, do what you will."
Save the file as .sh and it can be used as such.
Note, when navigation your folders using a bash script remember the directory you'll be starting from is always the home directory.

Cannot change directory in psql on windows 10. PostgreSQL 11

I downloaded local PosgreSQL 11 on Windows 10.
I try to change directory in psql on command line window to c:\Program Files\PostgreSQL\11\bin>
I get either invalid command or directory does not exist
I tried following with
postgres=# cd c:\Program Files\PostgreSQL\11\bin
Invalid command \Program. Try \? for help.
postgres-# \cd c:\Program Files\PostgreSQL\11\bin
Invalid command \Program. Try \? for help.
postgres-# \cd..
Invalid command \cd... Try \? for help.
postgres-# \cd ..
postgres-# \cd Program Files
\cd: could not change directory to "Program": No such file or directory
I'm not even sure about current directory as pwd is not recognized:
postgres-# \! pwd
'pwd' is not recognized as an internal or external command,
operable program or batch file.
many thanks in advance
UPADATE: Figured out how to check current directory \! cd
Tried to run command this way \! C:\>cd C:\Program Files\PostgreSQL\11\bin
I get:
postgres-# \! C:\>cd C:\Program Files\PostgreSQL\11\bin
Access is denied.
A bit late for OP, but here are some tips for others who stumble in here.
There are two relevant psql commands for these directory change and drive change tasks.
The "built-in" \cd command. You can use this to actually perform the change of directory. However, where Windows uses backslash, use instead forward slash. Also, this command understands drive letter, and unlike Windows cd, you don't have to add a flag to change drive with the cd command here. Examples:
\cd /dir1/dir2
\cd D:/dira/dirb <-- Drive letter
\cd '/dir with spaces/other dir' <-- single quotes
Problem: How do you display the current drive/directory? Unlike in Windows, if you issue a \cd with no argument, psql does not show you the current directory. Instead it changes to the root C:\ directory (presumably in analogy to linux cd command changing to home directory.) So you need to issue a different command to see current directory.
psql can call a shell command, using the form \! <command>
So in linux you could use \! pwd to view present working directory. However, Windows doesn't have a pwd command. But you could use \! cd.
This is apt to get confusing, and prone to accidentally using \cd (which changes the directory unwantedly) when you intended ! cd, especially if you're jumping between Windows and Linux. So on Windows you might want to create a batch file to implement pwd.
As a further point of confusion, you might think to use something like:
\! cd \dira\dirb , however, for some reason, running \! cd with arguments doesn't seem to work (forward or back slashes).
An additional alternative, if you only need to change to a particular current directory once, you could cd before running the script that launches psql. That is to say, don't use the "SQL Shell (psql)" command that Postgresql installs on the Start Menu. Instead, look at the properties of that command, note the path to the script, and use that in a command window only after you've cd'ed to the desired directory.
You could try
postgres=# \cd 'c:\\Program Files\\PostgreSQL\\11\\bin'
I'm using windows btw
You have to change your directory before you run psql
Now, you might be thinking but when I open psql shell Its already running psql that's because you opened it in psql shell, don't do that
Here's what you need to do
open command prompt
change your directory using cd
then run the psql command
if you are getting 'psql is not a command' error, that is because the psql path is not in your environmental variables
if you need to fix that go to this page..→ Click me

Navigating with cd and assigning a directory path to a shortcut variable name in Windows Bash

Is it possible to assign a directory path to a shortcut variable name that can be used to access quickly over and over again through commands like cd?
I am navigating consistently between several directories and I would like to avoid typing out the full directory path every time. I recall having the capacity to enter the shortcut for a path to access a commonly used directory in Linux. I was wondering if it is possible to use the same cd [SHORTCUT_DIRECTORY_NAME] in Windows Git-Bash or if there is an alternative permanent solution that would limit typing out the full directory paths.
Here is an example of such command to access C:\Users\[NAME]\Documents\common directory in a linux machine shortened to com:
[USER]#DESKTOP /c/Users
$ cd com
[USER]#DESKTOP /c/Users/[NAME]/Documents/common
$
I have mostly found ways to use .bat files and I'm not sure this applies to Windows. I was thinking my next best bet would be trying to create a Shell script, but any input on the most convenient method would be greatly appreciated.
Thank you!
Environment: Windows 10, Git Bash v. 4.4.12
is this what you require:
you can assign the directory path to a string and do cd $string. Example:
sh-4.4$ dir="/home/cg/root/abc/xyz/tyh/"
sh-4.4$ pwd
/home/cg/root
sh-4.4$ cd $dir
sh-4.4$ pwd
/home/cg/root/abc/xyz/tyh

Issue with win cmd finding folders

I am having an issue with the windows cmd line. When I cd into my Users dir my user folder shows as there but I cannot cd into. The path cd\Users\gmenfan83\ is my desired location. However, when I am in the Users dir and cd\Users\gmenfan83 \ I get a "The path is not found or specified" . I am more of a nix user but if the folder shows in the directory tree shouldn't I be able to cd into it? Thank you
Are you trying to use cd/Users/gmenfan83 while you have already used cd/Users? In that case you will not be able to find the file since you are already in the Users folder. Typing cd \Users\gmenfan83 right after opening cmd with C drive path should get you there.
It's unclear (even after your edit) what specifically you're doing, but this should get you started.
If you're currently in C:\users, and you want to change into the C:\Users\gmenfan83 folder, all you need is cd gmenfan83. If you're in C:\, all you need is cd users\gmenfan83.
Relative paths also work in Windows cmd.exe just as they do under *nix. To change from C:\users\gmenfan83\test to C:\users\gmenfan83\temp, you can use cd ..\temp, or specify cd \users\gmenfan83\temp.

Issue while navigating to a directory "C/Program Files (x86)" with cygwin?

I am trying to navigate to this below path in cygwin,
C/Program Files (x86)/temp/lfc/utilities
but unfortunately, it shows the below error
$ cd C/Program Files (x86)/temp/lfc/utilities
bash: syntax error near unexpected token `('
Could you please let me know, what is wrong here..
The command:
cd C/Program Files (x86)/temp/lfc/utilities
is trying to call cd with three arguments rather than the correct one:
C/Program
Files
(x86)/temp/lfc/utilities
and the third of those arguments contains characters that cause bash some grief - they're actually defined as metacharacters and, as per the bash doco:
Each of the metacharacters listed above under DEFINITIONS has special meaning to the shell and must be quoted if it is to represent itself.
Just surround the whole lot in quotes, like:
cd '/cygdrive/C/Program Files (x86)/temp/lfc/utilities'
You'll notice I've also prefixed it with the CygWin cygdrive mount point. I'm fairly certain that's still needed, at least from the version I installed a couple of months back.
Cygwin uses POSIX path nomenclature. To easily convert a Windows path into a Cygwin path you can use the cygpath tool:
$ cygpath 'C:\Program Files\foo'
/cygdrive/c/Program Files/foo
Also this tool can convert POSIX path to Windows:
$ cygpath -w '/cygdrive/c/Program Files/foo'
C:\Program Files\foo
A third solution is to drag and drop a file or folder from the Windows explorer directly into your mintty terminal. You will get you Windows path directly converted into the Cygwin's format.
You could also use PROGRA~1, PROGRA~2 and PROGRA~3 like this :
cd /cygdrive/c/PROGRA~1 is equivalent to cd
/cygdrive/c/Programmes
cd /cygdrive/c/PROGRA~2 is equivalent to cd
/cygdrive/c/Program\ Files\ \(x86\)
cd /cygdrive/c/PROGRA~3 is equivalent to cd
/cygdrive/c/ProgramData
You can directly use windows paths with:
cd $(cygpath -u "C:\Program Files (x86)\temp\lfc\utilities")
This is useful for environment variables like:
cd $(cygpath -u "$USERPROFILE")/Downloads
cd "$(cygpath -u "$PROGRAMFILES")/Program Name"
You can know more about cygpath on https://cygwin.com/cygwin-ug-net/cygpath.html

Resources