I'm trying to find the path to the latest edited file in a subdirectory matching a certain patern. For that I want to use a bash script to get the file path and then use it for a bunch of actions.
So for exemple i would have a tree like this:
Directory/
dir 1.0/
fileIwant.txt
fileIdont.txt
dir 2.0/
fileIwant.txt
fileIdont.txt
dir 2.1/
fileIwant.txt
fileIdont.txt
So in this case, I would want to find the latest "fileIwant.txt" (probably the one in "dir 2.1" but maybe not). Then I want to store the path of this file to copy it, rename it or whatever.
I found some scripts to find the latest in current directory but I didn't really understood them... So I hoped someone could give me hand.
Thanks !
Edit : Thanks to the diffent answers I ended up with something like this which work perfectly :
filename="fileIwant"
regex=".*/"$filename"-([0-9]+(\.[0-9]+)*).*/"$filename"\.txt"
path="$(find . -regextype awk -regex $regex -type f -printf '%T@ %p\n' | sort -n | cut -f2- -d" " | tail -1)"
(it doesn't exactly match my previous example obviously)