Перейти к содержимому

Cd too many arguments что делать

  • автор:

bash : cd : too many arguments

Few days ago, my friend asked me why he can’t enter to a directory called “reddit stock” that created by himself in Linux. The system keep showing “bash : cd : too many arguments”.

[Root Cause]

cd requires exactly 1 argument: The name of the directory that my friend typed reddit stock . System consider the user supplied two arguments split by space, so that’s why you got “to many arguments”.

[Solve]

  1. cd «reddit stock» By enclosing the folder name in quotes
  2. cd reddit\ stock By including a backslash as shown

Reference:

bash : cd : too many arguments [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

Closed 4 years ago .

if i need to go to my directory named as»exception handling» then i write (cd exception handling) but it gives error too many arguments

Veerabala J
asked Nov 17, 2017 at 13:38
Veerabala J Veerabala J
563 1 1 gold badge 5 5 silver badges 14 14 bronze badges

Either put the file name in quotes or escape the spaces so that bash knows it’s one string: cd ‘long file name’ or cd long\ file\ name . The problem is not unique to Ubuntu. If you were in a Windows command shell you’d have the same issue.

Nov 17, 2017 at 13:41

The problem is unique to bash 4.4; its implementation of «cd» is buggy. The manual page bash(1) specifies that » Any additional arguments following dir are ignored.» The OP’s command should go to directory «exception» and ignore «handling». Instead it throws an error. This is a bug. I tried bash 4.2, where «cd» works correctly.

Cd too many arguments что делать

Last updated: Mar 22, 2023
Reading time · 3 min

banner

# Table of Contents

  1. cd: too many arguments error in Bash and ZSH
  2. Wrap the name of the directory in double quotes
  3. Use a backslash to escape the spaces
  4. Use the Tab key for auto-completion
  5. Open your terminal in the destination directory

# cd: too many arguments error in Bash and ZSH [Solved]

The «cd: too many arguments» error in bash and zsh occurs when we try to cd into a directory whose name contains spaces or special characters.

You can solve the error by wrapping the directory name in double quotes or by using a backslash to escape each space.

cd too many arguments in bash zsh

Here is an example of a command that causes the error.

Copied!
cd my new folder

We a trying to cd into a directory whose name contains spaces, so bash assumes that we are passing multiple, space-separated arguments to the cd command.

You might also get the error «cd: string not in pwd:» when you try to cd into a path that contains spaces.

Copied!
# ⛔️ cd: string not in pwd: cd my folder

cd string not in pwd

The solution to both errors is the same.

# Wrap the name of the directory in double quotes

One way to solve the error is to wrap the name of the directory in double quotes.

Copied!
cd "my new folder"

example of command that causes error

You can also wrap an entire path to the directory in quotes.

Copied!
cd "my folder/my nested folder"

wrap entire path to directory in quotes

You can also wrap only the path components that contain spaces or special characters in quotes.

Copied!
cd my_folder/"my nested folder"

wrap only necessary path components in spaces

# Use a backslash to escape the spaces

You can also resolve the error by using a backslash to escape each space in the path.

Copied!
cd my\ new\ folder

using backslash to escape each space

Backslashes are used to escape special characters, so they can be treated literally.

For example, escaping a space with a backslash means «Treat the space as a literal space character and not as a separator between arguments».

Using this approach is a bit tricky because each space has to be escaped by a backslash.

It also gets a bit difficult to read when the path is deeply nested.

Here is an example.

Copied!
cd bobbyhadz-js/my\ new\ folder

backslash escape nested path

I used a forward slash / as the separator between the path components and then used a backslash \ to escape each space.

# Use the Tab key for auto-completion

You can also solve the error by using Tab auto-completion:

  1. Start typing the path.
  2. Press the Tab key to get auto-complete directly in your terminal.

Here is a short clip that demonstrates how this works.

If you have multiple folders with similar names, you might have to type the first few characters of the name to identify the correct folder you want to cd into.

If you don’t get autocomplete when you start pressing Tab , then the specified path doesn’t exist.

# Open your terminal in the destination directory

If you still aren’t able to cd into the directory, you can open your terminal directly in the destination folder.

For example, on Linux, you can:

  1. Open the directory in explorer.
  2. Right-click and select Open in Terminal.

open folder in terminal linux

Here is a short clip that demonstrates how this works.

On macOS, you can:

  1. Open a Finder window and navigate to the folder.
  2. If you don’t see the path bar at the bottom of the Finder window, choose View -> Show Path Bar.
  3. Press Ctrl and click the folder in the path bar.
  4. Select Choose Open in Terminal.
  1. Open the folder in Finder.
  2. Click on Finder in the top menu, then hover over Services.
  3. Select New Terminal at Folder.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

  • cd: no such file or directory error in Bash and ZSH [Fixed]
  • bash: permission denied: /home/user/.bashrc error [Solved]
  • Ubuntu: An error occurred. The specified movie could not be found
  • Unable to update «Snap Store»: Cannot refresh «snap-store»

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.

error: -bash: cd: too many arguments [duplicate]

Also, I just randomly happened to look at this question when it popped up. I typically look at questions tagged windows-subsystem-for-linux. Yours isn’t tagged this way, but it appears to me that you are likely using WSL on Windows. If that’s the case (and I could be wrong), along with @Nmath’s great advice on improving your question, please make sure to include all relevant details (and correct tags). If it’s WSL, make sure you say so (and tag it), along with the Windows version, Ubuntu version (it’s almost certainly not xubuntu), etc. Thanks!

Nov 6, 2022 at 1:10

The space character is a delimiter so you’ve provided multiple arguments where only one is required; ie. user error. It’s likely you intend the space as part of an argument, which means you need to escape it or place it in quotes so the space is treated as an argument character.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *