Solved

Getting the size of a file

Posted on 2007-04-04
3
214 Views
Last Modified: 2013-12-27
I am trying to add a line to a report if a certain file is empty. I am trying to use a if statement to do this. Does anyone know the command for getting the file size? Here is what I have:

if
    /bin/find .  -size 0c | grep ${PWD}/raw.txt
then
    /bin/echo "There are no alerts in the audit logs today"  >> ${PWD}/report_${DBSIDS}_`date +%y%m%d`.txt
else
    /bin/sed G raw.txt >> ${PWD}/report_`date +%y%m%d`.txt
0
Comment
Question by:sikyala
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
nixfreak earned 500 total points
ID: 18852341
if [ ! -s  "${PWD}/raw.txt" ] ; then
    /bin/echo "There are no alerts in the audit logs today"  >> ${PWD}/report_${DBSIDS}_`date +%y%m%d`.txt
fi
else
    /bin/sed G raw.txt >> ${PWD}/report_`date +%y%m%d`.txt
0
 
LVL 7

Expert Comment

by:nixfreak
ID: 18852386
> Does anyone know the command for getting the file size?

$ du -h file
0
 

Author Comment

by:sikyala
ID: 18852689
it worked. Thanks!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
UNIX network port 5 46
Solaris OS patch 3 28
Sed question 2 46
what is the difference between "sudo su" and "su - root" 6 70
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now