On Sun, Dec 12, 2004 at 06:10:30PM +0000, Graham wrote:
Probably a simple one, but I can't figure it...
I want to do some conversions on a set of files in a directory, such as
for file in * do do_something_with $file done
However, I want to do the files in date order, not alphabetically, so I tried
for file in $(ls -tr) etc.
But this only works if the files don't have spaces in their names; "for" breaks them up into space-delimited tokens, which is no use at all. How do I do this (apparently) simple thing?
I'd solve it with find (and printf), sort, cut, and then xargs. I'd use find to printf the modified date as YYYYMMDDHHMMSS filename, then pipe that output through sort -g, then use xargs to run the command, use --replace and {} if your command can only work on one file at a time.
Hope that gives you a good pointer.
Thanks,