This looks like a great way to get over the initial hurdle of unfamiliarity.
The only thing that looked potentially confusing was calling "cd .." a way "to step back". It could sound like a way to go to the last directory you visited instead of a way to go up a directory.
cd itself is implemented by the shell (granted, it is mostly just a syscall). You can't fork and exec a cd program because it would need to change the parent's working directory.
Also, bash offers a directory stack you can use:
pushd pushes the current directory to the stack and cd`s to the specified directory.
popd pops the top directory from the stack and cd`s into it.
Not quite the same thing as cd -, but still useful to know.
> cd itself is implemented by the shell (granted, it is mostly just a syscall).
Right, the distinction I was drawing is just that the shell potentially does chdir("..") when you run "cd ..", but it can't do chdir("-") when you run "cd -". It's true that in both cases the shell has to make the chdir syscall rather than running an external program.
I just did "strace -e chdir bash" and noticed that in fact, my shell doesn't do chdir("..") at all in practice, presumably because it wants to maintain a clean notion of PWD that doesn't contain a complex series of relative paths.
> presumably because it wants to maintain a clean notion of PWD that doesn't contain a complex series of relative paths.
More probably, it's so that things don't get confusing for the user with symbolic links to directories. If you cd to a symbolic link that leads to a directory, `chdir("..")` goes to the parent of the target, while `cd ..` goes to the parent of the source. In other words, `cd dir/subdir/; cd ..` will always get you back to dir/, but if it used chdir("..") it wouldn't always.
I think it kind of works, because it’s shown here in the context of the path shown on the PS1, (though I think it’s only the last directory by default?) I wonder if some variant of just ‘cd’ or ‘cd ~’ (or pwd) would be useful, I’ve often seen beginners get lost in the filesystem and knowing how to get back to the start is reassuring.
I wish ls colors were on by default though, it makes it much easier to know what is and isn’t a directory. (“I can make this easier by typing some magic that you don’t need to understand yet” isn’t a great tutorial process)
The only thing that looked potentially confusing was calling "cd .." a way "to step back". It could sound like a way to go to the last directory you visited instead of a way to go up a directory.