Get size of a file using ls on all UNIX OSes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get size of a file using ls on all UNIX OSes
# 8  
Old 05-02-2013
Yes, wc -c is the best answer. It gives the exact correct answer.

As you suggest, do not worry about "overhead" at this point. As you can see from my previous post with the time test, wc runs very fast on large files. If there were really an "overhead" problem, if your script takes too long, you could worry about it then. Smilie
# 9  
Old 05-02-2013
Quote:
Originally Posted by SkySmart
with "wc -c", the file size will always be in the first column. that's perfect!
By the way if you want just the file size and forget about piping the output to another process:
Code:
wc -c < file

This User Gave Thanks to Yoda For This Post:
# 10  
Old 05-02-2013
No, "wc -c" causes too much I/O load, because it must read the whole file!
Better stick to the "ls -l"; you can set a consistent locale:
Code:
LC_ALL=C ls -l

most OS take the -o option
Code:
LC_ALL=C ls -lo

# 11  
Old 05-02-2013
Quote:
Originally Posted by MadeInGermany
No, "wc -c" causes too much I/O load, because it must read the whole file!
Better stick to the "ls -l"; you can set a consistent locale:
Code:
LC_ALL=C ls -l

most OS take the -o option
Code:
LC_ALL=C ls -lo

how can you measure the I/O load consumption of a process?
# 12  
Old 05-02-2013
Quote:
Originally Posted by SkySmart
how can you measure the I/O load consumption of a process?
Have a 10GB file on an NFS share, and run "wc -c" on it on a hundred NFS clients simultaneously.
This will take very long, and your NFS server will be overloaded the whole time.
And your server admin will be angry. (The redness of his face Smilie is proportional to the overhead that you have caused.)
# 13  
Old 05-02-2013
Quote:
how can you measure the I/O load consumption of a process?
There is I/O load and time load.

I/O load is normally the file size, unless the file is already cached into RAM.

Time load is measured with time command, using an uncached copy, such as:
Code:
$ time wc -c 2011.bb
4234978 2011.bb

real    0m0.009s
user    0m0.000s
sys     0m0.004s

Unless you are dealing with large files, much bigger than the test file above, or you run into a problem, I would not worry about such "overhead" concerns. It's called "premature optimization" to "fix" something by making it complicated, before there is a known problem. On the other hand, if your script is too slow, then time to try something that does not read the actual data on the disk. Smilie
# 14  
Old 05-02-2013
Sorry but I totally disagree with you, Hanson44. Using wc -c to retrieve the size of a file is absolutely the wrong approach to take.

A better approach is to use some very simple shell script logic to parse the the output of ls -l in order to figure out the file size column.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get the remote server file size in UNIX

Hi All, I am trying to sftp, get a file from remote server. Post this we need to check the remote server file size or checksum value of the remote server file and compare it with the file size in the current server. But I am facing issue to get the remote server file size. Could you please... (2 Replies)
Discussion started by: abhi_123
2 Replies

2. Shell Programming and Scripting

Unix file empty.. but size is greater than zero??/

Hi, I have a file by redirecting some contents in unix shell. Even when there is no content that is being redirected, the file size still shows greater than zero. but even if there is no matching pattern the file APPRES has size greater than 0bytes. awk -f AA.awk $logfile>APPRES... (3 Replies)
Discussion started by: justchill
3 Replies

3. UNIX for Advanced & Expert Users

how to find the file size in unix

Anybody can help HOW TO FIND THE FILE SIZE IN UNIX (5 Replies)
Discussion started by: lmraochodisetti
5 Replies

4. UNIX for Dummies Questions & Answers

what's the Linux|Unix OSes works on Servers

Hi everybody , I'm new here in the forum and new Dummy in L|U systems (Hope finding welcomes...:)). I just want to ask : What is the OS's that works on servers and the OS's that work as client OS?? I just know that Solaris Work on sarvers :D.. and i'm glad to be memmber in this... (1 Reply)
Discussion started by: derbi
1 Replies

5. UNIX for Dummies Questions & Answers

Maximum size of a file in unix

What's the maximum file size supported by unix. (3 Replies)
Discussion started by: nagalenoj
3 Replies

6. UNIX for Dummies Questions & Answers

file size different in unix and windows

I have a file on solaris/linux. ls -ls shows the logical size to be: 13292 However, when I transfer the file to my windows machine.. Rightclick->Properties shows the file size as: 13421 I wrote a small program on unix and windows that does a stat() on the file and reports the st_size... (6 Replies)
Discussion started by: the_learner
6 Replies

7. Filesystems, Disks and Memory

unix file size becomes zero

Hi, when can a unix library file size become zero? For example.: can mistyping this command -> /usr/ucb/ps -auxww|grep -i <process name> make the "ps" library file size to become zero or its contents to get deleted? Is there any other way that an inadvertant mistake could cause the file size to... (1 Reply)
Discussion started by: ananthmm
1 Replies

8. Shell Programming and Scripting

File size limitation of unix sort command.

hi , iam trying to sort millions of records which is delimited and i cant able to use sort command more than 60 million..if i try to do so i got an message stating that "File size limit exceeded",Is there any file size limit for using sort command.. How can i solve this problem. thanks ... (7 Replies)
Discussion started by: cskumar
7 Replies

9. HP-UX

Unix file size - HP-UX

Hi All, Currently we are using HP-UX machine.. We are facing problems with respect to file size. The file size does not seem to be exceeding 2 GB. Could you please let me know the following 1. Is there any difference between a 32 bit application and 64 bit application with respect to file... (2 Replies)
Discussion started by: krishna7
2 Replies

10. UNIX for Dummies Questions & Answers

Hp Unix file size problem

We have two files /var/adm/wtmp and /var/opt/OV/tmp/OpC/guiagtdf Could you please tell me if what these files are and if I can purge them as they are very big and Vi will not let me look at them, it gives me a message 'file to long'. Help any ideas Thanks :cool: (3 Replies)
Discussion started by: A Roberts
3 Replies
Login or Register to Ask a Question