0

我有一堆文件,想根据文件名中表示的日期对它们进行排序,如“2013-03-29_13-56-30”。我正在使用bash.

myapplication-1.0-SNAPSHOT-V2013-03-29_13-56-30.jar
myapplication-1.0-SNAPSHOT-V2013-12-03_17-01-51.jar
myapplication-1.0-SNAPSHOT-V2013-04-04_13-49-58.jar
myapplication-1.0-SNAPSHOT-V2013-04-04_14-25-51.jar
myapplication-1.0-SNAPSHOT-V2013-04-05_10-06-33.jar
myapplication-1.0-SNAPSHOT-V2013-04-05_13-49-49.jar
myapplication-1.0-SNAPSHOT-V2013-08-09_17-48-54.jar
myapplication-1.0-SNAPSHOT-V2013-11-10_09-46-33.jar

谢谢


我不确定,但sort -n似乎足够了,因为我所有文件中的前缀都相同。这个对吗?

4

1 回答 1

2

如果您已经在文件中有文件名,并且它们是无序的,那么sort在 fedorqui 的答案中使用 as 就可以了。但是,如果您在文件系统上有文件,那么您用来枚举它们的任何工具都会为您排序:

$ echo *
myapplication-1.0-SNAPSHOT-V2013-03-29_13-56-30.jar myapplication-1.0-SNAPSHOT-V2013-04-04_13-49-58.jar myapplication-1.0-SNAPSHOT-V2013-04-04_14-25-51.jar myapplication-1.0-SNAPSHOT-V2013-04-05_10-06-33.jar myapplication-1.0-SNAPSHOT-V2013-04-05_13-49-49.jar myapplication-1.0-SNAPSHOT-V2013-08-09_17-48-54.jar myapplication-1.0-SNAPSHOT-V2013-11-10_09-46-33.jar myapplication-1.0-SNAPSHOT-V2013-12-03_17-01-51.jar
$ ls
myapplication-1.0-SNAPSHOT-V2013-03-29_13-56-30.jar
myapplication-1.0-SNAPSHOT-V2013-04-04_13-49-58.jar
myapplication-1.0-SNAPSHOT-V2013-04-04_14-25-51.jar
myapplication-1.0-SNAPSHOT-V2013-04-05_10-06-33.jar
myapplication-1.0-SNAPSHOT-V2013-04-05_13-49-49.jar
myapplication-1.0-SNAPSHOT-V2013-08-09_17-48-54.jar
myapplication-1.0-SNAPSHOT-V2013-11-10_09-46-33.jar
myapplication-1.0-SNAPSHOT-V2013-12-03_17-01-51.jar

现在,可以影响这一点的一件事是LC_COLLATE环境变量。如果您不确定,请将其设置为C.

于 2013-04-10T11:20:02.150 回答