Listing files that belong to a certain year date?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing files that belong to a certain year date?
# 1  
Old 10-13-2011
Listing files that belong to a certain year date?

I'm trying to list files, first by size and I'm using something like this
Code:
ls -l|awk '{print $5,$6,$7,$8,$9|"sort -nr"}'|more


Now I'd like to just do the same listing but only for files with the year 2009 in the $8 field or even anything less than 2011.

Last edited by Franklin52; 10-14-2011 at 03:32 AM.. Reason: Please use code tags, thank you
# 2  
Old 10-13-2011
See if this does it for you:
Code:
ls -l|awk '{print $5,$6,$7,$8,$9|"sort -nr"}' | egrep ' 2010 ' | more

# 3  
Old 10-13-2011
That worked thanks and if I wanted to remove all those files, then I could try this? I know the rm command is potentially dangerous so I would like to know before I run it
Code:
ls -l|awk '{print $5,$6,$7,$8,$9|"sort -nr"}' | egrep ' 2010 ' | rm -f

Oh and in a related question how about the files that are only 0 bytes which is represented in $5 and then just remove those?

edit:
I tried this and it seem to work for zero bytes from my results
Code:
ls -l|awk '{print $5,$6,$7,$8,$9|"sort -nr""}' | egrep '^0' | more

My only question left for above results is can I just add | rm -f to remove the files. I dont want to wipe the whole directory by accident.

Last edited by Franklin52; 10-14-2011 at 03:32 AM.. Reason: Please use code tags, thank you
# 4  
Old 10-13-2011
use find command.

Check first: (I just guess the date, you need adjust it with your request)
Code:
find . -type f -mtime +700 -mtime -1000 -ls

Then do the clean:

Code:
find . -type f -mtime +700 -mtime -1000 -exec rm -f {} \

# 5  
Old 10-14-2011
I tried this for files equal to 0

Code:
find . -type f -size 0 -exec rm -f {} \

and all I get is this:

Code:
>

# 6  
Old 10-15-2011
find . -type f -printf "%AY %p\n" | grep "^2010"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

2. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 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 list files that are not first two files date & last file date for every month-year?

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... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

5. Shell Programming and Scripting

Script to check if list of files belong to particular group

i just need help to write a shell script which when run should take the text doc(contains list of files which are to be copied) as input and then each file has to be checked to see if they belong to any of the 5 groupnames that we are going to mention in the other list document, id they belong to... (1 Reply)
Discussion started by: draghun9
1 Replies

6. Shell Programming and Scripting

Urgent...Need a shell script to list files which belong to particular groups

Hi, I am just new to scripting but got to write a complex scipt please help. i need a shell script which can check the list of data listed in a txt doc and see if they belong to any of the groups that are listed in other list file.... (5 Replies)
Discussion started by: draghun9
5 Replies

7. UNIX for Dummies Questions & Answers

listing year in ls command

Hi all .. As per rule i searched the forum i am not able found out ... I want to display the year in when listing the files .. when i use ls -lt it is not displaying files with recent 6 month old .. I know that perderabo has written a script for that if you give that link it will be... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

8. UNIX for Dummies Questions & Answers

listing files that does not belong to current date

How do we list all the file names in a directory that does not belong to current date. (3 Replies)
Discussion started by: esh.mohan
3 Replies

9. Shell Programming and Scripting

listing files that do not belong to current date

How do we list all the file names in a directory that does not belong to current date. (1 Reply)
Discussion started by: esh.mohan
1 Replies

10. UNIX for Dummies Questions & Answers

long listing of files up to a given date

Hi I would like to a long list of files up to a given date. I've tried: ls -al > filelist but this command gives me all the files. I've also have tried the find command: find . -mtime -10 -type f -print > filelist This gives me information on active file within the past 10 days and... (2 Replies)
Discussion started by: rlh
2 Replies
Login or Register to Ask a Question