wc vs ls (file size calculation)?
I had received a complaint recently that 'wc' is not returning a correct byte count for large files (in 10s of GB). Does 'wc' have any such limitation? If yes, would 'ls' be a better option to fetch file size.
I am planning on replacing wc with ls for calculating file sizes in the existing code. Please let me know if you see any issues with this change.
One interesting thing I noted while trying to simulate the problem was, 'wc' takes way longer time than 'ls'. Can anyone provide a reasoning for this? (See the code and its result below)
Thanks!
Sreenivas
============== Script ========================
timestamp=`date`
echo $timestamp
lscount=`ls -l two.dat|awk '{print $5}'`
echo $lscount
timestamp=`date`
echo $timestamp
wccount=`wc -c two.dat|awk '{print $1}'`
echo $wccount
timestamp=`date`
echo $timestamp
=============== Result =========================
Mon Apr 24 05:18:29 PDT 2006
2303923104
Mon Apr 24 05:18:29 PDT 2006
2303923104
Mon Apr 24 05:33:16 PDT 2006
========================================
Last edited by Sreenivasa; 04-24-2006 at 10:13 AM..