News for hackers. Stuff that matters.
Re:Why is the DOS path character "\"? (2005) by est on Friday February 26, 2021 @04:39AM (#26273014)
I never understood why Unix chose "-" for options. It creates unnecessary confusion. E.g. when deleting a directory called "-rf"
Re:Why is the DOS path character "\"? (2005) by skissane on Friday February 26, 2021 @05:19AM (#26273270)
Another viewpoint: the problem is caused by Unix allowing any character in filenames (other than slash and null). Other platforms are more restrictive in what characters filenames are allowed to contain. If you banned the '-' character from starting a filename, the problem wouldn't happen.

I personally think Unix allowing almost any character in filenames was a mistake. You can put newlines and other control characters in filenames. That has very little legitimate use, and is a potential source of security and other bugs. There is a proposal to amend the Unix standards to disallow control characters in filenames. But it doesn't look like it is going to be successful: https://www.austingroupbugs.net/view.php?id=251

Re:Why is the DOS path character "\"? (2005) by kiwidrew on Friday February 26, 2021 @05:58PM (#26280847)
Agreed!

Shell scripting would be so much more sane (and safe) if filenames couldn't contain spaces (or control chars) and couldn't begin with a '-' character. Then the shell's default $IFS would work as intended in the presence of pathname expansion, and there would be no need to use '--' to delineate the filename arguments from the option arguments when executing commands.

Re:Why is the DOS path character "\"? (2005) by shaoonb on Friday February 26, 2021 @05:48AM (#26273452)
A coworker of mine got into trouble when he named a directory ~ and then tried to delete it.
Re:Why is the DOS path character "\"? (2005) by bobowzki on Friday February 26, 2021 @06:12AM (#26273584)
I once named a file $HOME and then carelessly tried to delete it without thinking twice.
Re:Why is the DOS path character "\"? (2005) by toast0 on Friday February 26, 2021 @10:08AM (#26275469)
> the problem is caused by Unix allowing any character in filenames (other than slash and null).

Most Unixes don't allow any character; they allow any byte other than ascii slash or zero. Turning bytes into characters is outside the scope of most Unix kernels and the filesystems therein.

Re:Why is the DOS path character "\"? (2005) by skissane on Friday February 26, 2021 @05:52PM (#26280812)
> Turning bytes into characters is outside the scope of most Unix kernels and the filesystems therein.

All the major contemporary Unix(-like) kernels do have code in them to do file path charset translation. It is very important when dealing with removable media (ISO-9660, UDF), FAT filesystems, network filesystems (especially CIFS/SMB, but even some NFS implementations), filesystems defined in terms of Unicode such as NTFS, HFS+, APFS.

Traditional Unix filesystems don't do this, but they were originally designed at a time when few clearly distinguished the concept of byte from the concept of character.

Re:Why is the DOS path character "\"? (2005) by darkwater on Friday February 26, 2021 @05:26AM (#26273322)
The only solution to that confusion would be not allowing the options identifying character in file/directory names. Changing the character would just "change" the confusion.
Re:Why is the DOS path character "\"? (2005) by josefx on Friday February 26, 2021 @05:04AM (#26273164)
Wouldn't / just cause confusion trying to delete a directory called /rf ?
Re:Why is the DOS path character "\"? (2005) by est on Friday February 26, 2021 @10:31AM (#26275725)
There's no directory called /rf so the mistake can do no harm, as a good design should be.
Re:Why is the DOS path character "\"? (2005) by DHowett on Friday February 26, 2021 @11:48AM (#26276753)
Your comment is based on the premise that there is, in common use, a directory called “-rf” but not one called “/rf”? Why would the former be any less likely than the latter?
Re:Why is the DOS path character "\"? (2005) by Felk on Friday February 26, 2021 @04:59AM (#26273126)
Technically deleting a directory is done with the rmdir command. But rm with flags is flexible enough that I've seen very few people use rmdir
Re:Why is the DOS path character "\"? (2005) by Anarch157a on Friday February 26, 2021 @05:22AM (#26273291)
rmdir is usefull when you want to remove all empty subdirs, without touching files or directories with files. Just do 'rmdir *' and you're done.
Re:Why is the DOS path character "\"? (2005) by account42 on Friday February 26, 2021 @05:47AM (#26273449)
I like using rmdir even for individual directories that I think are empty just so that I don't accidentally delete any files that I did not expect to be there.
Re:Why is the DOS path character "\"? (2005) by Splognosticus on Friday February 26, 2021 @12:58PM (#26277697)
I use it whenever I expect a directory to be empty and want an error if for whatever reason it isn't. It's a bit niche, but good to have in your toolbelt.
Re:Why is the DOS path character "\"? (2005) by kaoD on Friday February 26, 2021 @05:09AM (#26273199)
There's always going to be ambiguity.

rmdir /f /usr

Is that force-deleting the /usr directory, or the /usr and /f directories?

Re:Why is the DOS path character "\"? (2005) by est on Friday February 26, 2021 @05:57AM (#26273506)
I mean on Windows it's

   rd /s /q \path\to\something
There's zero ambiguity because both "/" and "\" are special characters.
Re:Why is the DOS path character "\"? (2005) by hibbelig on Friday February 26, 2021 @09:35AM (#26275166)
Except that on Windows, you can use "C:/path/to/something" nearly everywhere where it accepts "C:\path\to\something".
Re:Why is the DOS path character "\"? (2005) by est on Friday February 26, 2021 @10:17AM (#26275583)
Except C:/ is not a command option, and only Unix people would write "/"
Re:Why is the DOS path character "\"? (2005) by naewonawonga on Friday February 26, 2021 @03:00PM (#26279177)
Sounds a bit provincial. That might have been true before mainstream internet access, but the average user these days is likely more familiar with unix style paths via URLs than local filesystem paths.

Also, most non-unix operating systems that don't happen to be made by Microsoft also use the forward slashes for paths.

Re:Why is the DOS path character "\"? (2005) by skissane on Friday February 26, 2021 @07:26PM (#26281455)
> the average user these days is likely more familiar with unix style paths via URLs than local filesystem paths

The average user ignores the contents of the address bar. "That's all tech gobbledegook". Increasingly, browsers even hide its contents from the user, just displaying the domain name, making the average user even less aware of it.

> Also, most non-unix operating systems that don't happen to be made by Microsoft also use the forward slashes for paths.

What are "non-unix operating systems that don't happen to be made by Microsoft". Non-Microsoft operating systems in common use – Linux (including Android), macOS/iOS/Darwin/XNU, *BSD – are Unix-like, and hence I wouldn't really call them "non-unix" (even if they are not strictly speaking certified as such)

If we look at non-Microsoft non-Unix(-like) operating systems (none of which are commonly encountered nowadays), we see a lot which use neither forward nor backslashes for directories. For example, OpenVMS and RISC OS both use dots, classic MacOS used colons. Stratus VOS uses the greater-than sign, which it inherited from Multics. The IBM mainframe operating system MVS (nowadays called z/OS) uses dots to separate the components of a dataset name – although those components aren't exactly directories. (It also supports forward slashes in its Unix compatibility subsystem, but that wasn't around for the first 25 years of its existence.)

Re:Why is the DOS path character "\"? (2005) by naewonawonga on Saturday March 06, 2021 @04:15PM (#26370573)
>> What are "non-unix operating systems that don't happen to be made by Microsoft".

It's a pretty big list. To name a few:

Beos (and derivatives), AmigaOS (and derrivatives), GEOS, Commodore DOS, Temple OS, TRON, plenty of Real Time Operating Systems...

Re:Why is the DOS path character "\"? (2005) by st_goliath on Friday February 26, 2021 @05:15AM (#26273240)
You can make that exact same argument irregardless of what switch character Unix uses. The real problem is not the switch character itself, but the approach used by standard Unix tools to "parse options until parsing fails, then assume it's an argument" which becomes an amazingly great foot gun if the actual option is inserted by a shell glob or a shell variable.
Re:Why is the DOS path character "\"? (2005) by eznzt on Friday February 26, 2021 @05:11AM (#26273214)
For everybody reading, a directory called "-rf" is deleted by writing "rm -- -rf"; -- indicates the end of all user-provided options.
Re:Why is the DOS path character "\"? (2005) by duckerude on Friday February 26, 2021 @06:22AM (#26273647)
If you're working with files, another (perhaps more reliable) way is `rm ./-rf`.