我有一个目录中,我将与日期格式(年月日)某些文件夹如下图所示 -如何查找目录中的最新日期文件夹,然后在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