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

от admin

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?

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.

Wpilot

Всякий раз когда в пути или в имени файла есть пробел вылезает эта ошибка. Что делать в этом случае.

Либо поместите путь до файла в кавычки либо не используйте пробелы чтобы путь до файла выглядел как одна строка. Проблема встречается не только в Linux. Если вы пользовались командной строкой Windows то там также присутствует эта ошибка.

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.

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.

How to Fix cd: too many arguments Error in Terminal: A Step-by-Step Guide

"cd: too many arguments" error occurs when you are trying to make use of the cd — change directory command to change your current working directory in the terminal or the command line.

Why this error

As the error says you are providing too many arguments to the command, while it excepts only one.

To know more about the syntax of this error let's take a look at its man page.

In the above example where our cd command failed we have provided

So definitely the issue is that we have added spaces in the directory path that is treated as a next argument!

Possible Fixes: Step-by-Step

Fix 1: Surround the path with double quotes

Fix 2: Make use of backslashes to escape special characters

You may also get this error if the directory name has special characters like braces.

In such a case you can escape the special characters with backslashes

Fix 3: Make use of tab completion

This is something that is highly recommended, while navigating to a directory using the cd command, always write some text pertaining to a directory and press the tab to autocomplete. It will automatically escape special characters for you!

Похожие статьи