0

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?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Alexander Mills
  • 9,330
  • 19
  • 95
  • 180

2 Answers2

1

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.

muru
  • 69,900
  • 13
  • 192
  • 292
Francisco
  • 188
  • 7
  • 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](https://unix.stackexchange.com/questions/77127/rm-rf-all-files-and-all-hidden-files-without-error/313388), and updated the answer. – Francisco Apr 19 '18 at 23:52
0

I got a suggestion to do this:

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

should work, I guess.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Alexander Mills
  • 9,330
  • 19
  • 95
  • 180
  • 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 01: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 –  Apr 20 '18 at 01:52
  • sorry I don't follow...I add comments to my answers all the time – Alexander Mills Apr 20 '18 at 02:00