Visit Our UNIX and Linux User Community

Checking for file Sizes

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Checking for file Sizes
# 1  
Old 10-20-2011
Checking for file Sizes

Hi ,

I have some 10 files where i need to check the size of each and every file...if the size of the file is 0...I shud send out an email mentioning which file is actually of 0KB size..

Pls help
# 2  
Old 10-20-2011
# Save a list of empty files.
for FILE in *
        [ -s "$FILE" ] || echo "$FILE is 0KB"
done > /tmp/$$

# If the list isn't empty, mail it.
[ -s /tmp/$$ ] && sendmail username@host < /tmp/$$
rm -f /tmp/$$

I'm not sure I have the sendmail part right, I don't use it much at all.
# 3  
Old 10-20-2011
# Save a list of empty files???

Do i need to mention all the files...say

for file in *do
[ -s "$FILE" ] || echo "$FILE is 0KB"
done > /tmp/$$
# 4  
Old 10-20-2011
Originally Posted by saggiboy10
# Save a list of empty files???
Yes. I assumed you wanted to send several notices in one mail, instead of one notice in many mails.

So I loop through every file:

for FILE in *

...print the files that are empty...

[ -s "$FILE" ] || echo "$FILE is empty"

...and save the output of that entire loop into a file.

done > /tmp/$$

If that list isn't empty, it needs to be mailed to somebody.

[ -s /tmp/$$ ] && sendmail username@host </tmp/$$

Do i need to mention all the files...
No, it already works.

If you wanted to be more specific, you could do *.txt instead of just *.

If you wanted to mention them all by name, you could do

for FILE in file1.txt file2.txt file3.txt file4.txt instead.

You can't put do on the same line. My spacing and linebreaks are mostly necessary.

Sometiems people like to cram it all in like for X in * ; do something ; done but that's tough to read later.
# 5  
Old 10-20-2011
i have the file names with me which are static...
So i would be checking file sizes for those files and if any of the file is 0kb

I want an email to be sent...

am testing ur approach...Thanks for the quick response

---------- Post updated at 02:51 PM ---------- Previous update was at 02:40 PM ----------


for FILE in *
[ -s "$FILE" ] || echo "$FILE is 0KB"
done > /tmp/$$

How abt the email.....and how do i get to see the file which r directed to /tmp/$$
# 6  
Old 10-20-2011
Originally Posted by saggiboy10
How abt the email.....
Well, did you try the code I suggested for that? Did it or did it not work? If it didn't work, in what way did it not work?

and how do i get to see the file which r directed to /tmp/$$
cat /tmp/$$
# 7  
Old 10-20-2011
for FILE in file1.txt file2.txt
[ -s "$FILE" ] || echo "$FILE is 0KB"
done > /tmp/$$

Since am only interested in few files..I have actually enlisted them...

But now how do i send an email with those files which are 0kb..I mean the files which are in /tmp/&&

your code worked fine.....1st part is part is pending...

Last edited by saggiboy10; 10-20-2011 at 06:11 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #665
Difficulty: Easy
In 2000, Microsoft cofounder Bill Gates relinquished his role as CEO of Microsoft to Steve Baltimore.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing file sizes

Hello, I need to compare the size of a file to what it's size was 20min ago. So far my outline script is:ls -ls /home > filesizeafter.txt compare filesizeafter.txt filesizebefore.txt > filesizechange.txt if /home filesizechange.txt > 100 { email root; } ls -ls /home >... (2 Replies)
Discussion started by: chyurdan
2 Replies

2. UNIX Desktop Questions & Answers

Summing file sizes

I was just curious about how to sum the total file size of a certain type of file. For instance: $find . -name "*.aif" will print out the paths to each .aif file. Instead of printing, how could one sum the total space used by all of the aif files? Thanks! Please use code tags (3 Replies)
Discussion started by: Alexander4444
3 Replies

3. Shell Programming and Scripting

Add all file sizes in ls -l

solaris 10 (c shell) need a command or script that will add up all (*.tmp) file sizes in bytes of a single directory, or kbytes, no matter (1 Reply)
Discussion started by: ajp7701
1 Replies

4. Programming

Checking columns in SQL, comparing user input and sizes.

I'm writing a KSH shell script that's using SQL though DB2. If I have a table defined and populated db2 "create table tb(num int,letter char(4))" db2 "insert into tb values(111,a) db2 "insert into tb values(112,b) db2 "insert into tb values(111,c) How can I check if a letter user... (0 Replies)
Discussion started by: busdude
0 Replies

5. Shell Programming and Scripting

Help with file sizes

I have 2 big files in the size of gb. They are same with respect to content, both are , delimited. Now both of them are created by two different processes but has the same logic. The problem is they are differing only in few bytes for e.g one file is 202195751 bytes other is 202195773. So... (2 Replies)
Discussion started by: dsravan
2 Replies

6. UNIX for Dummies Questions & Answers

Checking file sizes in script

Hi, I'm trying to check a filesize within a script and then excute a relevant action. An example is below: if then rm $filename rm $filename2 elif then rm $filename2 fi Basically if $filename2 has a filesize of 0 then I want both files to be removed, but... (6 Replies)
Discussion started by: chris01010
6 Replies

7. UNIX for Dummies Questions & Answers

File sizes -- why do they change?

I just noticed that the copy of a file I made is smaller than the original, although I hardly made any changes to it. Can anyone tell me what determines the size of files? They're all .doc files (saved in NeoOffice). It's really frustrating, because I'm using them to respond to job ads and the... (1 Reply)
Discussion started by: Straitsfan
1 Replies

8. Shell Programming and Scripting

how to compare file sizes

hi ls -l * | sed 's/\+/ /g' | cut -f5 -d " " >out1 ls -l * | sed 's/\+/ /g' | cut -f5 -d " " >out2 diff out1 out2 i tried this it will work fine and i can see difference but i need a script which should neglect, if the difference b/w files is small and it should display... (5 Replies)
Discussion started by: revenna
5 Replies

9. Shell Programming and Scripting

Script for checking and reporting file sizes in a directory.

Hi, Need help for a Script for checking and reporting database file sizes in a directory. Request you to please give your valuable inputs. Thanks a lot in advance. Best Regards, Marconi (1 Reply)
Discussion started by: marconi
1 Replies

10. UNIX for Dummies Questions & Answers

Help on adding file sizes

Hi I need to take a list of files that are defined by an ls -ltr or grep for particular file names - and add up the byte size colum which is field 5 seperated by a space. I tried to do this but I think I am way off: for file in 'ls -ltr | grep 20070916 | nawk -F" " '{temp+=5} END {print... (1 Reply)
Discussion started by: llsmr777
1 Replies

Featured Tech Videos