Unix find命令执行时的进度条 [英] Progress bar while Unix find command is executing

查看:154
本文介绍了Unix find命令执行时的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Unix shell脚本,该脚本正在执行耗时的 find 命令。直到执行为止,我的脚本似乎没有响应。但是它实际上是在现实中运行。
如何添加进度条或打印点,直到执行 命令?

I have a simple Unix shell script which is executing a time-consuming find command. Till it executes, my script appears non-responsive. However it's actually running in reality. How can I add a progress bar or print dots till the find command is executing?

I要打印一些点或哈希,直到执行函数 doSomething

I want to print some dots or hash till the function doSomething is executing.

function doSomething()
{
  # Time-consuming 'for' loop below
  for var in `find XXXXXX`
  do
      # Some more processing
  done;
}

# Call the function doSomething. Need the progress DOTS till doSomething is executing
doSomething

# Remaining script processing

我尝试过使用google,但是没有一种解决方案适合我想要实现的目标。有建议吗?

I have tried to google, but none of the solutions fits what I am trying to achieve. Any suggestions?

推荐答案

目前尚不清楚OP中的find命令选择了多少文件,以及是否执行了某些操作

It's not clear from the OP how many files are selected by the find command, and if the do-something has any significant impact on the overall processing time.

假定其中一种常见情况,其中(1)查找将扫描大量文件夹(2)相对较少的匹配项,并且(3)每个文件处理很少,可以通过记录扫描目录来创建进度指示。

Assuming one of the common cases, where (1) find will scan large number of folders (2) relatively small number of matches and (3) little processing for each file, it is possible to create progress indication by logging directory that are scanned.

如果原始查找使用的是 find STARTING-POINT ... FIND-EXPRESSION ,则修改后的命令为 find STARTING-POINT'(' LOGGING-EXPRESSION')'-o'(FIND-EXPRESSION')'

If the original find was using find STARTING-POINT ... FIND-EXPRESSION, the modified command is find STARTING-POINT '(' LOGGING-EXPRESSION ')' -o '( FIND-EXPRESSION ')'.

只要发现开始扫描,以下脚本将生成进度报告一个新文件夹。请注意,如果原始查找依赖于隐式-print,则FIND-EXPRESSION应该包含显式的 -print。

Following script will produce a progress report whenever find start scanning a new folder. Note that FIND-EXPRESSION should include explicit '-print', if the original find was relying on the implicit -print.

find STARTING-POINT   \
     '(' -type d -maxdepth 3 -fprintf /dev/stderr "Processing: %p" ')'   \
     -o \
     '(' FIND-EXPRESSION ')'

# Single Line
find STARTING-POINT '(' -type d -maxdepth N -fprintf /dev/stderr "Processing\n: %p" ')' -oo '(' FIND-EXPRESSION ')'

以上内容将记录每个扫描的文件夹(

The above will log each scanned folder (up to N level deep) to stderr.

示例:

# Find all '*.py' files on the system, showing '*' for each folder
find / '(' -type d -fprintf /dev/stderr "*" ')' -o '(' -name '*.py' -print ')'

# Find system '*.so' files, showing each folder scanned
find /lib /usr/lib '(' -type d  -fprintf /dev/stderr "Scanning: %p" ')' -o '(' -name '*.so' -print ')'

lo的其他自定义可以执行gging-使用日志过滤器中的 -regex或 -path

Additional customization to the logging can be performed - Using the '-regex' or '-path' in the logging filter

这篇关于Unix find命令执行时的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆