I need to determine if any three files have the same file size in a specified directly?
I have got as far as listing the file sizes but where to go from here?
ls -al |sort -n -r +4 | awq '{print $5}'
Thanks in anticipation
I need to determine if any three files have the same file size in a specified directly?
I have got as far as listing the file sizes but where to go from here?
ls -al |sort -n -r +4 | awq '{print $5}'
Thanks in anticipation
ls -ltr x1 x2 x3 |
awk 'BEGIN { sum=0 ; value=0}
{ sum+=$5 ; value=$5 } END { print sum ; print sum/3 ; if ( sum/3 == value )
{
print "Equal" ;
}else
{
print "Not Equal"
}
}'
If I am not mistaken this assumes you know the names of the three file to compare.
What I need is a script that assumes you do not know the names "x1" "x2" "x3" at the start.
Say you have a directory of 1000 files - the question is do any three (or more) of these 1000 files have the same size.
or another way to satisfy my needs would be a script:
Do the last three files created have the same size?
Thanks.
For the above ... pass aruguments to the script $1,$2,$3 ... and so on
You wil know how many number of arguments passed.
Then "x1 x2 x3" in the script will be replaced by $*
ls -ltr $*
Devide sum by $# ( no of files you are passing to the script)
the remaining script will be same.
It is very easy to find the last three files created
ls -lt | awk '{ (if NR > 1 && NR < 5 ) print $0 }'
Hope it helps ....
Thanks for this - final line is:
ls -l | tail -3 | awk 'BEGIN {sum=0 ; value=0} { sum+=$5 ; value=$5 } END { if ( sum/3 == value ) { print "equal" ; } else {print "not equal" } }'
on the assumption ls -l returns the files in created time sequence by default
Is it not ls -lat instead of ls -al ?