Linux - 按添加日期执行目录中的所有 Bash 脚本

标签 linux bash shell command-line

我正在寻找一个脚本,该脚本将按添加顺序执行给定目录中的所有 bash 脚本。例如,最早添加到目录中的脚本将首先执行。

这就是我现在使用的,但它似乎没有按添加日期执行脚本。

for each in /dir/*.sh; 
do 
    bash $each > /dev/null 2>&1 ; 
    rm $each > /dev/null 2>&1 ; 
done ;

请告诉我如何修改它以按添加日期对目录中的文件进行排序。

最佳答案

如果您的意思是“按创建顺序”:

ls -ctr /dir/*.sh | while read script
do
  bash $script > /dev/null 2>&1
  rm $script > /dev/null 2>&1
done

关于Linux - 按添加日期执行目录中的所有 Bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14302909/

相关文章:

unix - 给定开始和结束行号,从文件中获取一系列行

bash - 在 bash 中计算一行中的逗号

shell - 有没有办法在运行脚本时自动输入?

regex - 如何在 awk 命令中支持不常见的字符

python - 在 CentOS 6.7 上安装 python33 时出错

bash - 从 Applescript 中运行 bash 脚本

linux - bash 脚本 Heredoc + FTP 错误

bash - 调查bash脚本中cURL返回000错误代码的原因

php - Linux进程死掉后重新启动

linux - 如何通过 ssh 区分目录