Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Script to find the most recently modified file

I have two folders, for arguments sake /Volumes/A and /Volumes/B. They are mounted network shares from a Windows server containing a load of .bkf files from Backup Exec.

I am looking for a script which will look into both folders and find the most recently modified .bkf file and copy it to another location. There are other files in the folders which must be ignored.

Thanks in advance!!

Shaun

Edit:

I knocked this together:

cp ls -alt /Volumes/E /Volumes/F| grep bkf | head -n 1 | awk '{print $8}' /Volumes/$xservedisk/Windows/ 

Can anyone think of any reasons why I shouldnt use it?

Thanks again Shaun

like image 855
Shaun Johnson Avatar asked Dec 13 '22 01:12

Shaun Johnson


1 Answers

I prefer this for finding the most recently modified file:

find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
like image 90
Mark Theunissen Avatar answered Dec 26 '22 13:12

Mark Theunissen