logoalt Hacker News

em-bee • today at 9:33 PM • 1 reply • view on HN

in the days of yore, when i still was a green linux/unix newbie i attempted to use the mirror tool (written in perl i believe) to create a mirror of something on my account. i configured the tool to write the files into a directory in my home. in the config i wrote ~/somewhere ...

after running the tool, i discovered a literal directory named "~".

that's wrong i thought, fixed the config and proceded to remove the offending directory:

rm -r ~

then i waited ...

and waited ...

and i started wondering why removing an almost empty directory is so slow ...

...

...

oh sh!!!!!!

...


Replies

em-bee • today at 9:41 PM

i have no recollection of what i lost that day, but i learned a few lessons:

prefix ambiguous paths with ./

rm -r ./~ would have worked.

don't use rm -r when you can avoid it.

rmdir -p ~/something would have failed without causing damage.

rmdir -p ./~/something would have been the best option.

if there are files but no subdirs inside then

    cd dir
    rm ./* (if there is a more specific wildcard that catches all files then use that)
    cd ..
    rmdir dir
is my preference now.