In the output, instead of bytes size of something like 1984 or 1924, the file size is now listed as 1.9K. In this command, we generate the listing of the files and directory, sorting on their file size in ascending order, and then converting the bytes to more human-readable formats like kilobytes. Now the files are sorted on their size in ascending order but in the human-readable format. Let’s try listing files, sorting them in ascending order ( -Sr), and also use the -h parameter. It’s easier for humans to understand file size in megabytes or gigabytes rather than in long numeric format, such as 10472649. Rather than listing the files based on their byte size, we can also use the -h parameter to make the file size more human-readable. ls -lr -sort=size Sort Files by Size in a Human Readable Format We’ll just add -r and files will be listed in reverse order. This time the output is generated in ascending order.Īs before, we can also use the -sort parameter. We can do this by adding -r as a parameter with the -S parameter, which will basically just list the files in the reverse descending order, which is ascending. What if we need to sort the files by their size in ascending order – meaning the reverse than we did above. To do this, we need to execute the following command: ls -l -sort=size Sort Files in Ascending Order (the -Sr parameter) ls -lSĪlternatively, you can get the same result by replacing -S with the -sort parameter, and you will get the same output. To make ls sort files by size, we can use the -S parameter, which sorts the files in descending order by default. Sort Files in Descending Order (the -S parameter) By default, the ls command sorts files alphabetically. The -l parameter provides several details. We can also use the -l parameter to generate the long listing of files and directories: ls -l When we execute this command, the files in the current directory are listed. The ls command stands for listing and can be used without any parameter: ls To list files in Linux we commonly use the ls command. Preferably acting as a non-root sudo user to ensure a secure environment.Sort Files by Size in a Human Readable Format.Sort Files in Ascending Order (the -Sr parameter).Sort Files in Descending Order (the -S parameter).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |