Solved

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

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

732 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