Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple file sizes script 1

Status
Not open for further replies.

longhair

MIS
Feb 7, 2001
889
US
afternoon all,
working on what i thought would be a simple script (well probably is for most of you). anyway, what i need to do is write the date to the file if it's 0 bytes do nothing if it's greater.
thougth the following would do it:
Code:
if [ `wc -c </path/to/file/temp.txt` ! -gt 1]; then
 cat date > /files/dsch820.txt
fi
also tried using eq = 0 rather than ! -gt 1
any ideas?
regards,
longhair
 
feherke,
thanks much!!
looks to work, will try it in a few scenarios to verify.
have a start
regards,
longhair
 
A simpler way:
[ -s /path/to/file/temp.txt ] || date > /path/to/file/temp.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

Please note that I used [tt]wc[/tt] just because you used it. But that will work slow on big and/or many files. You can use only the shell ( [tt]bash[/tt] and [tt]ksh[/tt] ) to do that :
Code:
[ -f /path/to/file/temp.txt -a ! -s /path/to/file/temp.txt ] && date > /files/dsch820.txt

Feherke.
 
will keep the info in mind.
currently only looking at 2 files - don't think they are ever bigger than 30k.
regards,
longhair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top