I'm trying to write a bash script that tars all files within a specific directory.
I have this command written in the script:
tar -cvf /opt/file/myFiles.tar.gz /opt/data/name/logs/
So basically I want a tar file called myFiles.tar.gz to be created in /opt/file and when I untar the file, it should give me the folder logs and everything inside logs.
Instead, I get the folder opt and I have to go through data and name as well before reaching the logs folder.
Is there a way so that when I untar the file, I only get what's in the logs folder and I wouldn't have to go through opt/data/name? I also tried doing /opt/data/name/logs/* but it gave the same result.
CodePudding user response:
GNU and BSD tar
have a -C
option for that:
tar -cv -f /opt/file/myFiles.tar.gz -C /opt/data/name/ logs/
CodePudding user response:
Can you try this one?
tar -cvf /opt/file/myFiles.tar.gz -C /opt/data/name/logs/ .