Solved

unzip then chmod in one command

Posted on 2011-09-10
7
1,968 Views
Last Modified: 2012-05-12
HI

I have a zip file that I need to unzip, it contains lots of files and takes around 3 hours to unzip. Then i need to issue a recursive chmod 777 against these files, which again takes some time to do.

Is there a smart way to apply the chmod as the files are being unzipped ?

Maybe piping the unzip thru chmod ?...dunno

I was thinking umask ?...But i dont really understand it
0
Comment
Question by:Molko
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Expert Comment

by:pilson66
ID: 36516070
I suggest you to use tar+gzip (tar -cfz/-xzf) instead of zip. This will store/restore file/directory permissions.
0
 

Author Comment

by:Molko
ID: 36516071
The zip file is not provided by me....I have no control over it

Thanks
0
 
LVL 8

Expert Comment

by:pilson66
ID: 36516075
I see only way:
unzip bla-bla-bla; chod 777 bla-bla-bla
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Molko
ID: 36516080
How does that work ? How are you piping the files to chmod ?
0
 
LVL 8

Accepted Solution

by:
theodorejsalvo earned 500 total points
ID: 36516092
Here's a good one-liner:

unzip -Z -1 file.zip | xargs chmod 0777

Open in new window


Basically the -Z -1 causes unzip to list each file on it's own line, then xargs puts them all on one line and passes them to chmod.
0
 
LVL 5

Expert Comment

by:hvillanu
ID: 36517687
hi,
Try this.
unzip file.zip; chmod -R 777

Or in a shell script... myunzip.sh

# ---------------------------------------------------
#Script to unzip and change permissions
#Variables
MYFILE=$1

#go to file location
cd /some/path/where/zip/file/is

#unzip
unzip MYFILE

#changing permissions
chmod -R 777 *

#End Script
#----------------------------------------


To run type this
myunzip.sh myfile


-- hope helps --
0
 
LVL 19

Expert Comment

by:simon3270
ID: 36521903
unzip prints out the names of the files it is extracting, as below:
$ unzip bigfile.zip 
Archive:  bigfile.zip
   creating: dir1/
   creating: dir2/
 extracting: dir1/f1                 
 extracting: dir1/f2                 
 extracting: dir2/f4                 
 extracting: dir2/f3                 
$

Open in new window


You can read those names and, with a bit of text processing, pick out the names from the above output text and chmod them as they are extracted.  The command below captures that output as unzip runs, and for any lines where the first word ends "ing:", it runs chmod on the file.
unzip bigfile.zip | awk '/ing:/{print $2}' | xargs chmod 777

Open in new window

As with many commands like this, filenames with special characters (including spaces) will break processing.

If your files might contain spaces, you need a more complex:
unzip bigfile.zip | awk '/ing:/{gsub("^.*ing: ","");gsub(" *$","");printf "%s%c",$0,0}' | xargs -0 chmod 777

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best practice question for multiple stack upgrade: vSphere, Linux OS, Oracle DB & WebLogic 2 69
Shell Script- gzip 5 86
Linux 3 59
[bash] complex renaiming file 2 20
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question