How to list todays file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to list todays file
# 8  
Old 07-17-2009
Try first using find to cut the list down to the last 24 hours which cleverly avoids dealing with files over one year old (different ls format), then check the file timestamp against today's date.

Code:
#!/bin/ksh
TODAY="`date +'%b %e'"  # e.g. "Feb  3"
find `pwd` -type f -mtime -1 -print | while read FILENAME
do
        FOUND=""
        FOUND=`ls -lad "${FILENAME}"|grep "${TODAY}"|wc -l`
        if [ ${FOUND} -eq 1 ]
        then
                echo "${FILENAME}"
        fi
done

# 9  
Old 07-17-2009
Try this:

Code:
todays=$(date '+ %b %d ') 
ls -altr | egrep "$todays"

Or if you want from subdir files also, try this:
Code:
      ls -altr $(find . -name "sese*" -type f -ctime 0)

One problem with this is, if no files are found per my template ("sese*") then it will list all files.
It is equal to giving the 'ls -altr' command. To over come that try this:
Code:
   ls -altr $(find . -name "sese*" -type f -ctime 0 && echo "Error")

Output result:
ls: Error: not found

Last edited by edidataguy; 07-19-2009 at 02:31 AM.. Reason: Reformatted
# 10  
Old 07-17-2009
The following should do the trick:
Code:
find . -name "esi01v*" -type f -daystart -mtime 0

# 11  
Old 07-17-2009
Hi tkleczek,

encountered the following error :

(hello): find . -name "esi01v*" -type f -daystart -mtime 0
find: bad option -daystart
find: path-list predicate-list

Hi edidataguy & methyl,

thanks for the codes, its working fine but i need a command line.
# 12  
Old 07-17-2009
I use an alias "today":

today: aliased to find . -daystart -mtime 0

today | grep esi01v

or

find . -daystart -mtime 0 -name "esi01v*"

should get you there

mbs
# 13  
Old 07-17-2009
Hi mbs,

same error ...bad option -daystart...
# 14  
Old 07-17-2009
Both of the below lines are single liners:
Code:
ls -altr "esi01v*" | egrep "$(date '+ %b %d ')"
ls -altr $(find . -name "esi01v*" -type f -ctime 0 && echo "Error")

--- I know it is a bit late response, but the " needs to be removed and -altr should be -ltr.
Code:
ls -ltr esi01v* | egrep "$(date '+ %b %d ')"


Last edited by edidataguy; 07-20-2009 at 11:54 PM.. Reason: Fixed the error
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to list todays file in perticular folder?

How to list todays file in perticular folder Moved thread to appropriate forum (9 Replies)
Discussion started by: pspriyanka
9 Replies

2. UNIX for Dummies Questions & Answers

Help in script to check file name with todays date

I am trying to include a snippet in my script to check if the file created is having today's date. eg: File name is : ABC.YYYYMMDD-nnn.log The script should check if 'YYYYMMDD' in the above file name matches with today's date. Can you please help me in achieving this. Thanks in advance!! (5 Replies)
Discussion started by: kiran1112
5 Replies

3. Shell Programming and Scripting

Count for only todays files.

Hi, I unable to find the direct command get the total count for the below files with today date. ls -lrt c90.txt n5.txt t1.txt k3.txt h9.txt s1.txt n2.txt a123.txt -rw-rw-r-- kkk klkl 980 Apr 26 19:00 c90.txt -rw-rw-r-- kkk klkl 80 Apr 26 19:00 n5.txt -rw-rw-r-- kkk klkl 12890 Apr 26... (3 Replies)
Discussion started by: onesuri
3 Replies

4. Shell Programming and Scripting

How to list todays and yesterdays .rej files from a directory?

I am trying to display todays and yesterdays .rej files from a directory. ls -lrt *.rej | grep 'Aug 12' ; ls -lrt *.rej | grep 'Aug 13' Which is working as above. But i want take 'Aug 12' and 'Aug 13' from a variable and the command should work everyday. I am able to get todays files by... (9 Replies)
Discussion started by: GopalKrishnaP
9 Replies

5. Shell Programming and Scripting

how to get todays file name

Hi ! there can you please tell me how to get full files having today date like if i have files like this(below) , i want to grep only sra + today's date + what ever thing is there after date . grep `sra*$date*.csv` >>> i tried this one but its not working . sra28-08-2011xyz.csv... (1 Reply)
Discussion started by: sravan008
1 Replies

6. UNIX for Dummies Questions & Answers

need to zip all the files excluding todays file

HI All, At present in my server the log folder was filled up and causing memory issue. So I am planning to write a script in such a way that the files which are older than 30 days will be deleted and also need to find the files which were not compressed and need to compress this file.... (4 Replies)
Discussion started by: arumilli
4 Replies

7. Shell Programming and Scripting

List/Range Todays Log.

Hi All, I am mediator Shell programmer, Just have an hands on experice :-), i am writing a shell scirpt to list logs of todays date from /var/log/messages. I need to ur kind help where if i run this script from cron. the script should filter todays logs only from /var/log/messages. Below... (4 Replies)
Discussion started by: anand.kulkarni
4 Replies

8. Shell Programming and Scripting

How to grep a string in todays file

Hello guys - I am new to Unix. I am trying to understand how to grep a perticular string in todays file? I am trying this syntax but not getting what I am looking for: % grep `date '+%d/%b/%Y'` For instance there are 2 files generated today with same data. I am trying to find them and... (21 Replies)
Discussion started by: DallasT
21 Replies

9. Linux

Comparing the file drop date with todays date

Daily one file will dropped into this directory. Directory: /opt/app/jt/drop File name: XXXX_<timestamp>.dat.gz I need to write a script which checks whether the file is dropped daily or not. Any idea in the script how can we compare timestamp of the file to today's date?? (3 Replies)
Discussion started by: Rajneel
3 Replies

10. Shell Programming and Scripting

want to delete timestamp from todays file

i want to delete the time stamp from the file which have a date of yester day 640878 Nov 6 09:08 fbres.01.20031106:09:08:30 here is what my ls -lt command shows in current directory it want it to be 640878 Nov 6 09:08 fbres.01.20031106 thanks (5 Replies)
Discussion started by: maverick
5 Replies
Login or Register to Ask a Question