How to check if 3 files have same size in directory


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check if 3 files have same size in directory
# 1  
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  
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  
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  
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  
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  
Is it not ls -lat instead of ls -al ?
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #337
Difficulty: Easy
:set number in vi will add line numbers to the file and automatically save to disk.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check total files size in hdfs directory?

Is there a way to calculate the total file size of HDFS file directory in GB or MB? I dont want to use du/df command. Without that is there a way HDFS Directory - /test/my_dir (1 Reply)
Discussion started by: rohit_shinez
1 Replies

2. Homework & Coursework Questions

Sorting files by size in another directory

1. The problem statement, all variables and given/known data: I'm trying to use a directory path to enter a new directory and sort the files there. I'm using the language C with a system call in Unix to sort the files from smallest to largest. 2. Relevant commands, code, scripts, algorithms:... (1 Reply)
Discussion started by: TedFTW
1 Replies

3. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

4. UNIX for Dummies Questions & Answers

How to get the set of files size as a sum in a directory.

Hi, Can someone help me to get the complete files size (sum) over a perod time (1 day,2days)in a directory. eg: Directory :ABC I have a1,a2,a3 files are created in last 24 hours so I need to get the some of all these files. I am using the below find command but its giving me the... (1 Reply)
Discussion started by: gaddamja
1 Replies

5. Shell Programming and Scripting

Check file size and remove files

Hi, Here we have a situation where we have to check the file size and if the file size is greater than 0 bytes then remove the files from the directory. 1)EdwTrxn 2)EdwPost 3)EdwTndr 4)EdwSls 5)EdwSlsRej 6)EdwTndrRej Files will be created in the directory in the following manner. ... (5 Replies)
Discussion started by: srivsn
5 Replies

6. UNIX for Dummies Questions & Answers

Check the size of files

Hi, I need to put a script working to see in a directory with logs if exists file or files with size more than 12Mb. If exists it shoul send mail. Can anyone help me? thanks (3 Replies)
Discussion started by: osramos
3 Replies

7. UNIX for Dummies Questions & Answers

Cp files (>5 Mb size) from one directory to another

Hi All, I have a requirement like below, I want to transfer few file of size > 5 Mb from one directory to anotehr directory. Please let me know the command how can i do that Sorry if it looks silly Senthil (6 Replies)
Discussion started by: skcontact
6 Replies

8. UNIX for Dummies Questions & Answers

listing files in a directory in bases of size

Hi , I want to list all files in the order of size . Just want to know which files occupies more size and which occupies less size . Is it possible with ls command ? :) Thanks, Arun. (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

9. Shell Programming and Scripting

files of size 0 need to be deleted inside a directory

Hiiii, I have written a script which takes backup of some log files. let say the backuplocation is --- /abc/backuplocation -rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt23994.log -rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3601.log -rw-r--r-- 1... (2 Replies)
Discussion started by: namishtiwari
2 Replies

10. UNIX for Dummies Questions & Answers

How to check directory size

how say I have directory how can I get the directory size in mega and if it less then 1 mega so byts Thanks (4 Replies)
Discussion started by: umen
4 Replies

Featured Tech Videos