Tar extract command, Cannot open: Permission denied - file-permissions

I use tar -zxvf tarFile.tar.gz to extract the tarFile, but there is an error hint tar: subfile :Cannot open: Permission denied .
I am a root user, and the permission of tarFile.tar.gz is 755, and the directory of the tarFile is also 755.
Executetar -tvf tarFile.tar.gz tells the sub files permission is 644.
As the attached pic show.

Try with sudo command:
sudo tar -zxvf tarFile.tar.gz

Related

Loop through directory and zip specific folder without parent path

I'm trying to make a bash script to loop through all folder in directories, and individually zip just the folder I want without all path and choose where to zip theme.
#!/bin/bash
for dir in /MyPersonalFolder/*/*/WhatIWantFolder
do
folder_number=$(basename ${dir%/*}) ### basename get the name of this folder [*] 'folder have numbers' /MyPersonalFolder/*/[*]/WhatIWantFolder
sudo tar -cf "${folder_number}-WhatIWantFolder".tar.gz --absolute-names "$dir"
mkdir -p ./backup-theme/ && sudo mv "${folder_number}-theme".tar.gz $_ ### I use this to move zipped folder to specific directory if i can choose where to zip file in the zip command line it's better
done
I can zip the folder I want, but the output zip file comes with this content:
/MyPersonalFolder/0001/0001/WhatIWantFolder
But what I need is to output the file with this path:
0001/
|___WhatIWantFolder/
I tried to change "$dir" in this line
sudo tar -cf "${folder_number}-WhatIWantFolder".tar.gz --absolute-names "$dir"
with basename ${dir%/*}
sudo tar -cf "${folder_number}-WhatIWantFolder".tar.gz --absolute-names "basename ${dir%/*}"
tar not found the folder it's come with errors
tar: e0001: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
You can cd to another directory while running tar using the --cd option.
#!/bin/bash
for dir in MyPersonalFolder/*/*/WhatIWantFolder; do
parent="${dir%/*/*}"
subdir="${dir#*/*/*}"
outfile="backup-theme/${subdir/\//-}.tar.gz"
tar --cd "$parent" -cvzf "$outfile" "$subdir"
done
The directory structure of the tar file would look something like this:
tar -tf backup-theme/0001-WhatIWantFolder.tar.gz
0001/WhatIWantFolder/
0001/WhatIWantFolder/f1

Laravel 5: Failed to open stream: Permission denied

I have my project in local development and all it's working fine.
When I pass the project to a rasberry and try to make it works I'm getting some errors I try to find the solution in other questions like this here in stackoverflow but it not works.
When I call to a function who it's working with storage folder I get this error:
With sudo chmod -R 775 storage/
The stream or file "/var/www/html/test/storage/logs/laravel.log" could
not be opened: failed to open stream: Permission denied
And if I change the permission to 777 I get this error:
file_put_contents(/var/www/html/test/resources/views/projects/problema.blade.php): failed to open stream: Permission denied
How should be the permission of the folder to make it works?
This is what i used to do for the linux installations :
sudo usermod -a -G apache your_user
sudo chown -R your_user:apache /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;
You should be fine with these permissions.You can replace the group and user and you need. Never provide a 777 permission to any of the folders.

how to create tar file so that files at placed at root folder of tar.gz file

I need to create targ.gz file and contents of file should be at root folder
say. I want angle and Simple files at root of tarfile shown at bottom. Any suggestions. I tried as below but extra folder is created at root
tar -zcvf tarfile.tar.gz -C /example/tarFile .
./
./angle.txt
./Simple.jar
tar -zcvf tarfile.tar.gz -C /example/tarFile .
./angle.txt
./Simple.jar
Please try this
tar -czvf tarfile.tar.gz /example/tarFile
after creating tar file use cp or mv command to move anywhere you want.

how to tar all files in a directory and move that tar to another directory

So I have 2 directors A and B. I want to tar all the files in A and have the .tar file be sent to directory B. How can i do this?
I have tried
sudo tar -C /home/mine/A/ -cvf home/mine/B/test.tar
tar: Cowardly refusing to create an empty archive
tar -cvf /home/mine/B/test.tar /home/mine/A/
works fine for me.

How to fix "tar: Removing leading `/' from member names" warning?

I'm trying to create tar.gz file but I keep getting the error
tar: Removing leading `/' from member names
by doing:
sudo tar -zcf test.tar.gz /opt/stagecoach/apps/test/current/
Ive googled it and found the -P option but I still get the same error.
Any ideas?
Try this:
sudo tar -cvzf test.tar.gz /opt/stagecoach/apps/test/current
Try this:
sudo tar -czf test.tar.gz -P /opt/stagecoach/apps/test/current
The path of the archive when specified causes this informational message, you can do the following to resolve it:
tar -zvcf /tmp/mike.tar.gz -P /tmp/mike
or
tar -zvcf mike.tar.gz -P /tmp/mike
or
tar -zvcf mike.tar.gz /tmp/mike
Note: it is not an error, just informational.
Changing directory using the -C option solved the confusing message about removing leading `/' from member names:
tar cf - -C /working-directory .

Resources