0

I don't know why someone would make a directory with a leading hyphen, e.g. named "-1". When I try to change to that directory, it says invalid option.

I tried putting "-1" in quotes but that didn't help either. Can anyone tell me how to access these types of dirs?

$ ls -l
total 3
lrwxrwxrwx 1 root root 2 Dec  7 18:51 lastFailedBuild -> -1
lrwxrwxrwx 1 root root 2 Dec  7 18:51 lastUnstableBuild -> -1
lrwxrwxrwx 1 root root 2 Dec  7 18:51 lastUnsuccessfulBuild -> -1
$ cd -1
-bash: cd: -1: invalid option
cd: usage: cd [-L|[-P [-e]] [-@]] [dir]
$
2
  • 2
    Looks like this directory doesn't even exist. Commented Jan 26, 2023 at 22:26
  • 1
    For many GNU utilities you could use -- to delimit options and arguments, i.e. cd -- -1 could have worked if it had existed. Commented Jan 26, 2023 at 22:28

1 Answer 1

2

You can anchor the name -1 in the current directory by prefixing it with ./. Then, then resulting name ./-1 does not start with a dash and cd will not try to interpret it as an option.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.