{"id":7684,"date":"2018-07-27T18:40:09","date_gmt":"2018-07-27T10:40:09","guid":{"rendered":"http:\/\/rmohan.com\/?p=7684"},"modified":"2018-07-27T18:40:09","modified_gmt":"2018-07-27T10:40:09","slug":"linux-include-hidden-files-in-tar-archive","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7684","title":{"rendered":"Linux: include hidden files in tar archive"},"content":{"rendered":"<p>When you create a tar archive of a directory tree the hidden files are normally not included. Here\u2019s how to include the hidden files.<br \/>\n<span id=\"more-444\"><\/span><\/p>\n<p>Say you have a web directory called \u201c\/var\/www\/html\/mysite\/\u201d that contains the following tree:<\/p>\n<div>\n<div id=\"highlighter_158626\" class=\"syntaxhighlighter nogutter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">.htaccess<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"bash plain\">index.php<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"bash plain\">logo.jpg<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"bash plain\">style.css<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"bash plain\">admin_dir\/.htaccess<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"bash plain\">admin_dir<\/code><code class=\"bash plain\">\/includes<\/code><code class=\"bash plain\">.php<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"bash plain\">admin_dir<\/code><code class=\"bash plain\">\/index<\/code><code class=\"bash plain\">.php<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Normally you would use the tar command like this:<\/p>\n<div>\n<div id=\"highlighter_410852\" class=\"syntaxhighlighter nogutter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash functions\">tar<\/code> <code class=\"bash plain\">czf mysite.<\/code><code class=\"bash functions\">tar<\/code><code class=\"bash plain\">.gz <\/code><code class=\"bash plain\">\/var\/www\/html\/mysite\/<\/code><code class=\"bash plain\">*<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>This way all files are tarred except the .htaccess files.<\/p>\n<p>The solution is actually quite simple: replace the asterisk (*) by a dot (.):<\/p>\n<div>\n<div id=\"highlighter_945377\" class=\"syntaxhighlighter nogutter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash functions\">tar<\/code> <code class=\"bash plain\">czf mysite.<\/code><code class=\"bash functions\">tar<\/code><code class=\"bash plain\">.gz <\/code><code class=\"bash plain\">\/var\/www\/html\/mysite\/<\/code><code class=\"bash plain\">.<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>This way the .htaccess files are included in the tarfile.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you create a tar archive of a directory tree the hidden files are normally not included. Here\u2019s how to include the hidden files. <\/p>\n<p>Say you have a web directory called \u201c\/var\/www\/html\/mysite\/\u201d that contains the following tree:<\/p>\n<p> .htaccess index.php logo.jpg style.css admin_dir\/.htaccess admin_dir\/includes.php admin_dir\/index.php <\/p>\n<p>Normally you would use the tar command like this:<\/p>\n<p> tar [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7684"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7684"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7684\/revisions"}],"predecessor-version":[{"id":7685,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7684\/revisions\/7685"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}