News for hackers. Stuff that matters.
Re:Useful Perl one-liners (2013) by vesinisa on Tuesday November 29, 2016 @01:15PM (#13064916)
I think you can achieve exactly the same without pipes with:

> find . -name whatever\* -type f -print -delete

... except this variation should be safe with filenames containing the '\n' character (which is perfectly legal on most UNIXes).

Re:Useful Perl one-liners (2013) by tyingq on Tuesday November 29, 2016 @01:59PM (#13065336)
Ahh, yes, files with newlines.

You can use find -print0 | perl -0ne 'print($_);' ... using a null instead of newlines.

You're correct that -delete is easier in this case, but the perl one liner is handy (as a starting point) if you're doing something conditional, or changing file extensions in bulk, etc.

Re:Useful Perl one-liners (2013) by JadeNB on Tuesday November 29, 2016 @01:24PM (#13064988)
> > 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), 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 …).
Re:Useful Perl one-liners (2013) by EvilTerran on Tuesday November 29, 2016 @06:11PM (#13067001)
> 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 ;)
Re:Useful Perl one-liners (2013) by a_gopher on Tuesday November 29, 2016 @06:43PM (#13067222)

  perl -E 'sub x{say;for(<$_/*>){&x;unlink}};x for@ARGV' *

  perl -E 'push@ARGV,<$_/*>for@ARGV;say,unlink for@ARGV' *
Re:Useful Perl one-liners (2013) by EvilTerran on Wednesday November 30, 2016 @04:48AM (#13069534)
Isn'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.

Re:Useful Perl one-liners (2013) by a_gopher on Wednesday November 30, 2016 @06:20PM (#13075600)
fair. not quite so pretty now...

  perl -E 'for(@ARGV){say,unlink for<$_/whatever*>;push@ARGV,($_)x(-d^-l)for<$_/*>}' .
Re:Useful Perl one-liners (2013) by tyingq on Tuesday November 29, 2016 @01:37PM (#13065132)
That doesn't recurse into subdirectories.