在 for 循环中排除文件

在 for 循环中排除文件

我想删除 apk 文件中的 /lib 目录。我设法这样做:

for DIR in ~/ABC ~/ABD 
 do
  cd $DIR
   for APK in *
    do
     if test -f "$APK"
      then
       zip -d $APK /lib*
     fi
   done 
done

现在我想排除具有財經或者蒂塔在文件名中。我真的不知道该怎么做。

答案1

-x file|directory|list是你的钥匙

zip -d $APK /lib* -x *vvs* *tita*

从手册页中:

   -x files
   --exclude files
          Explicitly exclude the specified files, as in:

                 zip -r foo foo -x \*.o

          which  will  include the contents of foo in foo.zip while excluding
          all the files that end in .o.  The backslash avoids the shell filename
          substitution, so that the name matching is performed by zip at all
          directory levels.

          Also possible:

                 zip -r foo foo [email protected]

          which will include the contents of foo in foo.zip while excluding all
          the files that match the patterns in the file exclude.lst.

          The long option forms of the above are

                 zip -r foo foo --exclude \*.o

          and

                 zip -r foo foo --exclude @exclude.lst

          Multiple patterns can be specified, as in:

                 zip -r foo foo -x \*.o \*.c

          If there is no space between -x and the pattern, just one value is
          assumed (no list):

                 zip -r foo foo -x\*.o

          See -i for more on include and exclude.

答案2

添加内部 if 语句,使用以下方法之一来确定 $APK 是否包含字符串“vvs”或“tita”

https://stackoverflow.com/questions/2829613/how-do-you-tell-if-a-string-contains-another-string-in-unix-shell-scripting

相关内容