Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 是否可以计算文件的执行次数?_Bash_Shell_Unix - Fatal编程技术网

Bash 是否可以计算文件的执行次数?

Bash 是否可以计算文件的执行次数?,bash,shell,unix,Bash,Shell,Unix,我通常下载大量图像,并经常使用cleanup.sh文件进行清理,该文件只包含rm-rf*命令 我的问题是,我想知道一个人做了多少次。比如说,在另一个文件中,我想附加该文件已执行的信息。 他们有办法吗 在cleanup.sh中,您可以执行rm-rf*&&date>>cleanup.runs.log。这样,无论何时运行它,日期/时间都会写入日志文件,您可以使用日志文件计算脚本的执行次数和时间。在cleanup.sh中,您可以执行rm-rf*&&date>>cleanup.runs.log。这样,无论

我通常下载大量图像,并经常使用cleanup.sh文件进行清理,该文件只包含
rm-rf*
命令

我的问题是,我想知道一个人做了多少次。比如说,在另一个文件中,我想附加该文件已执行的信息。
他们有办法吗

在cleanup.sh中,您可以执行
rm-rf*&&date>>cleanup.runs.log
。这样,无论何时运行它,日期/时间都会写入日志文件,您可以使用日志文件计算脚本的执行次数和时间。

在cleanup.sh中,您可以执行
rm-rf*&&date>>cleanup.runs.log
。这样,无论何时运行它,日期/时间都会写入日志文件,您可以使用日志文件计算脚本的执行次数和时间。

在cleanup.sh中,您可以执行
rm-rf*&&date>>cleanup.runs.log
。这样,无论何时运行它,日期/时间都会写入日志文件,您可以使用日志文件计算脚本的执行次数和时间。

在cleanup.sh中,您可以执行
rm-rf*&&date>>cleanup.runs.log
。这样,无论何时运行,日期/时间都会写入日志文件,您可以使用日志文件计算脚本执行的次数和时间。

这可能会起作用:

echo "Script was executed" >> logFile
然后,您可以使用
wc-l

计算行数,这可能会起作用:

echo "Script was executed" >> logFile
echo $(($(cat other.file)+1)) > other.file;
然后,您可以使用
wc-l

计算行数,这可能会起作用:

echo "Script was executed" >> logFile
echo $(($(cat other.file)+1)) > other.file;
然后,您可以使用
wc-l

计算行数,这可能会起作用:

echo "Script was executed" >> logFile
echo $(($(cat other.file)+1)) > other.file;
然后您可以使用
wc-l

echo $(($(cat other.file)+1)) > other.file;
  • $(cat other.file)
    读取
    other.file的内容
  • $(…+1))
    将其递增1
  • echo…>other.file
    将结果写回
    other.file
当然,这需要您创建一个包含内容为
0
的初始
other.file

  • $(cat other.file)
    读取
    other.file的内容
  • $(…+1))
    将其递增1
  • echo…>other.file
    将结果写回
    other.file
当然,这需要您创建一个包含内容为
0
的初始
other.file

  • $(cat other.file)
    读取
    other.file的内容
  • $(…+1))
    将其递增1
  • echo…>other.file
    将结果写回
    other.file
当然,这需要您创建一个包含内容为
0
的初始
other.file

  • $(cat other.file)
    读取
    other.file的内容
  • $(…+1))
    将其递增1
  • echo…>other.file
    将结果写回
    other.file


当然,这需要您创建一个包含内容
0

的初始
other.file
,或者用于相同目的。但是,他需要对系统日志进行grep,可能会有多个,因为roundup和旧值最终将被删除。或者用于相同的目的。但是,他需要对系统日志进行grep,可能会有多个,因为roundup和旧值最终将被删除。或者用于相同的目的。但是,他需要对系统日志进行grep,可能会有多个,因为roundup和旧值最终将被删除。或者用于相同的目的。但是,他需要对系统日志进行grep处理,可能有多个,因为roundup和旧值最终将被删除。如果将输出重定向到同一个文件,则从other.file读取是不安全的。请看这个问题:在本例中,这没关系,因为命令替换是在输入重定向之前计算的。类似于
cat foo.txt>foo.txt
@Lynch的问题只会出现在读取结束之前开始写入时。猫的情况并非如此。谢谢@Siguza,它工作得非常好。非常感谢。@chepner你说得对。我在strace中对它进行了测试,它清楚地表明在调用echo之前对子进程的结果进行了评估:
$strace echo$(($(cat other.file)+1))>other.file execve(“/bin/echo”、[“echo”、“6”]、[/*74 vars*/])=0
。如果将输出重定向到同一个文件,则从其他.file读取my bad.it是不安全的。请看这个问题:在本例中,这没关系,因为命令替换是在输入重定向之前计算的。类似于
cat foo.txt>foo.txt
@Lynch的问题只会出现在读取结束之前开始写入时。猫的情况并非如此。谢谢@Siguza,它工作得非常好。非常感谢。@chepner你说得对。我在strace中对它进行了测试,它清楚地表明在调用echo之前对子进程的结果进行了评估:
$strace echo$(($(cat other.file)+1))>other.file execve(“/bin/echo”、[“echo”、“6”]、[/*74 vars*/])=0
。如果将输出重定向到同一个文件,则从其他.file读取my bad.it是不安全的。请看这个问题:在本例中,这没关系,因为命令替换是在输入重定向之前计算的。类似于
cat foo.txt>foo.txt
@Lynch的问题只会出现在读取结束之前开始写入时。猫的情况并非如此。谢谢@Siguza,它工作得非常好。非常感谢。@chepner你说得对。我在strace中对它进行了测试,它清楚地表明在调用echo之前对子进程的结果进行了评估:
$strace echo$(($(cat other.file)+1))>other.file execve(“/bin/echo”、[“echo”、“6”]、[/*74 vars*/])=0
。如果将输出重定向到同一个文件,则从其他.file读取my bad.it是不安全的。看这个问题:在这种情况下,是O