Question

I am running the following snippet in a bash script in a folder. This creates an archive where there is no root folder since I am running the script within the folder whose contents I am archiving.

tar -pczf $ARCHIVE_NAME --exclude=${ARCHIVE_NAME} --exclude=$(basename ${0}) *

Archive Contents:
/a/
/b/
/c/
/a_normal_file

works great, but since I am using the * it is not archiving hidden files in the immediate directory. I did some searching and found archiving (ubuntu tar) hidden directories I have then changed it to:

tar -pczf $ARCHIVE_NAME --exclude=${ARCHIVE_NAME} --exclude=$(basename ${0}) .

Archive Contents:
/./a/
/./b/
/./c/
/./.a_hidden_file
/./a_normal_file

still works, but now there is a root folder being created with the name being the '.' character. The contents are then within that. How do I get my previous result, but where it still archives hidden files in the immediate directory?

Thanks in advance!

Was it helpful?

Solution 2

While it doesn't affect the unpacking of the archive (since . just refers to the same dir), if it bothers you, you can change the wildcard from * to .[^.]* * to include all the hidden files as well.

In addition, if you have hidden files beginning with .., such as ..a, you'll need to add ..?* to the list as well.

OTHER TIPS

Use -C, --directory DIR

--directory=$(dirname ${0})

Example:

$ ls -a xxx
.  ..  aaa  .bbb
$ tar cvf test.tar --exclude test.tar -C xxx .
./
./.bbb
./aaa
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top