Molko
asked on
unzip then chmod in one command
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
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
I suggest you to use tar+gzip (tar -cfz/-xzf) instead of zip. This will store/restore file/directory permissions.
ASKER
The zip file is not provided by me....I have no control over it
Thanks
Thanks
I see only way:
unzip bla-bla-bla; chod 777 bla-bla-bla
unzip bla-bla-bla; chod 777 bla-bla-bla
ASKER
How does that work ? How are you piping the files to chmod ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 --
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/
#unzip
unzip MYFILE
#changing permissions
chmod -R 777 *
#End Script
#-------------------------
To run type this
myunzip.sh myfile
-- hope helps --
unzip prints out the names of the files it is extracting, as below:
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.
If your files might contain spaces, you need a more complex:
$ unzip bigfile.zip
Archive: bigfile.zip
creating: dir1/
creating: dir2/
extracting: dir1/f1
extracting: dir1/f2
extracting: dir2/f4
extracting: dir2/f3
$
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
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