The Computer Oracle

How to force ls terminal command to show results in Bytes while I have set the default to ls -h in bash profile?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Civilization

--

Chapters
00:00 How To Force Ls Terminal Command To Show Results In Bytes While I Have Set The Default To Ls -H In B
00:45 Accepted Answer Score 23
01:17 Answer 2 Score 1
01:42 Answer 3 Score 0
01:54 Thank you

--

Full question
https://superuser.com/questions/1110491/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #macos #commandline #bash #terminal

#avk47



ACCEPTED ANSWER

Score 23


Is there another command I can use to get file size?

Use one of the following:

wc -c file

-c prints the byte count.

\ls -ln file

\ escapes the ls alias.

Linux:

stat --format="%s" file

OS X:

stat -f "%z bytes" file

See linux - Portable way to get file size (in bytes) in the shell - Stack Overflow for other alternatives.




ANSWER 2

Score 1


For people reaching this topic and willing to stick to ls tool, I would suggest:

\ls -lb

-n (in ls -ln) would be too numerical for my eyes, I'd rather keep user/group readable with -b.

Or more conveniently:

alias lsb='command ls --color -lb' # where "command ls" is a synonym of "\ls"




ANSWER 3

Score 0


Running "ls" through the full path will show you the file sizes in bytes:

/bin/ls -l

Verified on macOS 10.15 with Bash.