in reply to UNIX command - remove 0 byte file

Here's a command-line version of bart's excellent solution:

src]$ mkdir empty; cd empty; touch {a,b,c}.{a,b,c} empty]$ echo foo > d.d empty]$ ls a.a a.b a.c b.a b.b b.c c.a c.b c.c d.d empty]$ perl -e'-f and !-s _ and unlink for @ARGV' *.* empty]$ ls d.d empty]$
Slightly golfier is good on the command line; this is marginally shorter and calls unlink only once, on a list,
empty]$ perl -e'unlink grep -f && !-s _, @ARGV' *.*
If you don't have to worry about named pipes and other filesystem exotica, you can reduce that to,
empty]$ perl -e'unlink grep !-s, @ARGV' *.*
since directories are at least one block long.

After Compline,
Zaxo

Replies are listed 'Best First'.
OT: Re^2: UNIX command - remove 0 byte file
by osunderdog (Deacon) on Sep 23, 2005 at 12:04 UTC

    Whoa, you never know what little tid bits you'll find lying around the monestary. I never knew about the shell {1,2,3}.{a,b,c} construct.

    Bravo!

    Hazah! I'm Employed!

      Glad you like it. That works with perl glob, too.

      $ perl -e'print "@{[glob q({c,t}{a,o}{t,re})]}$/"' cat care cot core tat tare tot tore $

      After Compline,
      Zaxo