The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Check file size and remove files srivsn Shell Programming and Scripting 5 05-28-2009 02:09 PM
Cp files (>5 Mb size) from one directory to another skcontact UNIX for Dummies Questions & Answers 6 06-12-2008 08:39 AM
listing files in a directory in bases of size arunkumar_mca UNIX for Dummies Questions & Answers 1 02-13-2008 07:38 AM
Find files size 0 within a directory astonmartin Shell Programming and Scripting 3 02-07-2008 04:49 PM
How to check directory size umen UNIX for Dummies Questions & Answers 4 08-30-2005 09:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-15-2005
oggle oggle is offline
Registered User
  
 

Join Date: Feb 2005
Location: Bedford, UK
Posts: 3
How to check if 3 files have same size in directory

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
  #2 (permalink)  
Old 02-15-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Code:

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"
  }
}'
  #3 (permalink)  
Old 02-16-2005
oggle oggle is offline
Registered User
  
 

Join Date: Feb 2005
Location: Bedford, UK
Posts: 3
How to check if any three files are the same size in a directory

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.
  #4 (permalink)  
Old 02-16-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Quote:

Say you have a directory of 1000 files - the question is do any three (or more) of these 1000 files have the same size.
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.



Quote:
Do the last three files created have the same size?
It is very easy to find the last three files created
Code:
ls -lt | awk '{ (if NR > 1 && NR < 5 ) print $0 }'

Hope it helps ....
  #5 (permalink)  
Old 02-16-2005
oggle oggle is offline
Registered User
  
 

Join Date: Feb 2005
Location: Bedford, UK
Posts: 3
My solution - last three created files same size?

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
  #6 (permalink)  
Old 02-16-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Is it not ls -lat instead of ls -al ?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0