?
Solved

Update modified date of parent/grand parent folder when sub-file is updated

Posted on 2015-02-04
2
Medium Priority
?
99 Views
Last Modified: 2016-06-23
I'm on a Mac, and working on a Bash script to handle this.

I have a folder hierarchy containing PO files ready for processing (RFP) and we have a script that looks at modified dates of folders that end in "-RFP". I don't have access to modify the processing job script.

If the "-RFP" folder's modified date is within last 24 hours, then the processing job will run on the folder. This works fine on new folders, but does not pick up edits to sub-files or folders with more complex sub-folders.

Users are updating files in sub-folders at varying depths below the "-RFP" folders, and they are expecting that the processing job will run against those folders. I'm looking to run a find-&-touch cron job to update the modified date of parent and grand-parent "-RFP" folders.

Here's a sample of the hierarchy.

Root
 --2015_Folder
      --PO48484_Folder_RFP (need to update mod date)
           --File1.txt (modified in last day)
      --PO23939_Folder_RFP (need to update mod date)
            --POComponent_Folder1
                --File3.txt (modified in last day)
                --File4.txt (modified three weeks ago)
            --POComponent_Folder2
                --File5.txt (modified three weeks ago)
                --File6.txt (modified three weeks ago)

I want to be able to find all modified .txt files in the folder hierarchy, and then update the modified date of the containing "-RFP" folder, regardless of file depth within the associated RFP folder.

Scraping together my very rusty bash knowledge and borrowing from elsewhere, I've got the following which should touch the parent folders, but not specifically the "-RFP" folders if the text files are down a layer or more.

find . -type f -mtime -1 -name '*.txt' -print0 \ | ( IFS=$'\0' ; while read -d "" FILE ; do echo touch -r "$FILE" "$(dirname "$FILE")" ; done )

Open in new window


What should I be using to look for the -RFP suffix?

Any help would be appreciated!
0
Comment
Question by:icg_team
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 40588849
find . -type f -mtime -1 -name '*.txt' -print0  | ( IFS=$'\0' ; while read -d "" FILE ; do echo touch -r "$FILE" "${FILE%RFP/*}RFP" ; done )
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question