Cracauer
January 9th, 2009, 06:23 PM
If you use find with -print0 (intended to go into xargs -0), how do you sort?
find traverses in order of the directory entries, it's not even alphabetically. Not happy.
Best I can do:
#! /bin/sh
find . -print \
| sort \
| while read foo ; do
# can't use -e here because filename might have funky chars
echo -n "$foo"
# force an echo that understands -e
# in Ubuntu /bin/sh it doesn't
/bin/echo -en '\0'
done
Of course that sorts by directory name first, where what I want is sorting inside a directory.
I really thing find should have an option to sort within a directory.
find traverses in order of the directory entries, it's not even alphabetically. Not happy.
Best I can do:
#! /bin/sh
find . -print \
| sort \
| while read foo ; do
# can't use -e here because filename might have funky chars
echo -n "$foo"
# force an echo that understands -e
# in Ubuntu /bin/sh it doesn't
/bin/echo -en '\0'
done
Of course that sorts by directory name first, where what I want is sorting inside a directory.
I really thing find should have an option to sort within a directory.