3

I have tar.gz files with such permissions

-rwxrwxrwx 1 sbesnard SBC 1118627  7 dec 11:34 LE72300832015207-SC20161121192747.tar.gz

However, when I change the permission of the tar.gz file as such chmod -R a+rwx ., the permission of the files in the tar.gz file did not change.

tar -ztvf LE72300832015207-SC20161121192747.tar.gz    
-rw-r--r-- espa/ie      223389 2016-10-30 20:45 LT52300831998344COA00_sr_band3.tif

Any idea on how I could change the permission of each file in my tar.gz file?

4

Well yes. The permissions are a feature of files on your filesystem. The files in the tarball don't actually exist on the file system. They are encoded within the tarball. Therefore, chmod commands cannot see them, nor obviously affect them.

When a tarball is extracted, the permissions applied are whatever the default file creation permissions are on your system. This is because untarring a file causes the files it contains to be created. This can be modified when creating the tarball, you can set it so that it keeps the original permissions, for example, but you cannot affect files already stored in a tarball using normal filesystem commands. As I said before, those files don't actually exist.

So, just extract the files first and then change their permissions.

| improve this answer | |
  • 1
    But is there any way to ask tar to modify the files inside the archive in this manner? For example, if one wanted to untar but remove all execute bits. – Boris the Spider Dec 8 '16 at 15:05
  • @BoristheSpider then you would have to untar and remove all execute bits. Just do it after untarring. As far as I know, there is no way of modifying things in the tarball. Any such solution would just be untarring, modifying and retarring in the background. – terdon Dec 8 '16 at 15:17
  • Thanks; that's what I suspected - it might be worth adding that to your answer as I think that's what the OP is trying to do. (Not remove execute bits specifically, but modify the permissions stored in the archive) – Boris the Spider Dec 8 '16 at 15:18
  • 1
    @BoristheSpider Tar obeys the umask setting (by default for users and with an option for root), so you can set umask to 111 (or 113 or 133 to also remove the traditional write bits) to exclude execute bits from created files. There is no ability to add permission bits in this way though. – Random832 Dec 8 '16 at 15:19
  • @Random832 that's very useful information - thanks. – Boris the Spider Dec 8 '16 at 15:20
4

You can change the permissions in the archive without extracting by opening the archive file in Emacs and editing the permissions in the archive-mode directory listing.

"The keys M, G, and O change the file’s permission bits, group, and owner, respectively.

Saving the Tar buffer writes a new version of the archive to disk with the changes you made to the components."

You don't even need the tar program since Emacs will read the file directly. You will need gzip though.

https://www.gnu.org/software/emacs/manual/html_node/emacs/File-Archives.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.