News for hackers. Stuff that matters.
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by buran77 on Monday November 18, 2024 @09:11AM (#42172410)
> rm -rf ~*

I'm more curious about the ~* part. Is the behavior triggered by a tcsh peculiarity that no longer works that way these days? Why would ~* trigger he behavior of deleting every home directory?

And aren't Emacs backup names appended with ~ rather than prepended? In that case shouldn't it be "~" (anything ending in ~) instead of "~*"?

The story sounds a bit flimsy regardless. Not that it's improbable but rather the opposite, rm -rf* stories are a dime a dozen.

Re:Undergrad thought he had mastered Unix in weeks. Then he ... by andai on Monday November 18, 2024 @09:20AM (#42172486)
Here's my reading: this ran in /home/ for some reason, where all the homedirs had a name pattern like ~stuff.
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by MayeulC on Monday November 18, 2024 @09:34AM (#42172584)
Likewise. Quite a few people here not realizing this is likely (t)csh-specific.

I ran a quick test on multiple tcsh versions I had installed, the oldest being 6.13 (2004, RedHat 4). All returned 'Unknown user: *.'

It wouldn't surprise me if at some point this expanded to every user's home directory, the way '~username' expands to /home/username, or wherever that user's home is.

I couldn't find anything of note in https://github.com/tcsh-org/tcsh/blob/master/Fixes

Re:Undergrad thought he had mastered Unix in weeks. Then he ... by einr on Monday November 18, 2024 @09:44AM (#42172700)
I couldn't say for sure that some UNIX shell somewhere at some point did not do home directory wildcard expansion -- seems like a WMD grade foot gun, but OK -- but as you've noticed, tcsh does not do it and in fact even if you go back to csh in NeXTStep from 1989 it doesn't do it either.

Try it yourself: https://infinitemac.org/1989/NeXTStep%201.0

Re:Undergrad thought he had mastered Unix in weeks. Then he ... by matrss on Monday November 18, 2024 @09:26AM (#42172535)
~username expands to the home directory of username. There might have been a shell that likewise expanded ~* to all home directories.
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by TrainedMonkey on Monday November 18, 2024 @09:21AM (#42172500)
On zsh `~` expands to home directory, while `ls ~*` does not do anything:

  alex@world RevelCode % echo ~
  /Users/Alex
  alex@world RevelCode % ls ~*
  alex@world RevelCode %
I am also curious how `~*` expanded to an equivalent of `/users/*`.
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by mmh0000 on Monday November 18, 2024 @11:52AM (#42174250)
It partially depends on Zsh's NOMATCH and NULL_GLOB setopt:

NOMATCH - print error when glob doesn't match;

NO_NOMATCH - print literal GLOB character:

  setopt NOMATCH
  ls * => zsh: no matches found: *

  setopt NO_NOMATCH
  ls * => ls '*'
NULL_GLOB - when glob doesn't match, return blank; (Overrides NOMATCH):

  setopt NULL_GLOB
  ls * => ls ''

  # Brings behavior inline with RHEL/Bash4 defaults:
  setopt NO_NOMATCH
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by einr on Monday November 18, 2024 @09:36AM (#42172616)
It does not "not do anything", it expands to a list of your files that have a filename starting with ~. You just don't happen to have any in the current directory ;)

And yes, this is a potential footgun:

  % touch ~test
  zsh: no such user or named directory: test
  % touch "~test"
  % ls ~*
  ~test
  % rm ~test
  zsh: no such user or named directory: test
  % rm "~test"
  % ls ~*     
  %
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by account42 on Monday November 18, 2024 @09:30AM (#42172561)
It kind of makes sense that if you have ~username and wildcards that you can then apply those wildcards to the username as well and not just real files and directories.
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by PittleyDunkin on Monday November 18, 2024 @09:33AM (#42172576)
It says `tcsh` in the article.
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by blakesterz on Monday November 18, 2024 @09:18AM (#42172473)
My first thought was wanting to get rid those files that emacs leaves behind.
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by ruthmarx on Monday November 18, 2024 @10:18AM (#42173112)
I don't think the tilde is referring to a shortcut for a home directory here, rather I think it's the first character in the filenames of the backup files he was trying to delete.
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by justin66 on Monday November 18, 2024 @09:13AM (#42172423)
Recursively remove everything in the home directory.
Re:Undergrad thought he had mastered Unix in weeks. Then he ... by einr on Monday November 18, 2024 @09:26AM (#42172534)
No, that would be ~/* or just ~. The article says that the command deleted every user's home directory, which seems to imply that the shell would expand ~* to a list of every user's home directory. But -- sensibly -- neither modern tcsh, bash, zsh, ksh nor the ancient csh in NeXTStep does that.

csh on NeXTStep 1.0:

  localhost> echo ~
  /me
  localhost> echo ~*
  echo: No match.