Skip to main content

Große Ordner löschen (rm -rf)

Mit rm (inklusive Fortschrittsanzeige und Log)

rm -rf /pfad/zum/ordner 2>&1 | tee -a delete.log
  • rm -rf: Löscht rekursiv und ohne Rückfragen.
  • 2>&1: Leitet Fehler- und Standardausgabe zusammen.
  • tee -a delete.log: Zeigt den Vorgang an und schreibt ihn gleichzeitig in eine Logdatei.

Ordner samt Inhalt löschen: 

rm -rf /pfad/zum/ordner 2>&1 | tee -a delete.log

nur Inhalt löschen:

rm -rf /pfad/zum/ordner/* 2>&1 | tee -a delete.log

EDIT: Klappt nicht so recht mit den logs..neue Methode:

https://unix.stackexchange.com/questions/255190/is-it-possible-to-determine-the-progress-of-an-rm-command 

I get the progress bar using pv command line Pipe Viewer

This is the command

rm -rv DIR_OR_FILE_NAME | pv -l -s $( du -a DIR_OR_FILE_NAME | wc -l ) > /dev/null

If you need root permissions for the dir or file to delete,

sudo rm -rv DIR_OR_FILE_NAME | pv -l -s $( sudo du -a DIR_OR_FILE_NAME | wc -l ) > /dev/null
  • rm -rv-r to recursively remove DIRs and files. -v verbose it lists all the files and directories that is removing.

  • pv -l -s-l to count lines instead of bytes. -s set the total lines to be removed.

  • $( du -a <dir_or_file> | wc -l )du -a returns a list all files and directories from the dir specified. wc -l returns the count of lines outputted by du -a.

  • > /dev/null: send the output of rm -rv to nowhere.