Hacker News new | ask | show | jobs
by hilsdev 15 days ago
If you use a trailing slash on the source it copies from the directory, if you omit the trailing slash it copies the directory itself. AFAIK this is pretty standard across POSIX tools
1 comments

It's not, for example cp -R doesn't change behavior on the basis of a trailing slash on directory names.
Indeed. This is one of the differences between the Unix and the MS/PC/DR-DOS command-line world. In the latter, recognizing empty final pathname components actually did become a way of differentiating such situations. I wrote a set of DOS and OS/2 tools in the 1990s, including COPY and MOVE commands, that had this very behaviour. I wasn't alone.
I was implementing something recently and stumbled across that cp difference. ugh.

the trailing slash is pretty convenient.

that's not a cp difference, cp is the granddaddy here

I think trailing / could be a nice way to indicate some meaningful difference, but since autocomplete always sticks it in, just feels like a bad idea to me. I might like it if directory names always had to have a trailing /, but I am less motivated by "convenience of common cases" and much more by "absolute precision/specificity/unambiguity" belt and suspenders.

(kind of unrelated but along the same lines, I toy with the idea of getting rid of . and .. visible in the filesystem, and make them only part of the syntax of paths. then you could have unambiguous multiple links to a directory: ".. is where you came from" and .. in the root is still the root, so chroot works too)

I think . and .. are useful. there's also perforce's ... which I find interesting (for example foo/... means everything below directory "foo")