If I use rm -rfi, this asks me every time each file is deleted. If I have a list of rm -rf commands, how can I make it so that the machine asks me for confirmation just once (when trying to delete the directory itself)


With some rm implementations (DragonFly BSD where it comes from, FreeBSD and GNU at least), the -I (capital i) is what you are looking for. -i asks for confirmation for every file, while the -I (capital i) ask for confirmation once when files are more than 3 or you are deleting recursively.

zsh -c 'rm -f -- **/*(^/)'
rm -ri -- *

This will recursively (**/) remove everything (*) that isn't a directory (^/) with zsh; then use your existing shell to interactively remove what's left (directories). To include dotfiles in the initial removal, use:

zsh -c 'rm -f -- **/*(D^/)'

followed by:

rm -ri -- *

Try this, Well this could be a wild solution, but wanted to share anyway!

# function rm_ {
   [[ -d $1 ]] && rm -rI $1 || rm -f $1; 

Then use rm_ <directory|file>. If its directory you get rm: remove all arguments recursively? , else nothing and the file would be deleted.

This way , there will be no prompt to user while deleting files, as well as the user gets a prompt while deleting a directory.

If only rm -rI were to be used , user gets confirmation prompt for both files and directories and so I used a combination of both rm -f and rm -rI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.