3 ms·
> > find . -name whatever\* -type f -print -delete Or you can also do it all in Perl: perl -E 'while (<whatever*>) { say; unlink }' EDIT: As tyingq poin
by JadeNB 10y ago
> > find . -name whatever\* -type f -print -delete
Or you can also do it all in Perl:
perl -E 'while (<whatever*>) { say; unlink }'
EDIT: As tyingq points out (https://news.ycombinator.com/item?id=13065132 https://news.ycombinator.com/item?id=13065132), I forgot that `find` recurses into subdirectories. I don't know a way to make Perl do the same that doesn't start getting more verbose (but there must be a Perl golfer somewhere around here who does …).
- tyingq 10y agoThat doesn't recurse into subdirectories.
- EvilTerran 10y ago> there must be a Perl golfer somewhere around here who does … Hello! perl -MFile::Find -e 'find sub{if(-f&&/^whatever/){say$File::Find::name;unlink}},"."' You might even be able to do 'find{...}"."' (no "sub" or ","), but I don't have perl on my phone to test that ;)
- a_gopher 10y agoperl -E 'sub x{say;for(<$_/*>){&x;unlink}};x for@ARGV' * perl -E 'push@ARGV,<$_/*>for@ARGV;say,unlink for@ARGV' *
- EvilTerran 10y agoIsn't that just "rm -rv *"? The original spec was to only delete files, not directories - and only those matching a given pattern, at that. Also, I think yours would go into an infinite spin if it met a symlink loop (say, "ln -s . foo") - File::Find is hardened against that kinda shenanigans.
- a_gopher 10y agofair. not quite so pretty now... perl -E 'for(@ARGV){say,unlink for<$_/whatever*>;push@ARGV,($_)x(-d^-l)for<$_/*>}' .