I run into an error while extracting a tar file, the created directory are created with the chmod 666 instead of 777. Therefore it will not extract inside this folder.

Here is my command:

$umask 000 && tar -xvzf compress.tgz
tar: dist/assets: Cannot mkdir: Permission denied
tar: dist/assets/favicon.ico: Cannot open: Permission denied

$ls -ll
drw-rw-rw- 2 user grp    4096 Mar 14 16:43 assets

I used this module on local to compress the file:


When I create a directory with mkdir it gives 777 mode, what am I missing?

As requested:

-bash-4.2$ tar tzvf compress.tgz
drw-rw-rw- 0/0               0 2018-03-15 12:17 dist/
-rw-rw-rw- 0/0           13117 2018-03-15 12:17 dist/3rdpartylicenses.txt
drw-rw-rw- 0/0               0 2018-03-15 12:17 dist/assets/

I use --strip 1 to extract.

  • 4
    you never, ever, ever need to have 777 rights.
    – Carpette
    Commented Mar 14, 2018 at 17:22
  • @thebtm let's say I have a folder with one file inside dist/assets/favicon.ico. When extracting I got only one folder dist with 666 mode and nothing inside. Also it output the errors above.
    – Frennetix
    Commented Mar 14, 2018 at 17:28
  • tar does have a p flag to preserve permissions however poor they may be
    – thrig
    Commented Mar 14, 2018 at 17:34
  • 2
    @Carpette never say never. I can think of several scenarios where 777 is an appropriate permission mode. Commented Mar 14, 2018 at 19:24
  • 1
    @RonJohn during the tar it create the subfolder but they haven't the right chmod so the subfolder and subfiles aren't created.
    – Frennetix
    Commented Mar 15, 2018 at 16:33

2 Answers 2


As you can see from the output of tar tv the permissions in the archive itself are broken. If you have any control over the tool that created this archive I would strongly recommend that you fix it, or report a bug.

I assume you still need to extract the files from the broken archive. Try this:

tar xzvf compress.tgz --delay-directory-restore
find dist -type d -exec chmod a+x {} \;

(We can't use a trailing + in this instance because the chmod must be applied one directory at time so that find can descend into the fixed subdirectories. The semicolon is prefixed with a backslash so that it's not treated by the shell as a special character, but rather it's passed to the find... -exec as a literal.)

  • -bash-4.2$ find dist -type d -exec chmod a+x {} + find: 'dist/assets': Permission denied
    – Frennetix
    Commented Mar 16, 2018 at 10:36
  • @Frenentix please change the trailing + to \;. I'll update my question too Commented Mar 16, 2018 at 10:40

With star (from schily-tools), you can extract it with:

star xf file.tgz -no-p -find -type d -chmod a+x

To add the execute permission (for everybody) to the extracted directories to fix those bogus permissions in the archive.

With -no-p, the umask is also applied even if run as root, which assuming your umask is at least 002 would also fix those too wide write permissions (note that the umask takes precedence over the -chmod).

Note that none of the GNU tar, bsdtar nor star implementations of tar in my test have any issue extracting an archive with such broken permissions. Most likely here, you're trying to extract it while there was already a dist directory without search permission (because for instance you have extracted a similar archive with similarly broken permissions).

You'd need to fix those permissions first before extracting the archive.

  • 1
    You are correct, any decent modern tar implementation implements automated delayed directory setup for permissions and time stamps. When a directory is newly created during extraction, this is done with sane permissions and the permissions from the archive are applied later.
    – schily
    Commented May 31, 2018 at 9:58

You must log in to answer this question.

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