Get the newest files based on date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the newest files based on date
# 1  
Old 07-27-2009
Get the newest files based on date

Hello friends,
I'm learning to script, and I need help.

How can I get the latest/newest files based on date? the format is as following:

Feb 07 19:25 TESTPWD_file_1vk6pn40_19519_1
Feb 07 19:46 TESTPWD_file_1uk6pn40_19518_2
Feb 07 19:47 TESTPWD_file_20k6pn40_19520_2
Feb 07 19:56 TESTPWD_file_23k6po9j_19523_1
Feb 07 19:56 Config_TESTPWD_020709:19:10.TXT

Jun 06 19:38 TESTPWD_10204_file_77kgu17l_19687_1
Jun 06 19:40 TESTPWD_10204_file_7akgu17p_19690_1
Jun 06 20:05 TESTPWD_10204_file_7dkgu3ba_19693_1
Jun 06 20:11 TESTPWD_10204_file_7ckgu344_19692_1
Jun 06 20:21 TESTPWD_10204_file_7ckgu344_19692_2
Jun 06 20:22 Config_TESTPWD_10204_060609:19:10.TXT

Jul 27 19:38 TESTPWD_10204_file_77kgu17l_19687_1
Jul 27 19:40 TESTPWD_10204_file_7akgu17p_19690_1
Jul 27 19:59 TESTPWD_10204_file_79kgu17l_19689_2
Jul 27 20:05 TESTPWD_10204_file_7dkgu3ba_19693_1
Jul 27 20:11 TESTPWD_10204_file_7ckgu344_19692_1
Jul 27 20:22 Config_TESTPWD_10204_060609:19:10.TXT

Thanks for your help.
# 2  
Old 07-27-2009
Personally, I would use the stat function to get the file date and store it into an array. Then you should be able to evaluate the newer files against the current time.

@filedata=stat($filename);
$mtime=$filedata[9]; # The tenth element is the mtime from the epoch
# 3  
Old 07-27-2009
you mean latest file in a DIR??
Code:
ls -lrt|tail -1

will give you latest file in that DIR
# 4  
Old 07-27-2009
I need to get **a group of latest files** based on date.

Thanks for responding.

---------- Post updated at 02:45 PM ---------- Previous update was at 02:41 PM ----------

For example, I need to get all of these files based on the latest/new date


Jul 27 19:38 TESTPWD_10204_file_77kgu17l_19687_1
Jul 27 19:40 TESTPWD_10204_file_7akgu17p_19690_1
Jul 27 19:59 TESTPWD_10204_file_79kgu17l_19689_2
Jul 27 20:05 TESTPWD_10204_file_7dkgu3ba_19693_1
Jul 27 20:11 TESTPWD_10204_file_7ckgu344_19692_1
Jul 27 20:22 Config_TESTPWD_10204_060609:19:10.TXT
# 5  
Old 07-27-2009
then use find command...
Code:
find . -mtime -1 -ls -long

# 6  
Old 07-27-2009
vidyadhar85,

Perfect. This is the code I need.

Thank you!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find the files based on date from filelist

Hi All, I have a filelist which contains the "ls" output, i want to extract the filenames written in this files based on date. I know i can run loop and extract the file but i want to avoid it. also there is find command which can be used on directory i.e. find . -type f -newermt "2019-09-25"... (3 Replies)
Discussion started by: kumarinfa
3 Replies

2. Shell Programming and Scripting

Delete all but 3 newest files

This is related to my post on backup up files. I really appreciate all the help too. :-) I would like to delete all but the 3 newest files in my backup directory. /media/andy/MAXTOR_SDB1/Ubuntu_Mate_18.04/ For example Ubuntu_Documents.zip_09Aug2018_12_00... (2 Replies)
Discussion started by: drew77
2 Replies

3. Shell Programming and Scripting

Find file by filename or with newest modified date

Hi, I have a directory that has numerous files in it, and there is two which are named "filerec_ddmmyyHH24MMSS" by the time they are created so "filerec_010615012250" was created at 01:22:50 on 1st June 2015. I need to find the most recently created of those 2 files and get the contents of... (4 Replies)
Discussion started by: finn
4 Replies

4. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt 2012-06-15 08:13" ! -newermt 2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

5. Shell Programming and Scripting

finding the files based on date..

Hi to every one , i had ascenario like this.. i had path like export/home/pmutv/test/ in this i will recive 43 files daily with each file having that days date i.e like product.sh.20110512 like this i will 43 files every day i had to find the files. if files are avaliable i... (2 Replies)
Discussion started by: apple2685
2 Replies

6. UNIX for Dummies Questions & Answers

Remove files based on date

Hello team, I have a number of files in a folder which are dated yesterday and today.Can i remove all the files which i created today based on date?? is there any syntax for this ?? (1 Reply)
Discussion started by: kanakaraju
1 Replies

7. Shell Programming and Scripting

Deleting the files based on the date's

I have to write one script which will delete the files in the below passion. If today is 17-Feb-2010 then the script delete only 17-JAN-2010 files from the directory. Could you please help me, How will I delete the files when the year is leap year, if today is 30th Mar 2010 then how will... (1 Reply)
Discussion started by: kandi.reddy
1 Replies

8. Shell Programming and Scripting

Copy files based on date

Hi all i am having so many files in my directory.Is there any option to copy files based on date. example i am having file this -rw-rw-r-- 1 ram user 1 Feb 2 17:12 abc -rw-rw-r-- 1 ram user 1 Feb 2 17:12 bnw -rwxrwxr-x 1 ram user 21122 Feb 4... (3 Replies)
Discussion started by: suryanarayana
3 Replies

9. Shell Programming and Scripting

Count of files based on date?

Hi Friends, Can anyone help me with this: To get the count of files that are existing in a directory created on a perticular date like in the example (01/08) .(having same pattern for the filename) ex: FileName Creted Date FILE001 01/08/2007 FILE005 ... (6 Replies)
Discussion started by: sbasetty
6 Replies

10. UNIX for Dummies Questions & Answers

Remove files based on date

I am trying to write a shell script that will remove files in a directory based on the date. For instance, remove all files older than yesterday. Any ideas? (4 Replies)
Discussion started by: hshapiro
4 Replies
Login or Register to Ask a Question

Featured Tech Videos