I am generating a .tar.gz file with the following command.
tar cfhpz archive.tar.gz -C /lots/of/subdirectories/files .
/lots/of/subdirectories/files contains a directory structure that is something like:
+
|-- bin/
|-- dist/
|-- lib/
And so on.
My end goal from running this command is to have a .tar.gz that contains a directory structure exactly like the one within /lots/of/subdirectories/files -- with no additional parent directories.
Using the command I specified, everything appears to be structured exactly how I want when I view the archive using Ark or the Archive Mounter. However, when I view the archive using GNOME Archive Manager, it shows that all of the files/folders are actually in a subdirectory called "." like so:
+
|-- .
|-- bin/
|-- dist/
|-- lib/
Is there any way I can get rid of the "." subdirectory?
In your command you call the directory .
, which is linked to the directory that your are in. The .
directory is a real directory, it just happens to have all the same continence as the directory that .
, its self, is in. For example, when you run a script with ./script.sh
, what you are doing is the same as if from a other position on the file system you gave the command /path/to/script.sh
. It's a convention in Bash to use the ./
when you are running an executable file from local directory. Alternatively you could run a script bash script.sh
So, when you run
tar cfhpz archive.tar.gz -C /lots/of/subdirectories/files .
it resolves to ./all-the-stuff-in-the-directory
. What you want is to take all the files in the directory, and not look at the them as a subdirectory of ./
. To do this, you want to use the wild-card, or regular expression, charter *
, which matches to everything.
tar cfhpz archive.tar.gz -C /lots/of/subdirectories/files *
For example, if I run echo ~/Documents/*
/home/seamus/Documents/2013 /home/seamus/Documents/2014 /home/seamus/Documents/2015 /home/seamus/Documents/2016 /home/seamus/Documents/2017 /home/seamus/Documents/2018 /home/seamus/Documents/2019
What we get echo-ed back are all the continence of the directory and no ./
, ../
or other hidden files.
The difference with KDE Ark and Gnome file Archive Manager is that Ark is making the inference that the ./
is probably just a redirect to the folder contains. This differs form Grome which is probably running something similar to ls
on the file structure, where it actually lets you walk the the file sturcture.