Have you let xargs into your life? xargs is designed to get around the shell's limitation of the number of arguments a program can take. xargs takes lines of input and turns them into commandline arguments:
repeatedly runs the chmod command with a bunch of filenames per invocation until all the output of ls is consumed.ls -1 | xargs chmod 755
But xargs has a fatal flaw. Spaces in filenames screw it up.
So my shell idiom of choice is now something like:
(though I'd use Perl's built-in chmod rather than shelling out, in this case).ls -1 | perl -e 'chomp(@args = <>); while (@args) { @a = splice(@args, 0, 50); system("chmod", "755", @args) }'
The case that inspired it was fixing the id3 tags on my mp3 files:
Change 50 to however many arguments per command you want.find . -name \*.mp3 -print | perl -e 'chomp(@args=<>); while (@args) { @a = splice(@args, 0, 50); system("id3convert", @a) }'
--Nat
Re:Spaces in filenames
rafael on 2002-08-28T07:20:28
If you have GNU ls, you can use -Q.ls -Q | xargs chmod 755
If you don't have it, you know the motto : Get New Utilities.
Re:Spaces in filenames
jdavidb on 2002-08-28T13:13:30
+1, informative
Re:Spaces in filenames
oneiron on 2002-08-28T08:49:54
I have been using xargs with space-riddled filenames for many years, as shown by examples below:
find . -print0|xargs -0 chmod 755 (GNU only)
find . -print|sed 's//\\ /g'|xargs chmod 755 (works everywhere)
Re:Spaces in filenames
gnat on 2002-08-28T16:25:55
Well bugger, I live and I learn! Thanks to everyone who pointed out print0.Well, the Perl idiom of sucking a bunch of array elements off at a time still stands, but now I feel SUPERHUMAN with my new-found shell fu.
use.perl to the rescue!
--Nat