-1

I am writing a shell script where I need to change permissions to the extracted set of files and folders from a double zipped tarball.

My code line is:

gzip -dc <file.tar.gz> | tar -tvzf - | cut -d"/" -f3 | uniq | xargs chmod -R 755 

but the tarball extract is in the other folder. How can I append the path to the extracted folder from uniq and change the permission?

starball
  • 20,030
  • 7
  • 43
  • 238
10hero
  • 15
  • 8
  • 2
    What is the meaning of the sentence _the tarball extract is in the other folder_? Why don't you provide the folder name explicitly to the `chmod` command, or do a `cd` to that folder before running the pipeline? Perhaps it would help if you would add to your question an example line coming out from `uniq`, and how the `chmod` command should look like. – user1934428 Dec 17 '21 at 08:04
  • cd is not in my requirement. You can underrate my question its okay. Anyways I have solved this query myself and without the use of cd or some traditional methods that you are trying to suggest. – 10hero Dec 30 '21 at 08:28
  • 1
    If you now have a solution which suits you, why not posting it as an answer? It is perfectly legal in SO to answer your own question, since others with a similar problem could benefit from it. – user1934428 Dec 30 '21 at 08:30

1 Answers1

0

Here is the code snippet :

perm_name=$(gzip -dc ${RELEASE_DIR}/${REL_PACKAGE}|tar -tvzf - |cut -d"/" -f3|sort|uniq)
arr=(${perm_name})

for i in ${arr[@]}
do 
f=${arr[t]}

find ${INSTALL_DIR} -maxdepth 1 -name ${f} -type d -exec chmod -R 755 {} \;
t=$(($t+1))
done;
10hero
  • 15
  • 8