How to list file names in a certain date range using ls command? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

How to list file names in a certain date range using ls command?

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-08-2008
satish.vutti satish.vutti is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 9 December 2008, 12:59 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Data How to list file names in a certain date range using ls command?

Hi experts,

I Need to print file names in a certain date range using ls. Please help me with any sample script. Thanks a lot in advance.

Regards,
Satish
Sponsored Links
    #2  
Old 09-08-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts
If your find command has the capability to find files by age, you can use that. It's a bit tricky if you haven't used it before, but this site is full of examples. Start with the FAQ: http://www.unix.com/answers-frequent...d-command.html
Sponsored Links
    #3  
Old 09-08-2008
satish.vutti satish.vutti is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 9 December 2008, 12:59 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by era View Post
If your find command has the capability to find files by age, you can use that. It's a bit tricky if you haven't used it before, but this site is full of examples. Start with the FAQ: http://www.unix.com/answers-frequent...d-command.html
Hi Era,

Thanks for quick reply. But my requirement has changed...i want a command instead of a script which can compare the files and list them with in a given date range. Actually am invoking this command in my service and i will supply two dates as my input and my output shud be a list of files. Please help me.
    #4  
Old 09-08-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 18 December 2014, 10:22 AM EST
Location: Out running a Marathon.
Posts: 2,342
Thanks: 74
Thanked 158 Times in 145 Posts
Tools You did not provide much to go on, but

try

Code:
ls -lt

list files in date order
or

Code:
ls -ltr

list files in reverse date order

From these, your could add a grep to select a specific month in instance.
Sponsored Links
    #5  
Old 05-27-2009
tonan tonan is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 19 September 2011, 6:51 AM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
#!/bin/ksh
#################################################
## File: findDateRange.sh
## Date: May 27, 2008
## Author: Saurav Sen
## Purpose: A script to find the files within
## a given date range
#################################################
echo "You have to provide the path, start date and the end date"
echo
echo "Enter the path to start search"
read fpath
echo "Please enter the start date in the format YYYYMMDD"
read strtdt
echo "please enter the end date in the format YYYYMMDD"
read enddt
touch -t ${strtdt}0000 /tmp/newerstart
touch -t ${enddt}2359 /tmp/newerend
#find ./ \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -print
find $fpath \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -exec ls -l {} \;
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using 'date' to list a range of dates TAPE Shell Programming and Scripting 4 10-14-2010 05:43 PM
List files with Date Range and Zip it nokiak810 Shell Programming and Scripting 2 08-01-2010 02:47 AM
How to list file names instead of lines when grep a gzcat command? HugoH UNIX for Dummies Questions & Answers 2 07-14-2009 06:56 PM
Command to list directory names only stevefox UNIX for Dummies Questions & Answers 6 11-29-2007 08:06 PM
Need to print file names in a certain date range using ls Shamwari UNIX for Dummies Questions & Answers 2 10-08-2001 08:14 PM



All times are GMT -4. The time now is 05:54 AM.