Powershell parameter error 'p' - windows

I tried typing this command
mkdir -p lol\hit\xx
But I get an error message
mkdir: Parameter cannot be processed because the parameter name 'p' is ambiguous.
I am following a tutorial online and according to that, there shouldn't be any error.
What is the reason behind this?

mkdir, when run in PowerShell, runs as an alias to New-Item. This can be seen by running Get-Help mkdir within PowerShell.
In that case -p is ambiguous because it could be either of the -Path or -PipelineVariable arguments for New-Item. I believe that what you want is:
mkdir -path lol\hit\xx
That will create the lol folder at your current location, and the hit folder inside it, and the xx folder inside of that.
The -p switch for mkdir in Unix forces the command to create all folders needed to get to the path you designate (so if all you had was 'lol' it would creates the 'hit' folder within that, and then create the 'xx' folder within the 'hit' folder). PowerShell's New-Item does this by default.

Related

Analog of $PWD in Windows

I run windows command in particular directory and I need to pass files and subdirectories in this directory with full path. How to retrieve full path of current directory? What is analog of bash $PWD?
$pwd is indeed a valid command in PowerShell as well (if you're using PowerShell). $pwd in PowerShell is basically an alias for Get-Location - both of them will give you the full path of current directory.
In case you are using cmd, use cd (just cd without any parameters)

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

Mkdir combined with "-p" flag

I am following a tutorial where I have to create a directory but also pass -p flag. I tried running it and I got a syntax failure. So I wanted to figure out what the -p did and found that this abbreviation is short for privileged. And found
Script runs as "suid" (caution!)
Started looking what that meant and found it meant Set User Identification and read that
– When a command or script with SUID bit set is run, its effective UID becomes that of the owner of the file, rather than of the user who is running it. Source
However, I still do not quite understand it. What is the purpose of me setting a directory to have that privilege and why should I be careful? Also, I tried looking here but I couldn't find any clarification(with the different search keywords I used). Also, not necessary.. but , why would me doing mkdir -p src/entities give me a syntax failure? I am using Windows(but I also have a bash package for Anaconda).
It looks like you're following a Unix-ish tutorial but running the commands on Windows in cmd.exe.
As the usage instructions say:
C:\>mkdir /?
Creates a directory.
MKDIR [drive:]path
MD [drive:]path
If Command Extensions are enabled MKDIR changes as follows:
MKDIR creates any intermediate directories in the path, if needed.
For example, assume \a does not exist then:
mkdir \a\b\c\d
is the same as:
mkdir \a
chdir \a
mkdir b
chdir b
mkdir c
chdir c
mkdir d
which is what you would have to type if extensions were disabled.
Windows commands don't use - for options (and in particular, the mkdir command built into cmd doesn't understand -p).
The part about "privileged" is for the shell option -p, as in bash -p. It has nothing to do with mkdir -p, which is explained in man mkdir:
-p, --parents
         no error if existing, make parent directories as needed
But again, that only applies to the Unix mkdir, not Windows / cmd.
"-p" creates parent directories if they don't exist.
For example:
With "-p" if "first" directory doesn't exist.
mkdir -p first/second # "first" parent directory is created
Without "-p" if "first" directory doesn't exist.
mkdir first/second # "first" parent directory is not created
mkdir: cannot create directory ‘first/second’: No such file or directory

How to locate a file in command prompt without having to direct to the specific folder

There must be a more effecient way to this, why can't I just type in the files name in the command line and expect the computer to find it? Right now I'm just paddling back and forward with the 'CD' and 'CD ..' commands.
You can use the following command which searches for the file in command prompt.
dir package.json /s
You can Use command find -path *content/docs/file.xml to find out the file.If it works please inform me the same.Thanks

cp and rsync cannot find system directory

I am working on a script to copy a custom user profile over to the default. Part of the script uses rsync to copy the contents of the customized profile, named "profile" to the default profile located in: /System/Library/User Template/English.lproj. Each time I run the command interactively, it fails indicating "No such file or directory." I can browse to the directory in the Finder. I can navigate to the directory via the terminal. Why can't rsync find it? Here is the command:
rsync -av /Users/profile/* /System/Library/User\ Template/English.lproj
I tried a similar approach using cp -R instead of rsync and got a whole bunch of file not found error messages. Using the cd command to that same path also fails. I can step through each individual directory and arrive at English.lproj but I can't do it in one command. Any ideas where I am going wrong with my command?
Thanks
Jason

Resources