0

I'm a newbie and this is probably a very newbie question (be forewarned). When using terminal with zsh, entering ls -h does not output the expected result. Instead I receive an output as if I just entered ls without the -h. What could be the cause of this? Does ls -h not function the same in zsh mode?

Edit: My expected outcome of running ls -h would be a more readable/understandable version of ls -l, displaying file sizes as 1.3k etc.

3
  • Have you ascertained that changing the shell really does affect ls, or are you comparing the result of running the command on a Mac with that of a Linux-based system? Have you looked at man ls to see if the -h flag is defined to do what you expect? What do you expect (you forgot to include that)? Please edit your question... don't comment here Jul 5, 2020 at 15:48
  • Are you sure you don't want ls -lh? Jul 5, 2020 at 15:53
  • Can you please edit your question and include the output of type ls in an environment where ls -h does what you want? Jul 5, 2020 at 18:22

1 Answer 1

2

If you're just running ls -h, the -h has no effect. From man ls:

-h      When used with the -l option, use unit suffixes: Byte, Kilobyte,
        Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the
        number of digits to three or less using base 2 for sizes.
...
  -l    (The lowercase letter ``ell''.)  List in long format. (See below.)
...
The Long Format
   If the -l option is given, the following information is displayed for each
   file: file mode, number of links, owner name, group name, number of bytes
   in the file, abbreviated month, day-of-month file was last modified, hour
   file last modified, minute file last modified, and the pathname...

If you want the sizes, then you'll want ls -lh:

$ /bin/ls -lh .zshrc
-rw-r--r--  1 username  staff   4.6K May 18 18:54 .zshrc
4
  • So just to clarify why do I have to use ls -lh, instead of ls -h?. Thank you for your help.
    – zaddy
    Jul 5, 2020 at 17:53
  • 1
    @zaddy ls just lists the files in the directory with no additional information. -h stands for "human readable" and it's referring to file and directory sizes. So using -h without -l is pointless because you don't see sizes in the first place without -l. -l use a long listing format
    – Rayleigh
    Jul 5, 2020 at 18:01
  • 2
    @zaddy maybe in some other environment you had an alias ls="ls -l"? Otherwise, I don't know of an implementation of ls where -h does anything if -l (or similar) isn't provided. Jul 5, 2020 at 18:19
  • 1
    "When used with the -l option…" Jul 5, 2020 at 19:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .