1
Platform: CentOS 6.2
Shell:tcsh
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 withcd ..
?
EDIT
[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 typecd -
, 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?
EDIT
I realize I can go back withcd ..
, but was hoping this could be a gateway to a less verbose deep back, e.g.cd -3
vs.cd ../../../
... hopefully that clarifies what I'm asking....
EDIT2
As to the current feedback, while..
is a special directory, I don't see a reason why the built-incd
to the terminal couldn't use a shorthand for../../ ... ../
e.g.cd ..5
or why the built-in also couldn't have a history (a la autopushd
/popd
) that could be turned on and used likecd -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 viaman cd
andhelp cd
(it's the same for either command), only lists-L
and-P
flags.
However when I type incd --help
it outputsUsage: cd [-plvn][-|<dir>].
.
Am I right in assuming the other flags and the - (back) option are nonstandard?
- What are the
-n
and-v
flags for?
Both seem to take me back to my home directory, that's all I've been able to figure out via experimentation.
A quick read on web resources [1][2] offered just the same sort of info that the man page did and didn't answer my questions.
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.
You might be using a builtin provided by
tcsh
calledcd
and not invoking/bin/cd
(unless you explicitly specify/bin/cd
on the command line) - this probably accounts for the difference in behavior. I'm not knowledgeable enough abouttcsh
to help you further, though. Try typinghelp cd
(that's forbash
, don't know how it will work ontcsh
...) – LawrenceC – 2012-04-25T20:21:41.293Just to add, executing
/bin/cd
would be pretty pointless (cd
pretty much has to be a builtin to be useful). I'm pretty sure it only exists to satisfy some obscure POSIX requirement. – FatalError – 2012-04-25T20:30:03.480Ah interesting, you're right, this is
tcsh
specific... that's kind of odd. I still am curious what the extra flags do.help cd
prints the same info asman cd
, like I mentioned... no clue as to what the extra flags in thetcsh
built-in are for. – Jason R. Mick – 2012-04-25T20:31:28.797Regarding 3, multilevel "
cd ..
": note that command history enables you to docd .. <Enter> <Up> <Enter> <Up>
and so on to quickly traverse backwards through the file tree. Perhaps I mostly find this more convenient because of my specific keyboard locale where/
is behind the shift modifier, though. – Daniel Andersson – 2012-04-25T20:56:35.350true, but then you have like 3-5
cd ..
littering your command history, which is less than optimal. acd ..5
built in would not only be less typing and easy to implement, it'd also leave your history cleaner. It's amazing to me that I'm possibly the first to have thought of it. :P – Jason R. Mick – 2012-04-25T21:37:01.650Thanks for your questions, but they should really be split into separate posts. Having several orthogonal questions (even if they are related to the same tool) in the same place makes for a less navigable site. – l0b0 – 2012-04-26T12:00:44.820
@I0b0 I wouldn't call them orthagonal, they're all related to the topic at hand. The question is fairly detailed and cohesive in my opinion, but if not, feel free to edit. – Jason R. Mick – 2012-04-26T14:44:51.493