linux - unix find without sort 逆向打印结果

标签 linux shell unix find

我想按如下方式对查找结果进行排序:

我正在使用:

find . -type f -print0 

结果是:

/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

但我想要的结果是:

/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

如果我这样做:

find . -type f print0 | sort -r 

订单全乱了。我在某处看到了这个解决方案:

find . -type f -ls | awk '{print $(NF-3), $(NF-2), $(NF-1), $NF}'

但我不能使用它,因为它会打印结果。

另请注意,我没有写入文件系统的权限,因此写入文件并反转行不是一个选项。

最佳答案

使用tac(cat backwards)来反转输出。不需要倒序排序,倒序即可。

find . -type f | tac

如果你想保留 -print0 然后使用:

find . -type f -print0 | tac -rs '\0'

关于linux - unix find without sort 逆向打印结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19691601/

相关文章:

c - 使用 ptrace 停止或杀死进程中的线程?

c - 使用 pty 使用 GCC 编译时出错

perl - grep 与不包含关键字的后上下文

unix - diff'ing diffs with diff?

linux - cron 作业部分运行

python - 解释性语言如何避免使用全局解释器锁(GIL)?

linux -/proc/xx/map for/bin/bash 的输出

mongodb - 在 MongoDB Shell 中向 ISODate 添加/减去天数

linux - sed 在开头放置圆括号并在第 4 行结束

sockets - SO_REUSEADDR 和 AF_UNIX