CentOS8のtarオプションでひかっかる

CentOS8でファイルのバックアップをtarでやろうとしたら失敗した話。

【環境】
CentOS-7:tar-1.26-35.el7.x86_64
CentOS-8:tar-1.30-4.el8.x86_64


こんなファイルがあるディレクトリにて。

$ ls
aaa.txt  bbb.txt  ccc.tmp

.tmp のファイルは除外したいので、以下のように実行。

$ tar zcf backup.tar.gz ./* --exclude *.tmp

CentOS7までは、これで問題なかった。
が、CentOS8では次のようなエラーが出る。

tar: The following options were used after any non-optional arguments in archive create or update mode.  These options are positional and affect only arguments that follow them.  Please, rearrange them properly.
tar: --exclude `ccc.tmp' has no effect
tar: 前のエラーにより失敗ステータスで終了します

--exclude を書く位置が、cf より前になければいけない模様。

書き直して実行してみると、

$ tar --exclude *.tmp zcf backup.tar.gz ./*
tar: '-Acdtrux', '--delete' または '--test-label' オプションのうち、いずれか 1つを指定しなければなりません
より詳しい情報は 'tar --help' または 'tar --usage' で.

違うエラーが出た。

ちょっとネットで調べてみると、ハイフンがいるのか・・・
ということで以下が大丈夫な例。

$ tar --exclude *.tmp -zcf backup.tar.gz ./*

中身を確認すると、.tmp は除外されている。

$ tar zft backup.tar.gz
./aaa.txt
./bbb.txt


上記のエラーを調べた時、以下の記事を読んだ。

お前のtarオプション指定は古い - Qiita

ハイフンが無いのは古いのね(´・ω・`)