Solved

Getting the size of a file

Posted on 2007-04-04
3
216 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sort command HPUX 11 65
sudo logging 5 81
Using Grep to Find a file 8 87
UNIX SCP 5 70
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

863 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

24 Experts available now in Live!

Get 1:1 Help Now