试图忽略以“。”开头的文件。但脚本不起作用

时间:2013-09-29 21:51:04

标签: bash terminal

有一个问题,希望我只是犯了一个愚蠢的错误。

我有一个脚本,我正在搜索指定的mxf文件。与此同时,我尝试忽略以句点(。)开头的文件,因为这些是我不需要搜索的隐藏文件。我不确定我在编写脚本时遇到了什么问题。当我的脚本搜索驱动器并运行到我没有权限并且试图忽略的文件或文件夹时,我一直收到错误。有人可以帮忙吗?脚本如下。

echo Searching for digitized INTV footage...
find /Volumes/TestingTranscode*           \
    -type f \(                            \
        -iname "*V01.*.mxf" !             \
        -iname "Avid_Mob*" !              \
        -iname ".*" !                     \
        -ipath "*Creating*"               \
    \)                                    \
    -exec /Users/admin/TestingTranscode/01_BashScripts/postfind_gw_digitize.sh {} \;

2 个答案:

答案 0 :(得分:0)

使用剪枝开关排除完整的子树:

找到。 -name“。*” - prune -o ...

我认为类似的事情应该有效:

find /Volumes/TestingTranscode*           \ 
    -name ".*" -prune -o \
    -type f \(                            \
        -iname "*V01.*.mxf" !             \
        -iname "Avid_Mob*" !              \
        -ipath "*Creating*"               \
    \)                                    \
    -exec
    -/Users/admin/TestingTranscode/01_BashScripts/postfind_gw_digitize.sh {}
    -/\;

答案 1 :(得分:0)

快速提问:

如果文件没有,你应该下载以句点开头的目录吗?或者,您是否也想要排除以句点开头的目录?

排除所有以句点开头的文件:

$ find . \! -name ".*" -type f

排除任何以句点开头的文件或目录:

$ find . \! -path "*/.*" -name "*.mfx" -type f

如果你太过花哨,你最好切换到像Perl这样的东西:

#! /usr/bin/env perl
use strict;
use warnings;
use File::Find;
use feature qw(say);

find ( sub {
          return unless -f;                       # Must be a file
          return if $File::Find::Name =~ m|/\.|;  # Remove files & dirs that starts with "."
          return unless /\.mfx$/i;                # Only MFX files
          return ....                             # More requirements....
          say $File::Find::name;
      }, "."
 );

当事情变得过于复杂时,大约1/2打左右的脚本将为您节省大量精力来尝试使find命令语法正确。