Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:23:28+00:00 2026-06-03T23:23:28+00:00

I have a directory tree in which there are some files and some subdirectories.

  • 0

I have a directory tree in which there are some files and some subdirectories.

/
/file1.txt
/file2.png
/dir1
    /subfile1.gif

The objective is to have a script that generates a gzipped version of each file and saves it next to each file, with an added .gz suffix:

/
/file1.txt
/file1.txt.gz
/file2.png
/file2.png.gz
/dir1
    /subfile1.gif
    /subfile1.gif.gz

This would handle the creation of new .gz files.

Another part is deletion: Whenever a non-gzipped file is created, the script would need to delete the orphaned .gz version when it runs.

The last and trickiest part is modification: Whenever some (non-gzipped) files are changed, re-running the script would update the .gz version of only those changed files, based on file timestamp (mtime) comparison between a file and its gzipped version.

Is it possible to implement such a script in bash?

Edit: The goal of this is to have prepared compressed copies of each file for nginx to serve using the gzip_static module. It is not meant to be a background service which automatically compresses things as soon as anything changes, because nginx’s gzip_static module is smart enough to serve content from the uncompressed version if no compressed version exists, or if the uncompressed version’s timestamp is more recent than the gzipped version’s timestamp. As such, this is a script that would run occasionally, whenever the server is not busy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:23:30+00:00Added an answer on June 3, 2026 at 11:23 pm

    Something like this, maybe?

    #!/bin/sh
    
    case $1 in
      *.gz )
        # If it's an orphan, remove it
        test -f "${1%.gz}" || rm "$1" ;;
        # Otherwise, will be handled when the existing parent is handled
      * )
        make -f - <<'____HERE' "$1.gz"
    %.gz: %
        # Make sure you have literal tab here!
        gzip -9 <$< >$@
    ____HERE
        ;;
    esac
    

    If you have a Makefile already, by all means use a literal file rather than a here document.

    Integrating with find left as an exercise. You might want to accept multiple target files and loop over them, if you want to save processes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some files in a directory tree which is being served over HTTP.
Consider the following directory tree Work--->subdir1--->File1 | | | ---->File2 | -->subdir2--->File3 There exists
I have a page which has a tree directory of people who work at
i have a directory called 'library' in my SVN tree which uses externals to
I have an application which keeps its data in a directory tree. Now, I
I have a repository which contains a directory tree. One of the directories is
So I have a directory tree as follows: pluginlist.py plugins/ __init__.py plugin1.py plugin2.py ...
I'm new to visual studio, coming from Delphi. I have a directory tree full
i have been sent a directory tree of source code that i want to
I have used copydir to copy a directory tree but it is deprecated. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.