I'm learning Git and my very first task is to navigate to a directory where my project will live. Unfortunately, my primary folder for my documents has the following form - folder1 -
for sorting purposes, and each time I enter;
cd - folder1 -
I receive the error;
bash: cd: too many arguments
After searching for a solution I have tried;
cd -- folder1 -
cd ./- folder1 -
cd .- folder1 -
cd /- folder1 -
and even changing the directory to the parent directory and trying a longer path but this doesn't work either
cd ..
cd parent/- folder1 -
The Meaning of – With cd But, using a dash as an argument of cd will change the current directory to the previous working directory. When we use a single dash as an argument of the cd command it contains the path of the previous working directory (OLDPWD).
cd or change directory The cd command allows you to move between directories. The cd command takes an argument, usually the name of the folder you want to move to, so the full command is cd your-directory . In the terminal, type: $ ls.
As a rule of thumb, if your filenames have spaces or special chars like $
put them in single or double quotes. As another rule of thumb, if one of your arguments starts with a -
and your command is interpreting it as an option instead of a filename (an option like the -n
in in echo -n myfile
) then you need to put a --
as an argument to your command.
So to solve your problem try this:
cd "- folder1 -"
If cd
continues to think your folder name is an option, then do this:
cd -- "- folder1 -"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With