Listing latest modified or created files recursively


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing latest modified or created files recursively
# 8  
Old 10-04-2012
From current directory try:
Code:
date +%Y | read cy
find ./ -type f -exec ls -l {} \; | awk -v cy=$cy '
BEGIN{
 ms="JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC";
 split(ms,ma,",");
 for (i=1; i<=12; i++) mo[ma[i]]=i;
}
{
 l=$0;
 sub("  *[.][/].*","",l);
 tl=l;
 gsub("  *"," ",l);
 c=split(l,a);
 t="0000";
 y=a[c];
 if (a[c] ~ ":") {
    t=a[c];
    gsub(":","",t);
    y=cy;
 }
 m=a[c-2];
 m=toupper(m);
 d=a[c-1];
 if (mo[m] ~ /^$/) mo[m]="01";
 fl=$0;
 sub(tl,"");
 printf("%4d%02d%02d%s : %s\n", y,mo[m],d,t,$0);
}
' | sort -n

NOTE: The find will run for a while from top level dir.

Last edited by rdrtx1; 10-04-2012 at 04:52 PM..
# 9  
Old 10-04-2012
Quote:
Originally Posted by karumudi7
I want to display latest files (created or modified) recursively in a path.
Just like most people seeking help, you neglected to specify your operating system. Without that information we are forced to guess or we must limit ourselves to a less functional common denominator.

Your first post suggests you are not using a GNU/Linux system, otherwise -printf would have been recognized. Had it been supported, it could have accomplished the decoration in a decorate-sort-dedecorate solution:
Code:
find . -type f -printf '%T@\t%p\n' | sort -rn | cut -f2-

Since that doesn't seem possible, we have to turn elsewhere. Many systems have a stat tool (or something similar) which can output numerically sortable timestamp data, but these utilities are highly unportable. With the proper options, such a tool could be invoked effectively by find's -exec.

Regards,
Alister

Last edited by alister; 10-04-2012 at 06:42 PM..
# 10  
Old 10-05-2012
assuming your column 6,7,8 are month, date and time respectively...
try this...
latest at the last...Smilie

Code:
find $path -type f -exec ls -lt {} \;  | sort -k 6 -k 7 -k 8

# 11  
Old 10-05-2012
Quote:
Originally Posted by pamu
assuming your column 6,7,8 are month, date and time respectively...
try this...
latest at the last...Smilie

Code:
find $path -type f -exec ls -lt {} \;  | sort -k 6 -k 7 -k 8

The ls date format is locale dependent. In what locale does your suggestion work? Can you show a sample of that locale's ls long-format output?

Since ls is never called with more than one argument, the -t option serves no purpose.

Regards,
Alister
# 12  
Old 10-05-2012
Quote:
Originally Posted by alister
The ls date format is locale dependent. In what locale does your suggestion work? Can you show a sample of that locale's ls long-format output?
I am running it on bash and as earlier mentioned in my previous post, ls format is month, date and time for columns 6,7 & 8 respectively. i have tried that and it works fine thats why i've suggested this...Smilie

May be for other format we need to modify it lit bit..Smilie
# 13  
Old 10-05-2012
Quote:
Originally Posted by pamu
i have tried that and it works fine
"locale dependent" means "what works for you won't work for someone else". Even worse, it will fail in ways that aren't obvious -- the output will be scrambled or wrong, rather than getting an error message or "option not supported".

It's better to write code that works in many places than make someone else fix code that doesn't.
# 14  
Old 10-05-2012
Quote:
Originally Posted by Corona688
"locale dependent" means "what works for you won't work for someone else". Even worse, it will fail in ways that aren't obvious -- the output will be scrambled or wrong, rather than getting an error message or "option not supported".

It's better to write code that works in many places than make someone else fix code that doesn't.
As what you said "locale dependent". Okies.. that's fine. agreed..
But I'll try as per what resources I have. This is not possible to check for all other types if I don't have it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Modified or latest files copy from windows to Linux

To copy the file from windows to linux i use pscp command(pscp source user@destination). Know i want to copy the latest modified or created files from windows to linux. could any one please help me out with it. Thanks and Regards, Sourabh (2 Replies)
Discussion started by: SourabhChavan
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. UNIX for Dummies Questions & Answers

To find the latest modified file in a directory

I am trying to fetch the latest modified file from a directory using the command find . -type f -exec ls -lt \{\} \+ | head | awk '{print $9}' After the O/P, I get the below mentioned error and the command doesnt terminate at all. find: ls terminated by signal 13 find: ls terminated by... (2 Replies)
Discussion started by: Sree10
2 Replies

4. Shell Programming and Scripting

Listing latest & large files from a mounted drive

Hi All, My AIX server have a mounted drive "/stage". I want to list the latest modified/created files in this drive. Also large files in this drive. I tried to ls -l | sort +4nr | head -10 Someother solutions to list from entire drive. Thanks. :) (6 Replies)
Discussion started by: karumudi7
6 Replies

5. UNIX for Dummies Questions & Answers

Recursively listing of the file

Hi, I want to list out the files for a particular date recursively along with timestamp and directory name . I tried using command ls -lRt this list out all the files along with directory structure but i want for a particular date so i tried with ls -lRt | grep 20110809 in... (9 Replies)
Discussion started by: Abhi2910
9 Replies

6. Shell Programming and Scripting

to pick the latest file modified in a directory

I wan to pick the latest modified file name and redirect it to a file .. ls -tr | tail -1 >file but this is printing file ins side the filename , can anyone help me out (5 Replies)
Discussion started by: vishwakar
5 Replies

7. UNIX for Dummies Questions & Answers

How to get the latest modified file name in /home directory?

I only know how to list all sub-directories or files in specified directory. I don't know how to order them by modified date, furthermore, I don't know how to get the top one file in the sorted list. Wish you can do me a favor. Thanks in advance! (3 Replies)
Discussion started by: crest.boy
3 Replies

8. Shell Programming and Scripting

Find the directory modified/created before 4 days

Hi, I have an application which creates some directories while running. I want to delete these directories which are 4 days older. i tried find . type d -mtime +1 -print And it is working fine.. but find . type d -mtime +4 -print is not giving any results which are 4 days... (6 Replies)
Discussion started by: Tuxidow
6 Replies

9. Shell Programming and Scripting

How can i search a file which has been created or modified in last five minutes

Hi Can some one please help me How can i search a file which has been created or modified in last five minutes I have used the command find . -mmin -5 and it does not work i get an error -mmin is bad option Please help Much regards Tarun (2 Replies)
Discussion started by: tarundeepdhawan
2 Replies

10. Shell Programming and Scripting

List Files & Folders created/modified

Hello people, I want to list the files & folders created/modified since a particular date say June 2006. I know I can list recursively thru the folders and use awk to extract the date column to get the desired output. Just wanted to check whether there is an easier way to do this. Please... (2 Replies)
Discussion started by: tipsy
2 Replies
Login or Register to Ask a Question