tar xzCf --mode doesn't work.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tar xzCf --mode doesn't work.
# 1  
Old 09-26-2011
tar xzCf --mode doesn't work.

Code:
[ ~/test]$ touch x y
[ ~/test]$ ls -l x y
-rw-r--r-- 1  g660 0 Sep 26 03:38 x
-rw-r--r-- 1  g660 0 Sep 26 03:38 y
[ ~/test]$ chmod 777 x y
[ ~/test]$ ls -l x y
-rwxrwxrwx 1  g660 0 Sep 26 03:38 x
-rwxrwxrwx 1  g660 0 Sep 26 03:38 y
[ ~/test]$ rm a.tar
[ ~/test]$ tar cvzf a.tar.gz .
./
./x
./y
./a.tar.gz
[ ~/test]$ ls -l
total 4
-rw-r--r-- 1  g660 180 Sep 26 03:38 a.tar.gz
-rwxrwxrwx 1  g660   0 Sep 26 03:38 x
-rwxrwxrwx 1  g660   0 Sep 26 03:38 y
[ ~/test]$ cd
[ ~]$ /bin/tar xvzCf
[ ~]$ cd test
[ ~/test]$ rm x y
[ ~/test]$ cd
[ ~]$ /bin/tar xvzCf ~/test ~/test/a.tar.gz --mode a-w
./
./x
./y
./a.tar.gz
[ ~]$ ls -l test
total 0
-rw-r--r-- 1  g660 0 Sep 26 03:38 a.tar.gz
-rwxr-xr-x 1  g660 0 Sep 26 03:38 x
-rwxr-xr-x 1  g660 0 Sep 26 03:38 y
[ ~]$

I provided --mode a-w to remove "w" bit from "all". But it only removed for others and not for the "user". I was hoping to see 555 and instead I see 755.

Why? My umask, BTW, is set to 022.

Last edited by volbod; 09-26-2011 at 10:04 AM.. Reason: Please use code tags
# 2  
Old 09-26-2011
The man page indicates that --mode works when ADDING to not extracting from an archive.
# 3  
Old 09-26-2011
set a temporary umask in your shell when doing an extract.

Code:
umask 222

then you can reapply your normal env settings
# 4  
Old 09-26-2011
Yes. Looks like I missed the point that the --mode is applicable only while "adding" the files and not during extraction.

Code:
[ ~/test]$ !touch
touch x y
[ ~/test]$ !ch
chmod 777 x y
[ ~/test]$ ls -l x y 
-rwxrwxrwx 1  g660 0 Sep 26 19:46 x 
-rwxrwxrwx 1  g660 0 Sep 26 19:46 y 
[ ~/test]$ umask
22
[ ~/test]$ tar cvzf a.tar.gz . --mode a-w
./
./x
./y
./a.tar.gz
[ ~/test]$ tar -tvzf a.tar.gz 
dr-xr-xr-x /g660     0 2011-09-26 19:46:50 ./
-r-xr-xr-x /g660     0 2011-09-26 19:46:50 ./x
-r-xr-xr-x /g660     0 2011-09-26 19:46:50 ./y
-r--r--r-- /g660     0 2011-09-26 19:47:07 ./a.tar.gz
[ ~/test]$

And if I need to be doubly sure that while untarring the "w" permissions are indeed knocked out, then i just need to set the umask as 222.

Was hoping to be able to provide the umask as part of the "tar" command (to untar) itself ; instead of setting umask to 222 and resetting it back to the original value.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Timeout doesn't work, please help me

#!/bin/sh trap "cleanup" TERM timeout=5 mainpid=$$ cleanup() { echo "at $i interupt" kill -9 0 } watchdog() { sleep $1 } (watchdog $timeout && kill -TERM $mainpid) & run_test() (10 Replies)
Discussion started by: yanglei_fage
10 Replies

2. Shell Programming and Scripting

-ne 0 doesn't work -le does

Hi, I am using korn shell. until ] do echo "\$# = " $# echo "$1" shift done To the above script, I passed 2 parameters and the program control doesn't enter inside "until" loop. If I change it to until ] then it does work. Why numeric comparison is not working with -ne and works... (3 Replies)
Discussion started by: ab_2010
3 Replies

3. UNIX for Dummies Questions & Answers

Why doesn't this work?

find . -name "05_scripts" -type d -exec mv -f {}/'*.aep\ Logs' {}/.LogFiles \; Returns this failure: mv: rename ./019_0120_WS_WH_gate_insideTEST/05_scripts/*.aep\ Logs to ./019_0120_WS_WH_gate_insideTEST/05_scripts/.LogFiles/*.aep\ Logs: No such file or directory I don't know why it's trying... (4 Replies)
Discussion started by: scribling
4 Replies

4. Shell Programming and Scripting

My if statement doesn't work why?

I have the following and for some reason I can't have two options together. I mean if I choose -u and -p it won't work... why? #!/bin/bash resetTime=1 mytotalTime=0 totalHour=0 totalMin=0 averagemem=0 finalaverage=0 times=0 function usage() { cat << EOF USAGE: $0 file EOF } (10 Replies)
Discussion started by: bashily
10 Replies

5. UNIX for Dummies Questions & Answers

Emacs starts in c++ mode but doesn't use c++ setup

Hi, I'm trying to use Emacs to edit C++ files (extension .cpp). My ~/.emacs file contains: (defun my-c++-indent-setup () (setq c-basic-offset 4) (setq c-default-style "linux") ) (add-hook 'c++-mode-hook 'my-c++-indent-setup) When I open a C++ file in Emacs, it's in C++ mode (the... (1 Reply)
Discussion started by: linuxnoob12
1 Replies

6. Solaris

shutdown -y -i5 -g0 DOESN'T work

hello, The command above seems not working on my solaris 8/9 sparc machines. a. resulted to the ff below when I instead use "shutdown" only. Broadcast Message from root (pts/1) on "hostname" date.. The system "hostname" will be shut down in 30 seconds THE SYSTEM bdosg IS BEING SHUT... (4 Replies)
Discussion started by: lhareigh890
4 Replies

7. Shell Programming and Scripting

HELP: If Doesn't Work in AWK

Hi! I have a somehow big file (almost 3000 lines long and thirteen columns). Some lines have no value at all or, at least, are incomplete. The columns' values that have no data are marked with a "-" and the corresponding line (the line that owns that value) should be discarded and not used. ... (5 Replies)
Discussion started by: Marcelo de Brit
5 Replies

8. Shell Programming and Scripting

What to do when mtime doesn't work?

I have a folder that I need to search for new files and copy on the latest. I've been using "-mtime -1" in my command line but it doesn't seem to work. I've been meaning to fine a different script because files are dropped into the folder all day long and because of the -mtime, I've only be... (19 Replies)
Discussion started by: bbbngowc
19 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

10. Shell Programming and Scripting

Why doesn't this work?

cat .servers | while read LINE; do ssh jason@$LINE $1 done exit 1 ./command.ksh "ls -l ~jason" Why does this ONLY iterate on the first server in the list? It's not doing the command on all the servers in the list, what am I missing? Thanks! JP (2 Replies)
Discussion started by: jpeery
2 Replies
Login or Register to Ask a Question