How to find last two files for a month?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to find last two files for a month?
# 1  
Old 04-10-2014
How to find last two files for a month?

Hi All,
I need to find last two files for the month.
lets say there are following files in directory
Code:
-rwxr-xr-x   1 user  userg         1596 Mar 19 15:43 c.txt
-rwxr-xr-x   1 user  userg         1596 Mar 21 15:43 d.txt
-rwxr-xr-x   1 user  userg         1596 Mar 22 15:43 f.txt
-rwxr-xr-x   1 user  userg         1596 Mar 24 15:43 h.txt
-rwxr-xr-x   1 user  userg         1596 Mar 25 15:43 w.txt
-rwxr-xr-x   1 user  userg         1596 Feb 12 15:43 q.txt
-rwxr-xr-x   1 user  userg         1596 Feb 21 15:43 a.txt
-rwxr-xr-x   1 user  userg         1596 Feb 22 15:43 s.txt
-rwxr-xr-x   1 user  userg         1596 Feb 23 15:43 k.txt
-rwxr-xr-x   1 user  userg         1596 Feb 27 15:43 j.txt

output should be:
Code:
Mar 24 15:43 h.txt
Mar 25 15:43 w.txt
Feb 23 15:43 k.txt
Feb 27 15:43 j.txt

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 04-10-2014 at 09:48 AM..
# 2  
Old 04-10-2014
You would need to repeat this monthwise:
Code:
 ls -lt | grep Mar | head -2

This User Gave Thanks to RudiC For This Post:
# 3  
Old 04-10-2014
Code:
ls -lrt | awk '{a[(NR % 2) $6] = ($6 FS $7 FS $8 FS $9)} END {for(x in a) print a[x]}'

This User Gave Thanks to SriniShoo For This Post:
# 4  
Old 04-10-2014
Try :

Code:
$ find . -name '*.txt' -mtime -60 -mtime +10 -ls

-60 60 days old but

+10 days younger since today is April 10

10< query <60

Last edited by Akshay Hegde; 04-10-2014 at 11:32 AM.. Reason: to add info
# 5  
Old 04-10-2014
Thanks a lot Srini & Rudic
Actualy i want all files other than last two files per month.
can it be posibble?
Code:
-rwxr-xr-x   1 user  userg         1596 Mar 19 15:43 c.txt
-rwxr-xr-x   1 user  userg         1596 Mar 21 15:43 d.txt
-rwxr-xr-x   1 user  userg         1596 Mar 22 15:43 f.txt
-rwxr-xr-x   1 user  userg         1596 Mar 24 15:43 h.txt
-rwxr-xr-x   1 user  userg         1596 Mar 25 15:43 w.txt
-rwxr-xr-x   1 user  userg         1596 Feb 12 15:43 q.txt
-rwxr-xr-x   1 user  userg         1596 Feb 21 15:43 a.txt
-rwxr-xr-x   1 user  userg         1596 Feb 22 15:43 s.txt
-rwxr-xr-x   1 user  userg         1596 Feb 23 15:43 k.txt
-rwxr-xr-x   1 user  userg         1596 Feb 27 15:43 j.txt

output should be:

Code:
c.txtd.txtf.txtq.txta.txts.txt

---------- Post updated at 09:35 AM ---------- Previous update was at 09:32 AM ----------

Code:
-rwxr-xr-x   1 user  userg         1596 Mar 19 15:43 c.txt
-rwxr-xr-x   1 user  userg         1596 Mar 21 15:43 d.txt
-rwxr-xr-x   1 user  userg         1596 Mar 22 15:43 f.txt
-rwxr-xr-x   1 user  userg         1596 Mar 24 15:43 h.txt
-rwxr-xr-x   1 user  userg         1596 Mar 25 15:43 w.txt
-rwxr-xr-x   1 user  userg         1596 Feb 12 15:43 q.txt
-rwxr-xr-x   1 user  userg         1596 Feb 21 15:43 a.txt
-rwxr-xr-x   1 user  userg         1596 Feb 22 15:43 s.txt
-rwxr-xr-x   1 user  userg         1596 Feb 23 15:43 k.txt
-rwxr-xr-x   1 user  userg         1596 Feb 27 15:43 j.txt

output should be:

Code:
For Marc.txtd.txtf.txtfor Febq.txta.txts.txt

Last edited by vbe; 04-10-2014 at 01:41 PM.. Reason: trying to sort the code (tags?)
# 6  
Old 04-10-2014
This is definitely unreadable!
# 7  
Old 04-10-2014
Hi All,
I need to find all files other than last two files per month.
lets say there are following files in directory
Code:
Mar 19 15:43 c.txt
Mar 21 15:43 d.txt
Mar 22 15:43 f.txt
Mar 24 15:43 h.txt
Mar 25 15:43 w.txt
Feb 12 15:43 q.txt
Feb 21 15:43 a.txt
Feb 22 15:43 s.txt
Feb 23 15:43 k.txt
Feb 27 15:43 j.txt

output should be:
Code:
Mar 19 15:43 c.txt
Mar 21 15:43 d.txt
Mar 22 15:43 f.txt
Feb 12 15:43 q.txt
Feb 21 15:43 a.txt
Feb 22 15:43 s.txt


Last edited by Franklin52; 04-11-2014 at 05:49 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need last month files after 10th of every month

Hi, I need all file names in a folder which has date >= 10th of last month, Example : files in folder AUTO_F1_20140610.TXT BUTO_F1_20140616.TXT CUTO_F1_20140603.TXT FA_AUTO_06012014.TXT LA_AUTO_06112014.TXT MA_AUTO_06212014.TXT ZA_AUTO_06232014.TXT Output: AUTO_F1_20140610.TXT... (9 Replies)
Discussion started by: nani1984
9 Replies

2. Shell Programming and Scripting

How to find all files other than last two dates per month and year?

Hi All, lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 a.txt -rwxr-xr-x 1 user userg 1596 Mar 19 2012 b.txt -rwxr-xr-x 1 user userg 1596 Mar 22 2012 c.txt -rwxr-xr-x 1 user userg 1596 Mar 24 2012 d.txt... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

3. Shell Programming and Scripting

How to find all files other than first two dates & last date per month and year?

how to find all files other than first two dates & last date per month and year Hi All, lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 a.txt -rwxr-xr-x 1 user userg 1596 Mar 19 2012 b.txt -rwxr-xr-x 1 user userg ... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

4. Shell Programming and Scripting

How to find all files for same month and year?

Hi All, I find all files for same month and year lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 c.txt -rwxr-xr-x 1 user userg 1596 Mar 21 2012 d.txt -rwxr-xr-x 1 user userg 1596 Mar 22 2012 f.txt -rwxr-xr-x 1... (8 Replies)
Discussion started by: Makarand Dodmis
8 Replies

5. UNIX for Advanced & Expert Users

Find all files other than first two files dates & last file date for month

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

6. Shell Programming and Scripting

how can i find the third friday of each month?

Help please! I need to read the calendar and put the date of the third Friday of each month into a variable for comparison in an "if" statement. How would I do this? Thnx, leslie02 (10 Replies)
Discussion started by: leslie02
10 Replies

7. UNIX for Advanced & Expert Users

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

8. Solaris

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

9. HP-UX

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

10. Shell Programming and Scripting

Find all files by month

Hi, I am trying to do achieving of files by months. find /test -name \*.* -mtime +30 will give me the result of all modified files after 30 days. But lets say i want to list all files that is modified in last months... what is the command to do it? Thanks! (13 Replies)
Discussion started by: maldini
13 Replies
Login or Register to Ask a Question