我有一個目錄中,我將與日期格式(年月日)某些文件夾如下圖所示 -如何查找目錄中的最新日期文件夾,然後在shell腳本中構建命令?
[email protected]:/database/batch/snapshot$ ls -lt
drwxr-xr-x 2 app kyte 86016 Oct 25 05:19 20141023
drwxr-xr-x 2 app kyte 73728 Oct 18 00:21 20141016
drwxr-xr-x 2 app kyte 73728 Oct 9 22:23 20141009
drwxr-xr-x 2 app kyte 81920 Oct 4 03:11 20141002
現在我需要從/database/batch/snapshot
目錄提取最新日期的文件夾,然後在我的殼構造的命令像這樣的腳本 -
./file_checker --directory /database/batch/snapshot/20141023/ --regex ".*.data" > shardfile_20141023.log
下面是我的shell腳本 -
#!/bin/bash
./file_checker --directory /database/batch/snapshot/20141023/ --regex ".*.data" > shardfile_20141023.log
# now I need to grep shardfile_20141023.log after above command is executed
如何找到最新的日期文件夾並在shell腳本中構建上述命令?
'我如何找到最新的日期文件夾:'?如果:$(ls-1t | head -n 1)'? – 2014-10-28 04:37:54
[在bash中獲取最新的目錄到變量](http://stackoverflow.com/questions/9275964/get-the-newest-directory-in-bash-to-a-variables) – tripleee 2014-10-28 04:38:25
它有可能重複以日期格式與最近的 – john 2014-10-28 04:42:02