Tuesday, August 30, 2022

[SOLVED] When I compress a tar gz file using paths, folders get included

Issue

When I compress a tar gz file using paths, folders get included. However, I want to just compress the file only. This is what I tried:

$ tar -czf ../coolfile.tar.gz newfol/coolfile

When I uncompress this tar.gz, I get the coolfile file in newfol folder. I would like compress coolfile only.

Uncompress tar gz command:

$ tar -xvf coolfile.tar.gz`

Solution

tar -C newfol -cvzf coolfile.tar.gz coolfile

Note: you specify the tar.gz file relative to the current directory, and you specify the file(s) to be tarred relative to the directory that is argument to the -C option, and that tar will cd into to perform the tar.



Answered By - user2849202
Answer Checked By - Marie Seifert (WPSolving Admin)