Hi,
i have some files in one directory(say some sample dir) whose names will be like the following.
some_file1.txt
some_file2.txt.
i need to get the last modified file size based on file name pattern like some_
here i am able to get the value of the last modified file size using the following command:
echo `ls -lt /sample/some_* |awk '{print $5}'` | `awk '{ F = " " ; print $1 }'
but the problem is, i need to store this value in one variable, and needs to print that variable value.
i tried several ways like the following.
SIZE=`echo `ls -lt /sample/some_* |awk '{print $5}'` | `awk '{ F = " " ; print $1 }'`
echo $SIZE
but it is not successful.
Your immediate help will be greatly appreciated
Reagrds,
Eswar
Looking for this
filename=`ls -lt /sample/some_* |awk '{print $5}' | awk '{ F = " " ; print $1 }'`
echo $filename
You may try Perl, to avoid the pipeline:
size=$(perl -e'
print -s (sort {-M $a <=> -M $b } glob "some_*")[0]
')
Thanks matrixmadhan for your immediate respone.
but i am getting the file size as
2580 111
i.e, both of the file sizes seperated by space.
Note: I have 2 files with name some_ under sample dir, whose file sizes are 2580 and 111.
i need only the last updated file size only.
i.e like 2580 (or) 111
Thanks,
eswar
Thanks matrixmadhan for your immediate respone.
but i am getting the file size as
2580 111
i.e, both of the file sizes seperated by space.
Note: I have 2 files with name some_ under sample dir, whose file sizes are 2580 and 111.
i need only the last updated file size only.
i.e like 2580 (or) 111
Thanks,
eswar
SIZE=`ls -lrt | awk 'END{ print $5 }'`
echo $SIZE
ls -lrt => display files with file that is last modified at the end
awk 'END{ print $5 }' => list only the file size of the last displayed file
SIZE => will contain the size of the file that is modified latest