Unix command for find updated and newly added files/folder
I need to find out the listed for files or folders that has been added/updated in the file system path (/home/user01/myapps/
) between two different time (scripts starting and ending time).
I am running a Shell scripts to do the updating/adding new files to the resource path /home/user01/myapps/
from different source. So, at the end开发者_开发技巧 of scripts I want to know the list of files or folders that has been added or updated.
I have the below command
find /opt/app/tds/tdsbatch -mtime -1
But, I am not sure about the script running time.
Any help indeed!
To record times at whatever desired moment:
# record the current time in seconds on script startup
start_time=$(date +%s)
...
# do whatever you like
...
# to get the runtime in secods - if you like:
runtime=$(($(date +%s) - start_time))
# to get the runtime in minutes (minutes are useful for -mmin find param)
runtime=$((($(date +%s) - start_time) / 60))
...
# to record the finish time in seconds:
end_time=$(date +%s)
and now find
according to your needs. something like
find /path \( -mmin $((-($(date +%s) - start_time) / 60)) \
-a $((($(date +%s) - end_time) / 60)) \)
- the first
-mmin
argument specifies modifed after (current time - script start time) minutes back from now - the second
-mmin
argument specifies modified before (current time - script end time) minutes back from now - both of them are in conjunction with
-a
parameter and enclosed in prefixed brackets
You could probably do with these. Otherwise I would need more clarification about your needs.
At the start of script you can use touch command for any existing file or create a dummy file.
e.g.
script start
touch filename1 - It will change the time stamp of filename1 to current time
Then at the end of script you can use following command:
find directory name -newer filename1
It will give all the files modified or created after timestamp of filename1 in that directory
精彩评论