4 ms·
"Guess what 'rm -rf *' does? That's right, it expands the wildcard and tries to load the gigs and gigs of names of files into memory until it hits swap hell
by greenyoda 11y ago
"Guess what 'rm -rf *' does? That's right, it expands
the wildcard and tries to load the gigs and gigs of names
of files into memory until it hits swap hell, but recursively."
Why not go up to the parent directory and do 'rm -rf dirname'? Then there'd be no wildcard to expand, and 'rm' would just walk the directory removing one file at a time.
- jepler 11y agoSo I set up a cloud instance (20GB disk, 512MB RAM) and tried this. $ find . Killed $ ls ls: Memory exhausted but indeed, cd'ing up a level and rm-rf'ing the directory full of files seems to succeed--my 'strace rm -rf' is busy spewing unlinkat() syscalls right now.
- dozzie 11y agoThat's right. And even if we assume `rm' does build those gigabytes, `find | xargs' should not. xargs is smart enough to build commands with chunk of the input and execute them one by one. The job can also be done with one of the several programming languages, Perl oneliner being my choice. Actually, this could be a good interview riddle, along the lines of fixing `chmod a-x /bin/chmod'.