Sunday, February 27, 2022

[SOLVED] Bash - how to list files with size in bytes

Issue

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.


Solution

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 *


Answered By - William Pursell
Answer Checked By - Cary Denson (WPSolving Admin)