How to copy, move and delete files in your shell the safe way
There’s a saying that it’s sometimes hard to see the forest for the trees. The flag
-i, --interactive for the commands
-I, --interactive=<never, once or always> for
rm is one of those occurrences.
It has been lurking in front of my face for all these years and yet I took me forever before noticing it. The flag simply makes
mv ask for confirmation before they overwrite any files or folders. Like this:
$ mv -i dog.txt cat.txt mv: overwrite 'cat.txt'?
$ cp -i cat.txt dog.txt cp: overwrite 'dog.txt'?
$ rm -i * zsh: sure you want to delete all 2 files in /home/johan/test [yn]?
This flag have actually saved me a few times. I highly recommend adding aliases for them so you never forget to use the flags:
alias cp='cp -i' alias mv='mv -i' alias rm='mv -I'
You might have notice that the flag for
rm have a capital “i”. This means that it will prompt once before removing more than three files or when removing recursively. If you want to prompt for every single file you just replace it with the flag