Cannot change directory in psql on windows 10. PostgreSQL 11 - windows

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

Related

CD command is not working

I am unable to change directory to a path stored as a variable value.
cd %VBOX_INSTALL_PATH%
If I input the command at the cmd.exe prompt it's working, but the same is not working in a batch file.
It's printed as:
cd C:Oracle/vbox
C:Oracle/vbox Not a valid directory path
Kindly help me to resolve it.
The CD command looks like this: CD C:\Oracle\vbox So if the error message is cd C:Oracle/vbox;C:Oracle/vbox Not a valid directory path Kindly help me to resolve it. I assume the content of %VBOX_INSTALL_PATH% is not C:\Oracle\vbox but something else. There is at least a \ missing right after C:. Further, this will only work as you expect if you are already on drive C:. If you want the command to work from everywhere, you should add the /D parameter:
SET "VBOX_INSTALL_PATH"="C:\Oracle\vbox"
CD /D %VBOX_INSTALL_PATH%
And by the way, / is the regular path separator for LINUX. For Windows, it is \. Windows will often accept / but in some cases, it might cause trouble.

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

How to change directory under git bash

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

Command not found

I am quite new to the Mac Terminal environment.
I donwloaded sqlplus (which is recognised as a UNIX executable program) and then in Terminal I do cd a few times until I arrive in the folder I put this in (\Applications\instantclient_10) in this case.
When I type 'ls' I see a listing of all the files including the sqlplus. So I would then expect to simply type at the Telnet prompt 'sqlplus' and then this would start but instead keep getting
-bash: sqlplus: command not found
This is problem one.
I have now downloaded MySQL and again, when I go to the correct folder (\Library\StarupItems\MySQLCOM) and I type 'ls' I see my files (including MySQLCOM) but when I come to try to 'run' this by simply typing 'MySQLCOM' again the message is:
-base: MySQLCOM: command not found
What am I doing wrong?
Thanks
To run binary/executables in current folder you need to prefix them with ./
./sqlplus
The idea here is that you want to force execution of local file and not run it accidentally. Imagine app that would put ls binary into it's folder and it would automatically run if did ls in that folder.

Resources