samedi 2 juillet 2016

rm alias to calculate size of files to be deleted and confirm deletion

I would like a bash and tcsh alias for rm that does:

  1. uses the FILE list from rm command to calculate the size of the files to be deleted
  2. asks the user if they really want to delete that much data
  3. if yes, then execute the rm command. if no, then exit.

e.g. suppose 'du -shc data/* | tail -1' return "56 GB total":

$ rm -rf data/*
Are you sure you want to delete 56 GB total? (y/n) n
Nothing deleted
$ rm -rf data/*
Are you sure you want to delete 56 GB total? (y/n) y
executing rm -rf data/*
$

Aucun commentaire:

Enregistrer un commentaire