Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash - how to list files with size in bytes

Tags:

bash

unix

I am wanting to use the ls command to output the files in a directory however I need the file size in bytes.

Is this possible with the ls command?

on similar questions i've found this ls -l --block-size=M which outputs the file size in megabytes however I cannot seem to get it to work with just bytes.

like image 991
Simon B Avatar asked Dec 14 '17 20:12

Simon B


2 Answers

If you are looking for statistics about files, then you want to use stat rather than ls. eg, with gnu stat:

stat --format=%n:%s *
like image 119
William Pursell Avatar answered Oct 17 '22 21:10

William Pursell


$ ls -l foo.tar.gz
-rw-r--r-- 1 james james 68964464 Mar 12  2014 foo.tar.gz

On my ls (GNU coreutils) 8.26 :

$ ls -s --block-size=1 foo.tar.gz
68972544 foo.tar.gz
like image 22
James Brown Avatar answered Oct 17 '22 21:10

James Brown