Debian のバックスラッシュ付き tar ファイル

Debian のバックスラッシュ付き tar ファイル

Debian 10 Podで(Windowsスタイル)バックスラッシュを含むファイルをコピーする必要があります。GNU tar 1.30バックスラッシュを含むファイルをアーカイブするのに問題があります。

docker run --rm -it debian:10 bash

たとえば、コンテナ内で実行している場合:

touch C\:\\LOG_DOTNET\\1
touch C\:\\LOG_DOTNET\\2

バックスラッシュ付きファイル:

ls -l C\:*

-rw-r--r-- 1 root root 0 Mar 14 17:20 'C:\LOG_DOTNET\1'
-rw-r--r-- 1 root root 0 Mar 14 17:20 'C:\LOG_DOTNET\2'

tarアーカイブにワイルドカードを使用してみてください。

tar cvf a.tar C\:*

tar: C\:\\LOG_DOTNET\001: Cannot stat: No such file or directory
tar: C\:\\LOG_DOTNET\002: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

文字をfind印刷して、以下を試してください。NULxargs

find . -name C\:\* -print0 | xargs -0 tar cvf a.tar

tar: ./C\:\\LOG_DOTNET\002: Cannot stat: No such file or directory
tar: ./C\:\\LOG_DOTNET\001: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

各行を一重引用符で囲みます。

find . -name C\:\* | sed "s/'/'\\\\''/g; s/^/'/; s/$/'/" | xargs tar cvf a.tar

tar: ./C\:\\LOG_DOTNET\002: Cannot stat: No such file or directory
tar: ./C\:\\LOG_DOTNET\001: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

\00私もそれが現れる理由と現れない理由を理解していません\\(私の問題の原因のようです)。

そのようなファイルをコピーするように提供したり注文したりするとkubectl cp役に立ちます。kubectl exec:-)

ベストアンサー1

私はここで答えを見つけました。スーパーユーザーの問題

find . -name C\:\* -print0 | tar --null -T - -cf a.tar 

tarマニュアルから:

--null Instruct subsequent -T options to read null-terminated names verbatim  (disables  special  handling  of
              names that start with a dash).

-T を使用すると、標準入力をソースとして使用できます。 =>テスト:

find -name 'C:*' -print0 |tar --null -T - -cf a.tar
tar tf a.tar 
./C:\\LOG_DOTNET\\2
./C:\\LOG_DOTNET\\1

おすすめ記事