Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
This is an explanation of a simple data model to help parse a JSON feed
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now