【发布时间】:2013-08-26 11:35:00
【问题描述】:
如何对目录中的所有文件进行排序?
我本可以在 python 中完成,但它似乎太麻烦了。
import os, glob
d = '/somedir/'
for f in glob.glob(d+"*"):
f2 = f+".tmp"
# unix~$ cat f | sort > f2; mv f2 f
os.system("cat "+f+" | sort > "+f2+"; mv "+f2+" "+f)
【问题讨论】:
标签: file unix sorting directory cat