I can do (say) cd ...
to go back 2 directories but ...
is not listed in the output if I do ls -a
. So how does linux understand that I want to go up 2 parent directories? I understand that .
and ..
are like hard links to the current and parent directory.
1 Answer
Answering my own question as my initial question itself was flawed
Linux doesn't actually understand multiple periods. It's actually zsh
which interprets it as going up multiple parent directories.
So if you are using zsh
and are on say /a/b/c
and use the command cd ...
, it will take you back to /a
. If you are using bash, it will correctly tell you that no such file or directory exists. It works the same way for other commands such as ls
so you can actually do ls ...
to see the files in the parent's parent directory. Just keep adding periods to go up one more parent.
It's a neat little feature hidden in zsh that I didn't know earlier. Thanks for the help everyone :)
cd ...
works? This doesn't work by default, only.
and..
are accepted 'shortcuts' unless you have some special scripts or such set up...grep '\.\.\.' ~/.bashrc ~/.bash_aliases ~/.bash_functions
zsh
maybe?zsh
, I didn't know this works only in zsh.oh-my-zsh/lib/directories.zsh
) - at least, that is the case on my system