-3

I'm typing cd ~ C:\Desktop\gitPractice And I get this return:

bash: cd: too many arguments

What do I need to fix here in order to be able to change directory?

vidarlo
  • 9,165

2 Answers2

2

cd expects one argument. You provide two - ~ and C:\Desktop\gitPractice.

Furthermore, bash in git for windows doesn't use drive letters. Thus the command will be cd /C/Desktop/gitPractice

vidarlo
  • 9,165
2

As already said in extension, the Windows "CD" command does not know what a tilde is and only accepts one argument.

  • cmd /? help says:
Changes the directory or displays its name.

CHDIR [/D] [drive:][path] CHDIR [..] CD [/D] [drive:][path] CD [..]

.. Specifies that you want to change to the parent directory.

Enter "CD drive:" to display the current directory on the specified drive. drive. CD without parameters displays the current drive and directory. directory is displayed.

Use the /D option to change the current drive in addition to changing the directory. also change the current drive.

If the command extensions are activated, CHDIR is changed as follows changed:

The specified directory name is converted so that it matches the name in terms of upper and lower case. case-sensitive to match the name on the drive. For example CD C:\TEMP sets the current path to the directory C:\Temp if a directory with this name exists on the drive. directory with this name exists on the drive.

The CHDIR command does not treat spaces as separators, so that it is possible to change to a subdirectory whose name contains spaces without enclosing the name in quotation marks. Example:

cd \WINNT\Profile\Username\Programs\Startmenu

is the same as:

cd "\WINNT\Profile\username\Programs\Startmenu"

If the command extensions are deactivated, the quotation marks must be characters must be specified.

djdomi
  • 2,020
  • 1
    There's some hints it's probably git for windows with bash... – vidarlo Feb 18 '24 at 18:12
  • 2
    @vidarlo Even if the OP is running a git/bash or WSL, the answer still applies. The cd command under any operating system that I know of takes only a single argument. – doneal24 Feb 18 '24 at 21:38
  • @doneal24 yes, but behavior with regards to drive letters may be different. – vidarlo Feb 18 '24 at 21:39
  • Please show me an operating system that supports another behavior, such as Linux, DOS, or Windows. As already answered, you must do cd /D N:\other_folder to change the drive while using the cd command to other_folder – djdomi Feb 19 '24 at 07:24
  • @djdomi The /D part is what's unlikely to be supported by bash. Bash doesn't have a concept of drive letters like Windows. – vidarlo Feb 19 '24 at 09:53
  • That's right, but on Linux, we don't usually have drives with a letter name. The question was specific enough to be identified as being meant for Windows. – djdomi Feb 19 '24 at 09:57
  • Yet the error message clearly mentions bash, and the path indicates git for windows (which indeed has a bash component...). See my updated answer. – vidarlo Feb 19 '24 at 11:05