Solarisでgzのファイルを除外する方法

Solarisでgzのファイルを除外する方法

Solarisでgzを使用するときにファイルを除外する方法:gzディレクトリにサブディレクトリを含めたい場合は、/ tempディレクトリと* .gzファイルを除外します。これが私が今まで使ったものです。

tar -cvf api_v2.x.tar.gz --exclude *.gz --exclude ./temp api

これには除外されたフォルダが含まれます。

ベストアンサー1

Solarisコマンドには、ファイル/ディレクトリを除外するスイッチがtarあります。使い方はXマニュアルページをご覧ください。man tar

マニュアルページから:

X

Exclude.  Use the exclude-file argument as a file containing a list
of relative path names for files (or directories)  to  be  excluded
from the tarfile when using the functions c, x, or t. Be careful of
trailing white spaces. Also beware of leading white spaces,  since,
for each line in the excluded file, the entire line (apart from the
newline) is used to match against the initial string  of  files  to
exclude. Lines in the exclude file are matched exactly, so an entry
like "/var" does not exclude the /var directory if tar  is  backing
up  relative  pathnames.  The entry should read "./var" under these
circumstances. The tar command does not expand shell metacharacters
in the exclude file, so specifying entries like "*.o" does not have
the effect of excluding all files with names suffixed with ".o". If
a  complex list of files is to be excluded, the exclude file should
be generated by some means such as the find(1) command with  appro-
priate conditions.

Multiple  X  arguments can be used, with one exclude-file per argu-
ment. In the case where included files (see -I  include-file  oper-
and)  are  also  specified, the excluded files take precedence over
all included files. If a file is specified in both the exclude-file
and the include-file (or on the command line), it is excluded.

最初の段落の最後の文を参照してください。

複雑なファイルのリストを除外するには、適切な条件を使用して find(1) コマンドと同じ方法で除外ファイルを生成する必要があります。

gtar最新のSolarisバージョンには、対応するマニュアルページで使用できるGNU tarもありますman gtar。このバージョンの特徴--exclude=PATTERN

はい

使用例tar:

/tmp$ find api/
api/
api/a.gz
api/temp
api/temp/b
api/b

/tmp$ cat api/exclude_from_tar 
api/a.gz
api/temp

/tmp$ tar cvfX api.tar api/exclude_from_tar api
a api/ 0K
a api/a.gz excluded
a api/temp excluded
a api/exclude_from_tar 1K
a api/b 0K

/tmp$ tar tf api.tar 
api/
api/exclude_from_tar
api/b

使用例gtar:

/tmp$ gtar cvf api.tar --exclude="*.gz" --exclude=temp api
api/
api/exclude_from_tar
api/b

/tmp$ tar tf api.tar 
api/
api/exclude_from_tar
api/b

おすすめ記事