Compressing a folder (tar) without its containing directory in the folder name
By Sarah Rodriguez •
I am trying to compress a folder with the tar command.
When I am trying to compress it, it works fine. The problem is with the file name.
Source path:
/data/file/Destination path:
/data/repo/temp/file.tar.gz
tar zcvf $srcpath $destinationpathI am executing the command from a different folder, and while extracting the folder I am getting all the sub directories instead of file folder alone.
31 Answer
The easiest way to do that is to cd to the directory first:
cd /path/to/containing/folder && tar -zcvf tarfile.tar.gz foldername_tocompressSo that the (containing) folder's directory becomes the root directory of your compressed file.
A bit more advanced is using the -C option:
tar -zcvf tarfile.tar.gz -C /path/to/foldername_tocompress .This creates a tar.gz file in the current (working) directory, containing all files/folders inside foldername_tocompress (mind the dot, saying all files/folders should be included).
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"