Solved

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

Posted on 2015-02-04
2
88 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Six Sigma Control Plans
Progress

696 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