hi,
I need a shell script which gives list of files as below
- mtime is between 6 months and 12 months
- mtime is between 12 months and 24 months
- mtime is above 24 months
with only the below fields
-- field 1---------field 2--------------field 3---
-- size in bytes--last modified time--file name---
and the fields should be sorted based on size
Yoda
2
OK, so what have you tried so far?
i have tried something like this
find /dir -user <userid> -type f -mtime +180 -mtime -365 -exec ls -lgo {} \; > output.txt
sort -nr output.txt
cut -d' ' -f5- output.txt > final.txt
for files not modified more than 12 months but less than 24 months
and for more than 24 months, i changed the no.of days in mtime option.
is this efficient? or any other simple code is there?
also, if possible i would like to get the output in a excel file with the 3 required fields in 3 columns, exactly.
Yoda
4
Your find command looks good.
In order to create a CSV result you can pipe the find command o/p to below awk program:
find ... | awk ' {
$4 = $4 " " $5 " " $6;
match ($0, /\..*$/);
F = substr($0,RSTART,RLENGTH);
$NF = F;
print $1, $2, $3, $4, $NF;
} ' OFS=, > output.csv