Listing of files between two timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing of files between two timestamp
# 1  
Old 12-17-2015
Wrench Listing of files between two timestamp

Hi,

I want to list down the files between two timestamp. But I can not use newer or newermt command as it doesn't support these tokens.


Is there any other way to achieve this? Else I have to write too much of coding .

Input
Code:
 Dec 01 02:02
 Dec 02 05:07


Last edited by Franklin52; 12-17-2015 at 10:34 AM.. Reason: Please use code tags
# 2  
Old 12-17-2015
What operating system are you using?
Code:
uname -a

# 3  
Old 12-17-2015
Quote:
Originally Posted by Abhijit Sen
Hi,
I want to list down the files between two timestamp. But I can not use newer or newermt command as it doesn't support these tokens.

Is there any other way to achieve this? Else I have to write too much of coding .

Input
Code:
 Dec 01 02:02
 Dec 02 05:07

If you have Perl installed in your system, then:

Code:
ls -1 | perl -lne 'BEGIN {use Time::Local;
                         $t1 = timelocal(0,2,2,1,11,2015); # Start time = "1-Dec-2015 02:02:00"
                         $t2 = timelocal(0,7,5,2,11,2015); # End time   = "2-Dec-2015 05:07:00"
                         printf("List of files modified between %s and %s\n", scalar localtime $t1, scalar localtime $t2);
                     }
                     @x = stat($_);
                     if ($t1 <= $x[9] and  $x[9] <= $t2) {
                         printf("%s| %s\n", scalar localtime $x[9], $_);
                     }'

# 4  
Old 12-17-2015
Thanks for the reply. But I don't know perl and I want it in shell. Is there any utility for this?
# 5  
Old 12-17-2015
Quote:
Originally Posted by Abhijit Sen
Thanks for the reply. But I don't know perl and I want it in shell. Is there any utility for this?
No worries; in that case someone else should be able to help you out.
# 6  
Old 12-17-2015
Quote:
Originally Posted by Abhijit Sen
Hi,

I want to list down the files between two timestamp. But I can not use newer or newermt command as it doesn't support these tokens.


Is there any other way to achieve this? Else I have to write too much of coding .

Input
Code:
 Dec 01 02:02
 Dec 02 05:07

I assume that the newer and newermt that you are talking about are primaries for the find utility. So, one might assume that you're trying to print the names of files that have a modification timestamp that is greater than or equal to the first time you've shown us and less than the second time you've shown us. By saying that you can't use those tokens with newer and newermt, we can make lots of unwarranted assumptions about why you can't convert those strings into values that could be used with touch to create start and stop files that could be used with the find primary -newer.

I see that you have not answered Yoda's question. So, we can make a lot more guesses that might or might not work in your environment.

Instead of having us make lots of wild assumptions, please give us a clear description of your environment (operating system and shell; including versions of both), where these date strings are coming from (and why you can't use the information provided by those strings to create temporary files with those timestamps using the touch utility and using:
Code:
find path -newer temp_start_file ! -newer temp_end_file

to get what you need), and why the perl utility isn't a utility you can use in a shell script.
# 7  
Old 12-17-2015
Quote:
Originally Posted by Abhijit Sen
Thanks for the reply. But I don't know perl and I want it in shell. Is there any utility for this?
Are you sure? By using Perl you pretty much make it more portable, when it comes to dealing with date and time conversions.

Otherwise, you have to let people know what's the operating system you are using and the shell you are intending to invoke.
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 contents of a file after a timestamp

Hi All I have a file which contains the timestamp of the log and a message and I want to implement a polling mechanism, where this log file is pooled every 2 minutes and list the errors in the file. I want to list down the errors only after the timestamp in the file is more than the current... (2 Replies)
Discussion started by: infyanurag
2 Replies

2. 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

3. Shell Programming and Scripting

Identifying files with a timestamp greater than a given timestamp

I need to be able to identify files with file timestamps greater than a given timestamp. I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies

4. Shell Programming and Scripting

sort the files based on timestamp and execute sorted files in order

Hi I have a requirement like below I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory My files looks like this PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies

5. Windows & DOS: Issues & Discussions

DOS Dir - listing of full path and timestamp

Hi, (Apologies, I'm sure I'm not the first person to raise this question but so far in my searches haven't found a good answer). I would like to output a listing per line of filename (including full path) and 'last updated' timestamp. e.g: Z:\dir1\file1.txt 01/02/2010 10:43... (5 Replies)
Discussion started by: GM_AIX
5 Replies

6. Shell Programming and Scripting

Just listing size, timestamp & name of files in a directory

How can I list the files in a directory and just show the file size, date stamp, timestamp and file name.. I've been trying to ls -lrt the directory to a file and then use the cut command but I'm not having any luck with getting the proper results.. I thought i could use the -f switch and count... (4 Replies)
Discussion started by: Jazmania
4 Replies

7. Shell Programming and Scripting

perl script for listing files and mailing the all files

Hi, I am new to perl: I need to write perl script to list all the files present in directory and mail should be come to my inbox with all the files present in that directory. advanced thanks for valuable inputs. Thanks Prakash GR (1 Reply)
Discussion started by: prakash.gr
1 Replies

8. UNIX for Advanced & Expert Users

listing files excluding files from control file

I have a directory named Project.I have a control file which contains valid list of files.I would like list the files from directory Project which contains files other than listed in the control file. Sample control file: TEST SEND SFFFILE CONTL The directory contains followign... (15 Replies)
Discussion started by: ukatru
15 Replies

9. UNIX for Dummies Questions & Answers

Timestamp in directory listing

Hi, I need a help. I want to see all the files in the directory with the Time Stamp. I use the following command. $ls -lt This displays the files with time stamp, but not all the files. Only last few months, the files are displayed with timestamp, the old files are only have dates. ... (2 Replies)
Discussion started by: vijashok
2 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question