Solved

unzip then chmod in one command

Posted on 2011-09-10
7
2,131 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

627 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