This command:

rm -rf "$HOME/.quicklock/locks/"*

does seem to remove files or folders in the locks directory, which start with "."

how can I remove those files too? Any other filenames that would fail to be removed given that command?

  • Alexander, should the Q read “does not seem to remove...”? – Jeff Schaller Apr 19 '18 at 23:23
  • 1
    If you want to remove everything, why not rm -rf "$HOME/.quicklock/lock" && mkdir $HOME/.quicklock/lock? – tachomi Apr 20 '18 at 0:09
  • @tachomi that's probably the right idea lol, but maybe some race conditions if the dir does not exist, but I can handle that – Alexander Mills Apr 20 '18 at 0:43

You can use a clever combination of wildcards to avoid . and ..:

rm -fr .??*

would be one of them, which works if you don't have any files or directories that are only 2 characters long (like .x for example).

rm -fr .[!.]*

does that job better.

  • Would miss a directory or file named .X, unfortunately. – Jeff Schaller Apr 19 '18 at 23:34
  • Huh, that is unexpected. And ".X" seems to be specifically the issue. Longer filenames are no trouble... – Francisco Apr 19 '18 at 23:41
  • each question mark requires a character.... – Jeff Schaller Apr 19 '18 at 23:43
  • Okay that makes more sense... the .??* is something I came up with years ago and to which I never gave any more thought. To be fair, I never had to deal with 2-character file/directory names. I found this, and updated the answer. – Francisco Apr 19 '18 at 23:52

I got a suggestion to do this:

rm -rf "$HOME/.quicklook/locks";
mkdir -p "$HOME/.quicklock/locks";

should work, I guess.

  • 1
    of course invites race conditions if other processes expect "$HOME/.quicklock/locks" to always exist, but nothing that mkdir -p can't solve if I just use that command elsewhere. – Alexander Mills Apr 20 '18 at 1:39
  • SO and SE Unix/Linux is not a forum board where you go and add a comment on previous comment it works like question and answers kind of thinkg – 0x476f72616e Apr 20 '18 at 1:52
  • sorry I don't follow...I add comments to my answers all the time – Alexander Mills Apr 20 '18 at 2:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.