{"id":536,"date":"2025-05-29T18:41:32","date_gmt":"2025-05-29T18:41:32","guid":{"rendered":"https:\/\/ouritsource.com\/blog\/?p=536"},"modified":"2025-05-29T18:47:30","modified_gmt":"2025-05-29T18:47:30","slug":"example-linux-bash-script-to-zip-contents-of-folders","status":"publish","type":"post","link":"https:\/\/ouritsource.com\/blog\/example-linux-bash-script-to-zip-contents-of-folders\/","title":{"rendered":"Linux Bash Script To ZIP contents of Folders"},"content":{"rendered":"<body>\n<p class=\"has-black-color has-text-color has-link-color wp-elements-11007b4c74a23f28efcba82868fa9985\"><strong>backup.sh<\/strong><br><br>#sets the current date and time to a variable so it can be used when naming zip file<br>current_time=$(date \u201c+%Y-%m-%d_%H.%M.%S\u201d)<br><br>#compress contents of \/var folder to zip file <br>tar -zcvf \/mnt\/EXTHD01\/fedora01\/backup\/fedora01_$current_time.tar.gz \/var<br><br>#compress contents of \/opt to zip file<br>tar -zcvf \/mnt\/EXTHD01\/fedora01\/backup\/fedora01_$current_time.tar.gz \/opt<br><br>#compress contents of \/etc to zip file<br>tar -zcvf \/mnt\/EXTHD01\/fedora01\/backup\/fedora01_$current_time.tar.gz \/etc<br><br>#compress contents of  \/home to zip file<br>tar -zcvf \/mnt\/EXTHD01\/fedora01\/backup\/fedora01_$current_time.tar.gz \/home<br><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-c39755e94e48d5eee895586bfdacff40\">#####################<\/p>\n\n\n\n<p><strong>To extract contents of compressed file, use the following syntax:<\/strong><\/p>\n\n\n\n<p>tar -xvf &lt;file.tar.gz&gt; &lt;folder_name&gt; -C &lt;destination_directory&gt;<\/p>\n\n\n\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>backup.sh #sets the current date and time to a variable so it can be used when naming zip filecurrent_time=$(date \u201c+%Y-%m-%d_%H.%M.%S\u201d) #compress contents of \/var folder to zip file tar -zcvf \/mnt\/EXTHD01\/fedora01\/backup\/fedora01_$current_time.tar.gz \/var&#8230;<\/p>\n","protected":false},"author":1,"featured_media":537,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[39],"tags":[],"class_list":["post-536","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","has-thumbnail"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ouritsource.com\/blog\/wp-content\/uploads\/2025\/05\/Penguin.png?fit=1024%2C1024&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/posts\/536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/comments?post=536"}],"version-history":[{"count":2,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/posts\/536\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/posts\/536\/revisions\/539"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/media\/537"}],"wp:attachment":[{"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/media?parent=536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/categories?post=536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ouritsource.com\/blog\/wp-json\/wp\/v2\/tags?post=536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}