Cd too many arguments что делать
Перейти к содержимому

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 cd: Too Many Arguments Error in Bash

Solve cd: Too Many Arguments Error in Bash

We use the cd command to change the working directory in Linux. However, incorrect use of this command may cause an error.

Please enable JavaScript

This article will explain how to solve the bash: cd: too many arguments error in Linux Bash.

Solve bash: cd: too many arguments Error in Bash

The cd command accepts a directory name as an argument and replaces the current shell environment’s working directory with the given directory.

If no argument is given, the cd command behaves as if the directory named in the HOME environment variable was specified as the argument.

If the directory you want to go to consists of more than one word and contains spaces, you should not give it an argument directly. The command below will generate the bash: cd: too many arguments error.

The command accepts test and directory as separate arguments and cannot operate. To solve this problem, you must write the directory name in quotation marks; use single or double quotes as you wish.

The following command will run without error, and the current directory will be replaced with the test directory . Using a slash ( / ) after the directory name is optional.

Another way to do this is to use the backslash character. The backslash ( \ ) is an escape character, and it preserves the literal value of the next character that follows.

So you can use the space character.

The following command will also run without error, and the current directory will be replaced with the test directory . Using a slash ( / ) after the directory name is optional.

Yahya Irmak has experience in full stack technologies such as Java, Spring Boot, JavaScript, CSS, HTML.

bash : cd : too many arguments [closed]

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

1 Answer 1

or escape the space:

(That being said, cd does not open a file but changes the working directory.)

Sora.'s user avatar
    The Overflow Blog
Hot Network Questions

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.6.15.43499

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Ubuntu 17.04 — bash: cd: too many arguments

I just upgraded my Ubuntu 16.04 to 17.04 and found a little problem with cd command.

Let’s say that I have two folders: album-01 & album-02

In Ubuntu 16.04, if I do cd album* it will go to the first folder found album-01

But in new Ubuntu 17.04, if I do cd album* it result me -bash: cd: too many arguments

How to make cd in Ubuntu 17.04 like cd in Ubuntu 16.04?

muru's user avatar

Hidayats's user avatar

4 Answers 4

I couldn’t test this on a real 17.04 system yet (only verified that it works on 16.04), but you should be able to override the cd Bash built-in command with your own custom function, which discards any additional arguments except the first one:

Update: As suggested in @muru’s comment, this version below might work better and support calling cd without arguments though:

After you have entered this line above in your terminal, please verify whether cd now behaves in the way you want. If this is the case, you can make this function definition persistent by appending that line to the end of your

/.bashrc file. Otherwise it will vanish as soon as you end your current shell session.

Note that if for whatever reason you temporarily need to use the real cd Bash built-in command instead of this custom function, you can simply call it with command cd instead of plain cd .

Byte Commander's user avatar

Short answer/Workaround

To answer your question in this exact case, this works

But it is probably not the functionality you really want.

What changed?

It appears that config-top.h in Bash-4.4 was updated to add the following option

And builtins/cd.def refers to your error here:

What can I do long-term?:

You could compile your own bash without the new CD_COMPLAINS, but that would get tedious. You can redefine the cd functionality like suggested here or you could alias a function like

Proving it

Bash 4.4 Beta where it still works

Bash 4.4 Stable Release where it doesn’t work

prolificslacker's user avatar

I’ve never encountered this issue as I always use Tab Completion.

So in your case, rather than having an imprecise guess as to which directory I want, I would type cd al Tab which if there’s only one match, completes it and if there are 2 or more completes up to where the matching ends and Tab Tab lists the choices.

Here’s an example from my system:

followed by Tab Tab produces

Elder Geek's user avatar

This looks like a bug in Bash: per man builtins the old behaviour is the correct one.

You can report the bug on the bug-bash mailing list; more details here.

Actually, the bug was reported (long ago). If you want a fixed Bash now, now, now, here’s how to do it properly (tested on 17.10, should work on others as well).

First create a directory to work in, for example:

Get the source package and the build dependencies:

Edit config-top.h to change this (should be line 32)

Edit debian/changelog and add an entry like this at the top (you can also use the command dch -i ):

The most important points are to append +foo to the current version number ( foo can be any string of lowercase letters; and be careful if you use dch -i , it will increment the last number, so you need to revert it to the current one) and to use the correct release name ( artful here). Finally, run dpkg-source —commit .

You can then run the debuild command, and if everything goes well (errors about debsign can be ignored) you should have some .deb s in the parent directory, which you can install as usual (there is no need to install all of them, just the ones you have now; use dpkg -l | grep bash to find out).

Note that the version number of the new package is set so that you will automatically get any future update to bash ; if the update does not fix the problem, you have to repeat the above process.

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

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