Forrest logo
back to the ls tool

numfmt:tldr:5daf7

numfmt: Convert 5th field (1-indexed) to IEC Units without converting header.
$ ls -l | numfmt --header=${1} --field=${5} --to=${iec}
try on your machine

This command performs two different operations together using the pipe (|) operator.

  1. ls -l: The ls command is used to list files and directories. The -l option is used to display the long format listing, which includes detailed information such as permissions, owner and group, size, and timestamps.

  2. | (pipe): This operator is used to redirect the output of the previous command (ls -l) and pass it as input to the next command (numfmt).

  3. numfmt: It is a command for formatting numbers. In this context, it is used to format the file size displayed in the long listing format.

    • --header=${1}: This flag specifies the header to use for output.
    • --field=${5}: This flag specifies the field (column) number to format. In this case, it is the fifth field, which represents the file size.
    • --to=${iec}: This flag specifies the format to use for formatting. Here, ${iec} stands for International Electrotechnical Commission (IEC) format, which uses binary prefixes (e.g., KiB, MiB) to represent file sizes.

In summary, the command lists files and directories in the long format with ls -l, then the file size of each entry is extracted using numfmt, and finally, the file size is formatted using the IEC binary prefixes.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the ls tool