6

On Linux I'm extracting files from a tar archive using

tar -xC / -f /tarFile.tar someFolder/[HD] video1.mp4

This works always fine but not in this case where file name contains square brackets. Tar response is

someFolder/[HD] video1.mp4: not found in archive

The file is extracted fine if I remove the square brackets.

I already tried both escaping all characters with \ and surrounding file name with '. No luck.

Any hint? Thanks

2
  • 1
    Can you share which tar --version and shell you use (echo $SHELL)? Can you include the version of commands which you tried with quoting and escaping?
    – kenorb
    May 4, 2018 at 13:06
  • 2
    Is that really the command you typed? It seems like you must have quoted or escaped the space in the filename, otherwise it would see someFolder/[HD] and video1.mp4 as separate arguments.
    – Barmar
    May 4, 2018 at 19:24

2 Answers 2

7

The first command you have provided will attempt to extract two or three files:

someFolder/H
someFolder/D
video1.mp4

If you enclose filename in single quotes (') the tar program will see the [HD] and process it as a glob wildcard meaning "Either H or D". It will therefore attempt to extract two files:

someFolder/H video1.mp4
someFolder/D video1.mp4

Quoting the filename and using the --no-wildcards flag will suppress these attempted expansions:

tar -xC / -f /tarFile.tar 'someFolder/[HD] video1.mp4' --no-wildcards
0
1

Replace square brackets with the wildcard characters (such as ? or *), e.g.

tar -x -C/ -v -f tarFile.tar 'someFolder/?HD? video1.mp4'

or:

tar -x -C. -v -f tarFile.tar 'someFolder/*video1.mp4'

To confirm the filename, you can list the archive file by:

tar -t -f tarFile.tar | grep mp4$
1
  • A tar implementation that implements pattern matching in extract mode is broken.
    – schily
    May 31, 2018 at 14:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .