Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

unzip then chmod in one command

Posted on 2011-09-10
7
Medium Priority
?
2,298 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 2000 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 20

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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

721 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