How to include .htaccess in tar commands?

Unix

Unix Problem Overview


Whenever I do

tar -pczf file.tar.gz *

it ignores any .htaccess files, and I can't see in the man how to include it.

Unix Solutions


Solution 1 - Unix

The shell is expanding * to all files in the current directory that do not start with a dot. This is the same rule that ls uses by default (by convention, files whose names start with a dot are considered "hidden" in Unix). Try instead:

tar -pczf file.tar.gz .

Using . at the end will collect all files in the current directory, including those whose names start with a dot.

Solution 2 - Unix

The problem isn't tar; the shell does not include hidden files in *. Do

tar -pczf file.tar.gz * .htaccess

And next time, perhaps this question could be posted on SuperUser.

Solution 3 - Unix

if your task allows you to hop up one directory level and tar the whole directory it works just fine and you don't have to remember anything special to make it work (I almost always forget the other way, and end up with tgz's missing .htaccess files)

tar -pczfv httpdocs.tar.gz httpdocs

Solution 4 - Unix

If you can, why not use:

tar -pczf file.tar.gz `find .`

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnixnubView Question on Stackoverflow
Solution 1 - UnixGreg HewgillView Answer on Stackoverflow
Solution 2 - UnixpavpanchekhaView Answer on Stackoverflow
Solution 3 - UnixThe Brawny ManView Answer on Stackoverflow
Solution 4 - UnixQix - MONICA WAS MISTREATEDView Answer on Stackoverflow