To run a script in the current directory ./script.sh
. But if "." didn't exist, then we could just use bash script.sh
.
Yes, but that requires knowing what the right interpreter is. Perhaps someone rewrote it it Perl but kept the name for compatibility, or perhaps the name was actually just othertool
, without an extension. Running it as ./othertool
lets the system take care of that, via the hashbang line (#!
). Or other magic numbers, since the program could be a binary file too. Of course you could just add .
to PATH
, too.
That's a post-facto rationalization though, since I'm pretty sure hashbang lines didn't exist from the start (they're not POSIX even now).
To change to the parent directory cd ..
. But if ".." didn't exist, then I imagine a command could exist like cd --parent 1
(go up one parent directory)
Yes, it probably could exist. But that would mean every time you wanted to use relative paths, it'd be harder. You couldn't do something like mv ../foobar/blah .
Perhaps some programs would include some way to do that, either via a command line option, like your --parent
, or via some string prefixed to the path, e.g. %up/foobar/blah
, or such.
Similarly you couldn't make relative symlinks point at higher levels of the tree. A symlink in /foo/bar/link
pointing to /foo/other/file
would need to spell the name out, instead of just containing the relative reference ../other/file
. The link would break when foo
was renamed, or there would have to be a mechanism for rewriting any such symlinks on any renames...
Even if it's not too commonly needed, having a standard way to move up in the filesystem tree makes stuff like that more general, and general is better in cases where it is needed.
Also, the filesystem needs some way of finding the parent of a given directory for even cd --parent
to work, and the straightforward and obvious implementation is to store it exactly like every other directory related to that directory, with a special name.
.
is similarly useful so that you can do cp /some/where/file.txt .
without a special way of referring to "here". Though as I recall, e.g. the COPY
command on DOS/Windows defaults to the current directory as destination, and e.g. GNU find and GNU grep with -r
start from the current directory by default. But that also means every program must have a special case for the current directory.
Of course, the names could be something completely different, and it might not have been a bad idea to e.g. forbid creating other files with names starting with dots. Or to reserve some particular character for those special names, and forbid using that character at all in other filenames.
.
and..
denote the current and the parent directory, and why that choice was made instead of any other way of referring to these two directories? – Kusalananda Aug 15 '21 at 18:02*
for the parent directory, and an empty path element for the current directory. The path delimiter was:
, so you'd use*:FOO
to refer toFOO
in the parent directory (I think). It doesn't matter really what the symbols are, but in a hierarchical file system, you would need a way to specify, with a path, that something is up a level or in some other way relative to the current directory. – Kusalananda Aug 15 '21 at 20:24>
e.g.>user_dir_dir>proj>user>stuff
and<
(by itself, not combined with>
) was parent. Apple (Mac, don't recall Lisa) used:
for delimiter but AFAIR not*
for parent. – dave_thompson_085 Aug 16 '21 at 00:51