In Linux, the “ls” command is utilized to view file size and details by obtaining information regarding the files/directories in a directory. It determines the size of the files, their permissions, and hidden files/directories. In short, “ls” is the best choice to get detailed information about files/directories in Linux.
This article will illustrate the “ls” command along with possible examples to view file size in detail in Linux.
- How to View File Size/Details from ls Command in Linux?
How to View File Size/Details from ls Command in Linux?
The “ls” command has various applications, including disk usage analysis, file organization, file permissions, debugging, and many more. The extensive usage of the “ls” command can be seen using the command:
$ ls --help
To view the file sizes with detailed information, different examples of the “ls” command are mentioned below:
Example 1: Using ls -l Command
The “ls -l” command shows the files/directories in a long format. It shows information such as the file size, permissions, owner, and modification time:
$ ls -l
The output shows the sizes of the home directory file and directories in the “KB” format.
Example 2: Using ls -lh Command
The “ls -lh” command is similar to the “ls -l” command, but it displays the file sizes in human-readable format (e.g. KB, MB, GB, etc.):
$ ls -lh
The above figure shows the list of files and directories in a human-readable format.
Example 3: Using ls -s Command
The “ls” command with the “s” option displays the file size in blocks, rather than in bytes:
$ ls -s
The output visualizes file sizes in block representation.
Example 4: Using ls -sh Command
The “ls -sh” command is similar to the “ls -s” option, but it displays the file sizes in a human-readable format:
$ ls -sh
In this way, view the file size in a human-readable format.
Example 5: Using ls -lS Command
The “ls -lS” command sorts the files and directories by size, in descending order, with the largest files appearing first:
$ ls -lS
The above display sorts the file sizes in descending order.
Example 6: Using ls -lhS Command
The “ls -lhS” command is similar to the “ls -lS” command, but it displays the file sizes in a human-readable format:
$ ls -lhS
The output visualizes the file size in a descending and human-readable format.
Linux offers the “ls” command with “l”, “s”, and “h” options to view the file size along with detail in “long”, “sorting”, and “human-readable” format. Additionally, these options visualize the file size, permissions, owner, and modification time of files as well as directories in the terminal. This article has illustrated the different methods to view the file size/detail from the “ls” command in Linux.