Shell Script for searching files with date as filter

Hi ,
Assume today's date is 10-May-2002. I want to get a list of files which were last modified since 01-May-2002. If I run the script after 5 days, it should still list me the files modified from 01-May-2002 till today. I also plan to pass the date 01-May-2002 as an argument to the shell script through which we can avoid editing the script for other dates.

How can I implement this requirement through shell scripting.
(I'am new to Shell scripting)

Can anyone kindly help me out,

Thanks,
Kanak.

Look at the man pages: man find

eg: # find / -name *log -mtime +5 -print

Hi Cameron,
Thanks for your reply. Basically I wanted to automate a task to find the list of files modified from any date in the past till date.

I will pass the past date as an argument to the schell script. I will take the current system's date ,find the number of days between them and run the find command. I donot want to change the script in the future.
This is my actual requirement.

  • How to define date variables in shell script
  • How can I access system date inside the shell script and assign to a varialbe
  • How to find the number of days between two dates

Thanks once again,
Kanak.

Use date format power to manipulate numbers:

myYear=`date +"%C%y"`
myMonth=`date +"%m"`
myDay="01"

You can use concatenation like "${myYear}${myMonth}${myDay}" in your logic.

Hope this helps :slight_smile: