Filename/Filesize in bytes? ls -l too much info

Hi

As PHP’s file_size doesn’t work on directories without write permissions (yes… very odd) I was looking for a workaround using exec/parsing the results.
So I basically want just a list of filenames/size in bytes for easy parsing.

ls -l
Does what I want aside from the useless additional information in there.
ls -1 -A -s -h
Gives the size in KB/MB etc, bit difficult to parse
ls -1 -A -s
Gives size in blocks, but need root permissions to figure out the blocksize?
filesize [FILENAME]
Works great, but only one file a time? Probably going to be rather slow with a lot of files in one directory. Tried **filesize *** and **filesize *** but both give back the result of just one file.

stat -c %s file

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Why not just use du? By default I think it gives you kilobytes but ‘-b’
will have it return bytes.

du -b /path/to/your/file

Good luck.

Axeia wrote:
> Hi
>
> As PHP’s file_size doesn’t work on directories without write
> permissions (yes… very odd) I was looking for a workaround using
> exec/parsing the results.
> So I basically want just a list of filenames/size in bytes for easy
> parsing.
>
> ls -l
> Does what I want aside from the useless additional information in
> there.
> ls -1 -A -s -h
> Gives the size in KB/MB etc, bit difficult to parse
> ls -1 -A -s
> Gives size in blocks, but need root permissions to figure out the
> blocksize?
> filesize [FILENAME]
> Works great, but only one file a time? Probably going to be rather slow
> with a lot of files in one directory. Tried *filesize ** and *filesize
> ** but both give back the result of just one file.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJJ+JvQAAoJEF+XTK08PnB5qwQP/2WEiwYGT+W1nypJ0hjBcE8P
xk/YNMmkQscuTqnietyYfjeDTcP8pSrbZmChzQX9NKtx2ih4YtUPd20aWF1WSQ7E
iWCNXLZepuwen6nl6CZydxqhgzbNpCuJ1MnwikJR8ZRRIaD7T7n82aaFyliGSwVI
jouBeYdpiRn1xpr/Ot8Nt/z9n1a9xJA/os5TN7xidUGRmcs16Ws8GhrSDwwaB605
qZ5M1xiNFVKg2dtaFWbUG8Y7WF4eivxHjeA9w2v4UpGAmRrs+0v1kOUbbbIX5c9C
7Khv+7I8Cw/IqGFeIHyndjsHjpiNtSbBBpTg9qK4pcVHc1/9O4fnQxNxB8/vg2dG
MTGO/tLqwX2CVIDjeg8XOAQgJEiDWefnigrLMbDb86Mmg++jz/+7zDcchGJI7AyB
j0Rsoo6PcdJW7Zs0qYqIewrztlc7MCDkdZe/luUMa0ZtUAmtfhRr3pTZlsMlUEDX
cpwyCX3GeSc3qSWMdOhmO/Afq/nvt34NYb9Q5+MyirAeRc5v9CHI9YWvi4tSzwXt
XVHR98GtLIwoojyvgIhw5XxRZclqmjkqH7Zet2PO9rsPpVt2YaWBilVw5i9cLdAq
7gdWvOqboSnSUzOzMdqEqtDKe0R5G3l9bVde1NwYMjvAee1n3a3VWQ5khbVi7+ZK
498he5tBkU1pH+yIdGT2
=0FYo
-----END PGP SIGNATURE-----

Ah thanks both of you,
du -b works perfectly :slight_smile: (well aside from hidden files… but mweh, don’t care much about those)

A little trick that might help, or not :-), in the future when you are looking for the “right” command:

Do a:

man -k regexp | sort | less

The short descriptions and manual page names are searched.

Then do a man on the command(s), that look like they might work, and a find for your string. It helps to know basic keys for less, like: / p, n.

Additionally:
man 7 regex - regular expressions
man 7 glob - shell file globbing

Just a small tidbit that hopefully helps make life a little easier.

On Wed, 2009-04-29 at 18:16 +0000, Axeia wrote:
> Hi
>
> As PHP’s file_size doesn’t work on directories without write
> permissions (yes… very odd) I was looking for a workaround using
> exec/parsing the results.
> So I basically want just a list of filenames/size in bytes for easy
> parsing.
>
> ls -l
> Does what I want aside from the useless additional information in
> there.

How about:

du -b *

This is really useful. I never noticed “man -k” before :slight_smile: