How to zero files out inside a VMware image file so that their space can be reclaimed

diskfilesystemsvirtualizationvmware

is there a command on Linux to remove a file but zeroing it's contents first?

so if i do, something like this:

rm -rf /var/cache/pacman/pkg/*

it would overwrite each file on that directory with 0 values, then erase it

i need it for compacting my VMware image files without creating super big file containing zeros first.

Best Answer

The shred command can zero out a file. To do what you want, I think something like this should work

find /var/cache/pacman/pkg -type f -exec shred -n 0 -z {} \; \
    && rm -rf /var/cache/pacman/pkg/*
Related Question