Languages and Scripting

files listing for specific date

 
SOLVED
Go to solution
Nilesh_Rami
Occasional Advisor

files listing for specific date

How to get listing of files which has been created on specific date I.e. I want the list of files created on 1st of july 2016

6 REPLIES 6
Steven Schweda
Honored Contributor

Re: files listing for specific date

A forum or Web search for keywords like:

      find newer touch

should find many examples of using "touch" to create files with the
date-time boundries, and then "find -newer" to do the search.

      man touch
      man find

Dennis Handly
Acclaimed Contributor

Re: files listing for specific time range

>How to get listing of files which has been created on specific date range

 

Note: You can't get "created" only modified or accessed.

Nilesh_Rami
Occasional Advisor

Re: files listing for specific time range

Thanks Dennis,

Let me know the command to get modified or accessed files on 1st of July.

Dennis Handly
Acclaimed Contributor

Re: files listing for specific time range

>Let me know the command to get modified or accessed files on 1st of July.

 

As Steven said, you need to search:

http://community.hpe.com/t5/Languages-and-Scripting/Script-to-get-quot-last-month-quot/m-p/5017836

http://community.hpe.com/t5/Languages-and-Scripting/help-newer-option-in-find/m-p/5122333

http://community.hpe.com/t5/System-Administration/find-mtime-newer/m-p/4875192

http://community.hpe.com/t5/Languages-and-Scripting/delete-the-files-with-date-wise/m-p/6391751

http://community.hpe.com/t5/Languages-and-Scripting/script-to-move-files-by-month/m-p/3968863

 

Use "touch -a -m" to set both access and modification times.

If you want both accessed OR modified in a date range you need an OR:

find ... \( -newer start -o -newera start \) \(! -newer stop -o ! -newera stop \)

Bill Hassell
Honored Contributor
Solution

Re: files listing for specific time range

There is no single command to accomplish what you want. You must create 2 files with the timestamp range you need, in this case, July 1st. Then you construct a find command that looks for files newer than the start file and older than the stop file. Here are the steps:

touch -t 07010000 /tmp/jul1_start
touch -t 07012359 /tmp/jul1_stop
find /somedir -newer /tmp/jul1_start ! -newer /tmp/jul1_stop -type f -exec ls -l {} \;

So some details:

The touch command will create a new file or change the timestamp of an existing file.The man page for touch defines several forms of the date but the minimum form is MMDDhhmm (8 numbers). So the two reference dates are both 0701 (July 1st). One technical note is that a file created on Jul 1st at 00:00 will *not* be found. Only Jul 1st 00:01 will be newer than 070000. So for an exact selection, use:

touch -t 06305959 /tmp/jul1_start

 Now, a file with a Jul 1st 00:00 timestamp will be found.
The second file is fine using 07012359 because "not newer" (the ! -newer construct) will be true if the file is Jul 1st 23:59.

I put the reference files in a specific location so that temp files don't get scattered in random locations.

The -type f is important because you said the requirement is for a file and not directories or symlinks, etc. This will prevent finding both directories and files.

The -exec is used only for testing. It will run the command ls -l on the results of the find. You can remove it to show just the filenames.



Bill Hassell, sysadmin
Nilesh_Rami
Occasional Advisor

Re: files listing for specific time range

Hi Bill,

Thank you very much for your reply, its really very helpful to me and really appreciate regarding your step by step guidelines which really help me to find out the solution of my issue after long time.

Regards,

Nilesh