How to list todays file

 
Hi Friends,
 
How to list todays file from a directory listing of files for amny dates.
 
I tried with the following options but not working :
 
find . -name "esi01v*" -mtime 1 -ls
 
find . -name "esi01v*" -ctime 1 -ls
 
find . -name "esi01v*" -mtime 1
 
Please advise

Try:

find . -type f -mtime 1 -exec ls {} \+

please tell me where do I give the pattern like abcd* or esi001*

something like this :

find . -name "esi01v*"  -type f �ctime 0 | xargs ls -l

Hi Panyam,

I tired but it is listing yesterdays files also

tried with -ctime with 0 1 etc but not the correct results

then modify that script a bit...

find . -name "esi01v*" -type f -mtime 1 -exec ls {} \+

HI Rakesh,

afraid...not working. itried other options in the above command line as well but not getting the desired results.

is there anyway i can match todays date Jul 17 with the ls -lrt command date and extract file

like :
date | awk '{print $2}' | cut -c 1-3 > this command will return Jul
date | awk `{print $3}` > will return 17

ls -lrt esi01v* | awk '{print $6 $7}' > will return Jul 17

is it possible to concatenate the first 2 match with the 3rd and list files

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.

#!/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

Try this:

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

Or if you want from subdir files also, try this:

      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:

   ls -altr $(find . -name "sese*" -type f -ctime 0 && echo "Error")

Output result:
ls: Error: not found

The following should do the trick:

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

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.

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

Hi mbs,

same error ...bad option -daystart...

Both of the below lines are single liners:

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.

ls -ltr esi01v* | egrep "$(date '+ %b %d ')"

Can you be more specific.

HI friend,

now i am getting the error variable syntax for bothe command liners.

*not sure if there is any way to get a 1 liner to list todays file

---------- Post updated at 09:07 PM ---------- Previous update was at 09:06 PM ----------

Hi Methyl,

I have used your code and its working fine.
But I need a 1 liner which I am not able to work out.

---------- Post updated at 09:10 PM ---------- Previous update was at 09:07 PM ----------

i want to execute a one line command which will list all files of a particular pattern with todays date.
The same pattern files may be present for yesterday also but the command will list only file with current date (todays date)

What do you want the output to look like?

only the file names would do

Fair attempt at a one-liner. Does not work for filenames containing space characters but does avoid calling "date" for each filename.

TODAY="`date +'%b %e'`";find `pwd` -type f -name "esi01v*" -mtime -1 -exec ls -lad "{}" \; | grep " ${TODAY} "|awk '{print $9}'

What we can do is to "touch" a file that is created today at 00:00:00 and we can use shell to compare those files newer than this file

touch -t 200907180000 /tmp/today.file
for i in `find . -type f`
do
    if [ $i -nt /tmp/today.file ]; then
        echo $i
    fi
done

BTW, the "-nt" newer only available in ksh and bash

---------- Post updated at 11:29 PM ---------- Previous update was at 10:13 PM ----------

Sorry, we need to make it more generic

touch -t `date '+%Y%m%d0000'` /tmp/today.file
for i in `find . -type f`
do
    if [ $i -nt /tmp/today.file ]; then
        echo $i
    fi
done