Reputation: 173
I want to sort the result of the find as follows:
I am using:
find . -type f -print0
Result is:
/mnt/sdcard/qu/led/t1/temp42.txt
/mnt/sdcard/qu/led/File.plist
/mnt/sdcard/qu/yellow.plist
/mnt/sdcard/SHA1Keys/SHA1SUMS
/mnt/sdcard/File.xml
/mnt/sdcard/File.plist
/mnt/sdcard/.DS_Store
But i want the result as:
/mnt/sdcard/.DS_Store
/mnt/sdcard/File.plist
/mnt/sdcard/File.xml
/mnt/sdcard/SHA1Keys/SHA1SUMS
/mnt/sdcard/qu/yellow.plist
/mnt/sdcard/qu/led/File.plist
/mnt/sdcard/qu/led/t1/temp42.txt
And if i do:
find . -type f print0 | sort -r
The order gets all messed up. I saw this solution somewhere:
find . -type f -ls | awk '{print $(NF-3), $(NF-2), $(NF-1), $NF}'
But I can't use it since it prints the results.
Also note I don't have permissions to write to the filesystem, so writing to a file and reversing the lines is not an option.
Upvotes: 4
Views: 11717
Reputation: 361595
Use tac
(cat
backwards) to reverse output. You don't need to sort it in reverse order, you just need it reversed.
find . -type f | tac
If you want to keep the -print0
then use:
find . -type f -print0 | tac -rs '\0'
Upvotes: 15