1

I've been a fool.

I've written a python script that's supposed to create a folder at ~/photos and then write some files to it. However, instead of this it created a folder in my working directory called '~'. (including the 's).

I foolishly stormed ahead with an rm -rf ~ and hit enter before thinking. After spending the last few hours recovering I've ran the python script again and once again I'm faced with a folder named '~'.

Too terrified to run any command to remove it, I've come here to ask: How do I delete this folder safely? Am I safe to run rm -r '~'? (with the 's)

  • 2
    If you feel unsure, you can always run ls '~' before rm -r '~' to double-check. – Wieland Oct 30 '21 at 20:19
  • @Wieland ls '~' was the solution for me here. Thanks for this. – Danny Herbert Oct 30 '21 at 20:23
  • 3
    If you are unsure and you even are not sure if ls and rm work the same way, I would have renamed ~ using mv ./~ baddir (./~ should not be interpreted as the home directory) and then check if the bad directory has been renamed to baddir. In the worst case, your home directory is renamed to baddir. In the good case, you can safely do a rm -r baddir. – Martin Rosenau Oct 30 '21 at 20:34
  • @Wieland that would have shown nothing. Perhaps ls -d ~ – Chris Davies Oct 30 '21 at 20:42
  • 1
    Quote the quotes, like "'~'". Use rm -i ??? to match all names with 3 chars and interactively choose y or n for each one. ls will report names inside quotes if it thinks they contain suspect characters -- the name may really be just ~. Use find . -name '~' -- it should not treat it as HOME. – Paul_Pedant Oct 30 '21 at 20:51
  • learning the hard way.. you can always use find to list files, it has lot of search and exclude options (size date permissions etc) once only desired file is printed, add -delete flag – alecxs Oct 30 '21 at 22:11

0 Answers0