我有一个目录,其中有一些日期格式为(YYYYMMDD)的文件夹,如下所示-
david@machineX:/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
目录中提取最新的date文件夹,然后像这样在我的shell脚本中构造命令-
./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
如何在外壳程序脚本中找到最新的日期文件夹并构造以上命令?
看,这是方法之一,仅grep仅包含8位数字的文件夹:
ls -t1 | grep -P -e "\d{8}" | head -1
或者
ls -t1 | grep -E -e "[0-9]{8}" | head -1
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句