Instead of parsing ls
, use find
:
find . -type f -printf "%s\t%f\n"
The %f
directive prints the filename with leading directories removed. %s
produces the file size in bytes.
For restricting the listing to the current directory, use -maxdepth
:
find . -maxdepth 1 -type f -printf "%s\t%f\n"
You could also use stat
:
stat --printf "%s\t%n\n" *