DEV Community

Discussion on: 9 Evil Bash Commands Explained

Collapse
 
dwd profile image
Dave Cridland

Ah. So rm -i is often seen as a solid protection, but it's really not.

rm asks in some cases anyway, particularly cases such as where you own the directory bu not the files within it. Those are outstanding cases, and using -i means these no longer stand out.

Secondly, I find it encourages people to use -f a lot, which is just bad behaviour outside of scripts. -f really shouldn't be used in an interactive shell - exceptional cases will no longer be asked about, and errors are lost.

Thirdly, try this, probably in an isolated environment like a docker container:


mkdir experimental-directory
cd experimental-directory
touch very-important-file
touch ./-f

# Now we want to delete files, but we'll rely on -i to avoid
# deleting the very important file.

rm -i *
ls

# Ooops...

I'll leave how to safely delete that -f file as an exercise for the reader...

Collapse
 
devmount profile image
Andreas

Wow, I didn't know that it's working like that! Thank you for pointing out, that -i is no solid protection.