Tech Support > Operating Systems > Linux / Variants > FILE SIZE in bytes??
FILE SIZE in bytes??
Posted by AB PP on March 7th, 2004


How can you get the size of a file in bytes (not in KB or 512b)?

I tried 'du' but it only gives it in KB or 512b.

I know 'ls' gives it in bytes, and you could use 'grep' to get
that number. But how could you extract that file size for any
file on any directory when the length of the 'ls' info line is
not always the same on all directories?

Posted by Dances With Crows on March 7th, 2004


On Sun, 07 Mar 2004 15:18:24 -0500, AB PP staggered into the Black Sun
and said:
ls -l file.zip | awk '{printf "%s",$5}'
perl -e '@s=stat("file.zip"); print $s[7];'

TWMTOWDI, after all. HTH,

--
Matt G|There is no Darkness in Eternity/But only Light too dim for us to see
Brainbench MVP for Linux Admin / mail: TRAP + SPAN don't belong
http://www.brainbench.com / Hire me!
-----------------------------/ http://crow202.dyndns.org/~mhgraham/resume

Posted by Chris F.A. Johnson on March 7th, 2004


On Sun, 07 Mar 2004 at 20:18 GMT, AB PP wrote:
Please do not multi-post.

Your question has been answered in comp.unix.shell (not to mention
that it has been answered many, many times before, and a search of
the archives would have found the answer).

--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
================================================== =================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License

Posted by AB PP on March 7th, 2004


THANKS!


On 3/7/04 3:28 PM, in article
slrnc4n1n0.fki.danSPANceswitTRAPhcro...202.dyndns.org, "Dances
With Crows" <danSPANceswitTRAPhcrows@usa.net> wrote:


Posted by Garry Knight on March 7th, 2004


In message
<slrnc4n1n0.fki.danSPANceswitTRAPhcrows@samantha.c row202.dyndns.org>,
Dances With Crows wrote:

Too many characters!

ruby -e 'puts File.size("file.zip")'

--
Garry Knight
garryknight@gmx.net ICQ 126351135
Linux registered user 182025

Posted by AB PP on March 7th, 2004


Hey, that one is good too. I didn't know about the 'ruby' language.

I will read on it.

Thanks.




On 3/7/04 4:01 PM, in article 1078693314.22071.0@demeter.uk.clara.net,
"Garry Knight" <garryknight@gmx.net> wrote:


Posted by Ken Bloom on March 7th, 2004


On Sun, 07 Mar 2004 15:18:24 -0500, AB PP wrote:

Just "du -b" or "wc -c"
("wc" is the wordcount command -c asks how many characters (bytes) are in
the file)

--
I usually have a GPG digital signature included as an attachment.
See http://www.gnupg.org/ for info about these digital signatures.
My key was last signed 10/14/2003. If you use GPG *please* see me about
signing the key. ***** My computer can't give you viruses by email. ***


Posted by Alan Connor on March 7th, 2004


On Sun, 07 Mar 2004 16:08:11 -0500, AB PP <abpp@mail.com> wrote:
[please don't top post]


Here's yet another, while we are having fun:

ls -l file | sed 's/ */:/g' | cut -d: -f5



AC

--
ed(1) Check out the original tutorials by Brian W.
Kernighan at the Ed Home Page http://tinyurl.com/2aa6g

Posted by Alan Connor on March 7th, 2004


On Sun, 07 Mar 2004 14:11:57 -0800, Ken Bloom <kabloom@ucdavis.edu> wrote:
du -b won't do it, Ken.

------------------------------------------
Sun Mar 7 02:35pm AC 0
~
$ ls -l junkfile | sed 's/ */:/g' | cut -d: -f5
1836
------------------------------------------
Sun Mar 7 02:36pm AC 0
~
$ du -b junkfile
2048 junkfile
------------------------------------------
Sun Mar 7 02:36pm AC 0
~
$ wc -c junkfile
1836 junkfile

Disk usage and file size are not the same thing.


AC

--
ed(1) Check out the original tutorials by Brian W.
Kernighan at the Ed Home Page http://tinyurl.com/2aa6g

Posted by John W. Krahn on March 7th, 2004


Garry Knight wrote:
Yes, definitely!

perl -le'print -s pop' file.zip


John
--
use Perl;
program
fulfillment

Posted by Chris F.A. Johnson on March 7th, 2004


On Sun, 07 Mar 2004 at 23:02 GMT, John W. Krahn wrote:
Much too long-winded; try:

stat -c%s file

--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
================================================== =================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License