7

I entered cd -- into the terminal, just to see what I'd get...

It brought me here: ~ # (I'm root btw).

Just wondering where exactly I am - if I enter ls the output is:

Desktop

ls -a:

.          .bash_history  .config  .loki        .q3a
..         .bazaar        .dbus    .kbd        .macromedia  .synaptic
.adobe     .bzr.log       Desktop  .panda3d     .wine
.aptitude  .cache         .gconf   .local      .profile

I can't cd into home, / or anything else - and I can't get out of the folder :'(

Would be nice to know what I just did...

5
  • 2
    You are in the /root
    – Pilot6
    Dec 19, 2015 at 21:57
  • @Pilot6 how do you/I know?
    – TellMeWhy
    Dec 19, 2015 at 21:58
  • 2
    By the prompt. ~# is /root.
    – Pilot6
    Dec 19, 2015 at 21:59
  • And there is no problem to do e.g. cd /home
    – Pilot6
    Dec 19, 2015 at 21:59
  • 5
    Do "pwd" to see where you are.
    – pcm
    Dec 19, 2015 at 22:01

2 Answers 2

13

The -- is interpreted as "no more options following", see more in this answer. So the command is equivalent to cd, which switches to the current user's home directory.

As you reported, you end up with a prompt of ... ~ #, which, with default config means that you are logged in as the root user and that you currently are in root's home directory (~ is a shortcut for a user's home).

On a default Ubuntu setup, the home of root is /root. So cding to home doesn't work, as you are not in the root directory and therefore the shell doesn't know where to go. But you should always be able to cd /. Are you sure you entered that command correctly?

3
  • I'm not sure your first paragraph is technically accurate . Bash doesn't "interpret" --, it's handled as part of the application argument parsing.
    – Oli
    Dec 19, 2015 at 22:05
  • Of course, you're right ;) I'll change it.
    – s3lph
    Dec 19, 2015 at 22:06
  • 7
    @Oli's remark is 100% spot on since not clarifying that is potentially misleading, however the funny fact is that in this case it's not inaccurate to say that Bash handles it, since cd is a built-in (hence part of Bash). You may well say that Bash handles it, but you should also make it clear that this is because cd is part of Bash.
    – kos
    Dec 19, 2015 at 22:27
2

The command pwd will output your present working directory (where you are).

@pilot6 is probably right - you are in /root given your ls output.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .