Fraser Campbell <[EMAIL PROTECTED]> [2003-01-04 21:51:21 -0500]: > On January 4, 2003 09:20 pm, the fabulous Gerald V. Livingston II wrote: > > > Thank you. Took a couple of tries to get the syntax correct but I > > ended up with this: > > > > if [ `ls *.jpg 2>/dev/null|wc -l` -gt 0 ] > > then for i in *.jpg; do mmv "$i" `date +%s`-$a.jpg; a=a+1; done > > fi
What does 'mmv' buy you over using the more standard 'mv' in this example? Just curious. You were not using any of the mmv features that I could tell here. > If there were thousands of jpgs you'll probably still get a "too many > arguments" error with that for loop. I usually do something like this: > > ls *.jpg | while read i; do > mv "$i" `date +%s`-$a.jpg; a=a+1 > done > > If there are no files, no problem, if there are 10,000 files also no problem > (although there might be a faster way?). That works. I prefer 'xargs' myself. Consider this alternative, not replacement, example. Also you do have the shell to help you out with your unique name generation and I don't. (Of course I only have the 'echo' there for testing because I am paranoid that someone would cut and paste this literally.) The {} is replaced with each name read from standard input in turn. find . -name '*.jpg' -print0 | xargs -r0 -i echo mv {} /path/to/there/ However, if this is a command that is run frequently as I seem to recall the OP saying earlier in this thread then I would assume that it would not be possible to get up to ARG_MAX and would do the simpler for loop above. Bob
msg22452/pgp00000.pgp
Description: PGP signature