CentOS 6.2 Shell:
I'm playing around with
cd for a BASH script, and noticed the wondrous
cd - option, but was left with many questions...
- Why the
cd -? Isn't this redundant with
[As FatalError points out, these two commands don't do the same things... so the answer is "no"]
- Can you delve farther back into your history with
-flag, a la in a browser?
e.g. When I type
cd -, it takes me to my previous directory, but then if I enter that command again, it takes me to the directory I just came from, creating a sort of loop.
Is a shorthand for going back multiple levels supported?
I realize I can go back with
cd .., but was hoping this could be a gateway to a less verbose deep back, e.g.
cd ../../../... hopefully that clarifies what I'm asking....
As to the current feedback, while
..is a special directory, I don't see a reason why the built-in
cdto the terminal couldn't use a shorthand for
../../ ... ../e.g.
cd ..5or why the built-in also couldn't have a history (a la auto
popd) that could be turned on and used like
cd -3. I get that this could be somewhat of security/privacy risk, but I don't see how it's any worst than storing a command history, which most shells/terminals do.
- The manpage for
cd, accessible via
help cd(it's the same for either command), only lists
However when I type in
cd --helpit outputs
Usage: cd [-plvn][-|<dir>]..
Am I right in assuming the other flags and the - (back) option are nonstandard?
- What are the
Both seem to take me back to my home directory, that's all I've been able to figure out via experimentation.
Note: The second Linux-centric resource above claimed
cd only had two options (obviously not true in current
CentOS) hence my assumption that this functionality could be non-standard.