ls -l all files created between two times


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ls -l all files created between two times
# 1  
Old 10-24-2008
ls -l all files created between two times

solaris 8 and solaris 10
c shell

I have a /local/tmp/ directory that is cleared out every day and files are created in it all day long from 0000 - 2359 (24 hour clock) A new file is created in this directory every couple of minutes.

I want a script "rrtime" that takes two arguments hhmm1 and hhmm2 and lists all files in /local/tmp/ that were created between hhmm1 and hhmm2... the times are given in 24hour format, for example 1500 - 1600
Sounds easy enough? If somebody could give me an example script, even one that is SIMILAR to what I need here....that would be awesome!
thank you so much!

example usage: rrtime 1500 1600
(this would list all files in /local/tmp/ created between 15:00 and 16:00)
# 2  
Old 10-24-2008
Hammer & Screwdriver Here is a start to think about (one approach)

This snippet will give you the last modification time for a file, in this case file305.

Code:
> stat -c%y file305
2008-10-24 12:35:18.183724000 -0700
> stat -c%y file305 | cut -d" " -f2
12:35:18.183724000
> stat -c%y file305 | cut -d" " -f2 | cut -d"." -f1
12:35:18

I think you will want to create a for loop, to cycle through filenames in your specific directory. Then, on each file, execute with something like the above code.
# 3  
Old 10-24-2008
Hammer & Screwdriver To help find files

This will find files for today:
Code:
> ls -l | grep "`date | cut -d" " -f2-3`"
drwxrwx---  2 xxx dp 1536 Oct 24 12:35 ./
drwxrwx--- 99 xxx dp 3072 Oct 24 08:48 ../
-rw-rw----  1 xxx dp  843 Oct 24 07:36 file301
-rw-rw----  1 xxx dp  141 Oct 24 12:35 file305
-rw-rw----  1 xxx dp    4 Oct 24 12:35 file305x

And this will strip out to just files (not directories) and only have the names:
Code:
> ls -l | grep "`date | cut -d" " -f2-3`" | grep "^-" | awk '{print $9}'
file301
file305
file305x

So, combine the logic to list out today's files, with my previous post on determining the exact time, and you should be in business.
# 4  
Old 10-24-2008
joeyg, thank you for the help...you gave me great help on listing today's files in the 2nd post...and the first post the stat command looks like it will also be of great help....I was hoping for a little more help on creating the exact logic loop (or an example) that will list only the files created between the two times....somehow create an IF loop that looks at the output of this stat command and compares it with hhmm1 and hhmm2 if it is greater than hhmm1 and less than hhmm2 then list the file........in any case, thanks again!!
# 5  
Old 10-25-2008
Hammer & Screwdriver There are more elegant ways, but something to ponder...

Code:
rm filelist good_files
starttime=10:00:00
endtime=11:00:00

ls -l | grep "`date | cut -d" " -f2-3`" | grep "^-" | awk '{print $9}' >filelist
while read myfile
  do
  filetime=$(stat -c%y $myfile | cut -d" " -f2 | cut -d"." -f1)
# now check for the times in ranges (not sure about syntax)
  if [ $filetime -ge $starttime ] && [ $filetime -le $endtime ]
     then
     echo "Good file"
     echo $myfile >>good_files
  fi
done <filelist  
# show the good_files
cat good_files

You can try the above script. Not sure of all the syntax - have not tried out the coding. But, should be something to start with.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

2. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

3. Programming

need help with C access times of files

i am just checking the access times of files in C, but i am unsure about something say i have a c program called acc.c (only file in directory) then i compile it and get acc then i ran acc and it tells me all the files in the current directory thats access time is only later than acc.c for... (5 Replies)
Discussion started by: omega666
5 Replies

4. Shell Programming and Scripting

Count todays created files and old files

Hello experts, I used following approach to get listing of all files of remote server. Now I have remote server file information on same server. I am getting listing in the output.txt I want to count today's created files and old files. I want to compare the numbers... (11 Replies)
Discussion started by: dipeshvshah
11 Replies

5. Shell Programming and Scripting

Gzip files as they are created

Hello. I have a scripting query that I am stumped on which I hope you can help with. Basically, I have a ksh script that calls a process to create n number of binary files. These files have a maximum size of 1Gb. The process can write n number of files at once (parallel operation) based on the... (4 Replies)
Discussion started by: eisenhorn
4 Replies

6. Shell Programming and Scripting

Files created in last 24 hours

I need a script which list the files which is starting with the word heap*** and that is created before past 24 hours.I need the script using find command. please help me on this. (1 Reply)
Discussion started by: jayaramanit
1 Replies

7. UNIX for Dummies Questions & Answers

Files created by particular user

How i get the all the files created by particular user?? (2 Replies)
Discussion started by: Anshu
2 Replies

8. UNIX for Dummies Questions & Answers

Last modification times of files less than 6 months old

How do I get the modification time for files less than 6 months old? (It seems for fles as old or older than this I get to see only the day,month and year. I tried the option -u but it gives me the last accessed time) (1 Reply)
Discussion started by: Abhishek Ghose
1 Replies

9. UNIX for Dummies Questions & Answers

files created within last 10 mins

Any simple 1 liners to check a directory to see if a file was created within the last 10 mins? (5 Replies)
Discussion started by: frustrated1
5 Replies

10. UNIX for Dummies Questions & Answers

Two Files Created For Every One?

Hello, my linux box is, for some reason, creating two files when I creat one. For example, if I create a file via the VI editor called TestFile, the box will create: TestFile TestFile~ Does anyone have any ideas as to why I'm getting that second file with the ~ at the end of it? ... (1 Reply)
Discussion started by: Atama
1 Replies
Login or Register to Ask a Question