AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / unix / Perguntas / 407696
Accepted
ryanbrainard
ryanbrainard
Asked: 2017-11-30 01:59:32 +0800 CST2017-11-30 01:59:32 +0800 CST 2017-11-30 01:59:32 +0800 CST

bsdtar: Como evitar sobrescrever as informações do arquivo existente?

  • 772

bsdtartem uma -k (Do not overwrite existing files)opção que evita alterar o conteúdo de qualquer arquivo existente, mas ainda sobrescreve as informações do arquivo (por exemplo, permissões) com o que está no arquivo. Existe uma maneira de bsdtarignorar completamente a substituição de arquivos existentes, deixando as informações do arquivo intactas da mesma forma que a --skip-old-filesopção funciona no GNU tar?

Aqui está um script que demonstra o problema:

#!/usr/bin/env bash

echo -e "\nCreate an archive with normal files"
rm -rf test-tar
mkdir test-tar
echo "TEST CONTENTS 1" > test-tar/1.txt
echo "TEST CONTENTS 2" > test-tar/2.txt
ls -la test-tar
bsdtar -czf test.tgz test-tar

echo -e "\nChange contents and permissions of one of the files"
echo "MORE CONTENTS" >> test-tar/2.txt
chmod 000 test-tar/2.txt
ls -la test-tar

echo -e "\nUntar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed"
bsdtar -xzkf test.tgz
ls -la test-tar
cat test-tar/2.txt

echo -e "\nUntar the archive without -k"
bsdtar -xzf test.tgz
ls -la test-tar
cat test-tar/2.txt

Aqui está a saída do script:

Create an archive with normal files
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 29 17:53 .
drwxr-xr-x  14 rbrainard  wheel  476 Nov 29 17:53 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 1.txt
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 2.txt

Change contents and permissions of one of the files
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 29 17:53 .
drwxr-xr-x  14 rbrainard  wheel  476 Nov 29 17:53 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 1.txt
----------   1 rbrainard  wheel   30 Nov 29 17:53 2.txt

Untar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 29 17:53 .
drwxr-xr-x  14 rbrainard  wheel  476 Nov 29 17:53 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 1.txt
-rw-r--r--   1 rbrainard  wheel   30 Nov 29 17:53 2.txt
TEST CONTENTS 2
MORE CONTENTS

Untar the archive without -k
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 29 17:53 .
drwxr-xr-x  14 rbrainard  wheel  476 Nov 29 17:53 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 1.txt
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 2.txt
TEST CONTENTS 2

Minha bsdtarversão é 3.3.2.

tar gnu
  • 1 1 respostas
  • 434 Views

1 respostas

  • Voted
  1. Best Answer
    ryanbrainard
    2017-12-04T19:43:55+08:002017-12-04T19:43:55+08:00

    Acontece que isso é um bug. Eu postei para libarchive-discuss e um dos mantenedores respondeu como tal. Arquivou um problema em: https://github.com/libarchive/libarchive/issues/972

    • 1

relate perguntas

  • gpg — o comando list-keys gera uid [ desconhecido ] depois de importar a chave privada para uma instalação limpa

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Matriz JSON para bash variáveis ​​usando jq

    • 4 respostas
  • Marko Smith

    A data pode formatar a hora atual para o fuso horário GMT? [duplicado]

    • 2 respostas
  • Marko Smith

    bash + lê variáveis ​​e valores do arquivo pelo script bash

    • 4 respostas
  • Marko Smith

    Como posso copiar um diretório e renomeá-lo no mesmo comando?

    • 4 respostas
  • Marko Smith

    conexão ssh. Conexão X11 rejeitada devido a autenticação incorreta

    • 3 respostas
  • Marko Smith

    Como baixar o pacote não instalá-lo com o comando apt-get?

    • 7 respostas
  • Marko Smith

    comando systemctl não funciona no RHEL 6

    • 3 respostas
  • Marko Smith

    rsync porta 22 e 873 uso

    • 2 respostas
  • Marko Smith

    snap /dev/loop em 100% de utilização -- sem espaço livre

    • 1 respostas
  • Marko Smith

    chave de impressão jq e valor para todos no subobjeto

    • 2 respostas
  • Martin Hope
    EHerman Matriz JSON para bash variáveis ​​usando jq 2017-12-31 14:50:58 +0800 CST
  • Martin Hope
    Christos Baziotis Substitua a string em um arquivo de texto enorme (70 GB), uma linha 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Drux A data pode formatar a hora atual para o fuso horário GMT? [duplicado] 2017-12-26 11:35:07 +0800 CST
  • Martin Hope
    AllisonC Como posso copiar um diretório e renomeá-lo no mesmo comando? 2017-12-22 05:28:06 +0800 CST
  • Martin Hope
    Steve Como as permissões de arquivo funcionam para o usuário "root"? 2017-12-22 02:46:01 +0800 CST
  • Martin Hope
    Bagas Sanjaya Por que o Linux usa LF como caractere de nova linha? 2017-12-20 05:48:21 +0800 CST
  • Martin Hope
    Cbhihe Altere o editor padrão para vim para _ sudo systemctl edit [unit-file] _ 2017-12-03 10:11:38 +0800 CST
  • Martin Hope
    showkey Como baixar o pacote não instalá-lo com o comando apt-get? 2017-12-03 02:15:02 +0800 CST
  • Martin Hope
    youxiao Por que os diretórios /home, /usr, /var, etc. têm o mesmo número de inode (2)? 2017-12-02 05:33:41 +0800 CST
  • Martin Hope
    user223600 gpg — o comando list-keys gera uid [ desconhecido ] depois de importar a chave privada para uma instalação limpa 2017-11-26 18:26:02 +0800 CST

Hot tag

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve