1

The code worked in Debian 8.5 but not in Debian 8.7

 root@masi:/home/masi# nice tar --keep-directory-symlink czf /media/masi/masiDisc/backup_home_27.2.2017.tar.gz /home/masi/

In Debian 8.7, I get with GNU tar 1.27.1

tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' options
Try 'tar --help' or 'tar --usage' for more information.

I can fix it by appending by - the czf but not sure if equivalent

 root@masi:/home/masi# nice tar --keep-directory-symlink -czf /media/masi/masiDisc/backup_home_27.2.2017.tar.gz /home/masi/

OS: Debian 8.7

  • 1
    OpenBSD & FreeBSD tar also behaves like this. AFAIU, using tar czf is incorrect, even though most Linuxes would allow it. – SYN Feb 27 '17 at 18:12
  • @SYN There is a change in the policy from Debian 8.5 to 8.7, since the former command worked before. I will start to use -czf systematically if it is so like you say then. - - Please, make your comment an answer so I can accept it. – Léo Léopold Hertz 준영 Feb 27 '17 at 18:14
  • 1
    Note that on a freshly installed Debian 8.7, I am still able to use tar czf. Version shows: tar (GNU tar) 1.27.1 – SYN Feb 27 '17 at 18:18
  • @SYN Can you do my above command with --keep-directory-symlink? - - I cannot do it in Debian 8.7. – Léo Léopold Hertz 준영 Feb 27 '17 at 18:24
  • 1
    Only if I move that option after the czf filename. Otherwise, you're right, tar fails. – SYN Feb 27 '17 at 18:26

2 Answers2

3

I really started wondering, and I can't reproduce the behavior you claim to have seen in: BusyBox tar, star, libarchive-bsdtar.


(earlier post) The question becomes, which tar were you using? The GNU tar in 8.5/8.7 was NEARLY identical, and both of them cause the same error you saw. What wouldn't cause it would be some other tar being used via Debian alternatives / dpkg-divert, or happened to be elsewhere on your path.

These are the GNU tar versions shipped with each release, as noted by the ISO listings on the Debian FTP:

debian-8.5.0-amd64-CD-1.list.gz:tar_1.27.1-2+b1_amd64.deb
debian-8.7.0-amd64-CD-1.list.gz:tar_1.27.1-2+deb8u1_amd64.deb

They are extremely similar, containing exactly one more patch for CVE-2016-6321. You can see how Debian treated it here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=842339 The patch deals with handling of /../ path entries in the tarball, and does not affect the handling of arguments.

If we get both debs (In my case I pulled them from the netinst iso), and extract the tar binaries, we can test the behavior:

$ for i in tar_1.27.1-2+b1_amd64 tar_1.27.1-2+deb8u1_amd64 ; do \
  ls -la ${i}.deb && \
  deb2targz ${i}.deb && \
  mkdir -p $i && \
  tar -xf ${i}.tar.xz -C $i && \
  find $i -name tar -type f -perm /111 -ls \
  ; done ;
# First Debian package
-r--r--r-- 1 root root 675968 Mar 24 21:31 tar_1.27.1-2+b1_amd64.deb
# Convert it to a tarball for extracting
deb2targz: converting 'tar_1.27.1-2+b1_amd64.deb' ...
deb2targz: skipping section 'debian-binary'
deb2targz: skipping section 'control.tar.gz'
deb2targz: wrote 'tar_1.27.1-2+b1_amd64.tar.xz'
# Tar binary in the first debian package:
108669076    352 -rwxr-xr-x   1  root     root       358072 Nov  8  2014 tar_1.27.1-2+b1_amd64/bin/tar

# Second debian package
-r--r--r-- 1 root root 676278 Mar 24 21:32 tar_1.27.1-2+deb8u1_amd64.deb

# Convert it to a tarball for extracting
deb2targz: converting 'tar_1.27.1-2+deb8u1_amd64.deb' ...
deb2targz: skipping section 'debian-binary'
deb2targz: skipping section 'control.tar.gz'
deb2targz: wrote 'tar_1.27.1-2+deb8u1_amd64.tar.xz'
# Tar binary in the first debian package:
543129777    352 -rwxr-xr-x   1  root     root       358072 Oct 31 14:37 tar_1.27.1-2+deb8u1_amd64/bin/tar

Now we have both versions extracted, and we can compare them with a variant of your test command:

# Variables to make it clear which one we are using:
$ tar1=./tar_1.27.1-2+b1_amd64/bin/tar
$ tar2=./tar_1.27.1-2+deb8u1_amd64/bin/tar

# First
$ $tar1 --keep-directory-symlink czf /tmp/foo.tar.gz /tmp/foo
./tar_1.27.1-2+b1_amd64/bin/tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' options
Try './tar_1.27.1-2+b1_amd64/bin/tar --help' or
'./tar_1.27.1-2+b1_amd64/bin/tar --usage' for more information.

# Second
$ $tar2 --keep-directory-symlink czf /tmp/foo.tar.gz /tmp/foo
./tar_1.27.1-2+deb8u1_amd64/bin/tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' options
Try './tar_1.27.1-2+deb8u1_amd64/bin/tar --help' or
'./tar_1.27.1-2+deb8u1_amd64/bin/tar --usage' for more information.

As for the discussion of other tar implementations, see my answer to a question difference between tar implementions: https://unix.stackexchange.com/a/104172/54009

robbat2
  • 3,639
1

I can fix it by appending by - the czf but not sure if equivalent

It is. The manpage takes a lot of time to go through this.

Basically you're expecting pretty weird behaviour in tar, because the set of long options includes aliases for the short operation mode options.

tar --keep-directory-symlink czf b e

tar --create b e

tar --create zf b e

e.g. what do you want the last command above to do. Do you want it to treat zf as a file in the last case, while not treating czf as a file in the first case?

sourcejedi
  • 50,249