Arash
Arash

Reputation: 23

Git bash: 'cp' is not recognized as an internal or external command, operable program or batch file

In Git bash, when I use the cp command, it gives the error message:

'cp' is not recognized as an internal or external command, operable program or batch file.

what should I do ?

Upvotes: 1

Views: 7520

Answers (2)

Lupa
Lupa

Reputation: 822

In Git Bash 5.2.x 64bits (at least in x=15 and x=26) the command exists and works. I specifically used cp -v -f

$ echo "hola" > holamundo.txt

$ cp -v -f ./holamundo.txt ./h1.txt
'./holamundo.txt' -> './h1.txt'

$ dir
h1.txt  holamundo.txt

I know this question is old but I faced a similar situation when testing CI pipelines using bash in a self-hosted Windows agent that usually had been working fine in Microsoft-hosted agent. The pipeline failed because it had executed cp from PowerShell, which is an alias for Copy-Item, and it failed because -f had resulted ambiguous.

After installing Git and configured it as an agent's capability it worked the same as in the Microsoft-hosted agent.

BTW, cp is not documented as it is not listed when you type help in a Git Bash console.

Upvotes: 0

Dustin
Dustin

Reputation: 38

I just had the same issue. I had to use copy in Windows instead of cp for it to work. See this link CP Command Prompt Windows 7 not recognized.

Upvotes: 1

Related Questions