{"id":1704,"date":"2021-06-26T09:25:56","date_gmt":"2021-06-26T03:55:56","guid":{"rendered":"https:\/\/jaipurhosting.com\/blog\/?p=1704"},"modified":"2021-06-26T09:28:39","modified_gmt":"2021-06-26T03:58:39","slug":"how-to-list-all-files-ordered-by-size-in-linux","status":"publish","type":"post","link":"https:\/\/www.jaipurhosting.com\/blog\/how-to-list-all-files-ordered-by-size-in-linux\/","title":{"rendered":"How to list all files ordered by size in Linux"},"content":{"rendered":"\n<p><strong>Description<\/strong><\/p>\n\n\n\n<p>The <strong>ls<\/strong> command is one of the basic commands that any Linux user should know.<\/p>\n\n\n\n<p>It is used to list information about files and directories within the file system.<\/p>\n\n\n\n<p>The <strong>ls<\/strong> utility is a part of the GNU core utilities package which is installed on all Linux distributions.<\/p>\n\n\n\n<p>In this article, we can see a number of useful <strong>ls <\/strong>command options to list all of the files in a certain directory and sort them by file size in Linux.<\/p>\n\n\n\n<p>To list all files in a directory, open a terminal window and run the following command. <\/p>\n\n\n\n<p>Note that when <strong>ls<\/strong> invoked without any arguments, it will list the files in the current working directory.<\/p>\n\n\n\n<p><strong>ls -la<\/strong><\/p>\n\n\n\n<p>In the following command the <strong>-l<\/strong> flag means long listing and <strong>-a<\/strong> tells ls to list all files including (.) or hidden files. <\/p>\n\n\n\n<p>To avoid showing the . and .. files, use the <strong>-A<\/strong> option instead of <strong>-a<\/strong>.<\/p>\n\n\n\n<p><code>ls -la<\/code><\/p>\n\n\n\n<p>OR<\/p>\n\n\n\n<p><code>ls -la \/var\/www\/html\/<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"908\" height=\"184\" src=\"http:\/\/jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/1.png\" alt=\"\" class=\"wp-image-1706\" srcset=\"https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/1.png 908w, https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/1-768x156.png 768w\" sizes=\"auto, (max-width: 908px) 100vw, 908px\" \/><\/figure>\n\n\n\n<p><strong>ls -laS<\/strong><\/p>\n\n\n\n<p>To list all files and sort them by size, use the <strong>-S<\/strong> option. <\/p>\n\n\n\n<p>By default, it displays output in descending order (biggest to smallest in size).<\/p>\n\n\n\n<p><code>ls -laS \/var\/www\/html\/<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"908\" height=\"185\" src=\"https:\/\/jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/2.png\" alt=\"\" class=\"wp-image-1707\" srcset=\"https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/2.png 908w, https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/2-768x156.png 768w\" sizes=\"auto, (max-width: 908px) 100vw, 908px\" \/><\/figure>\n\n\n\n<p><strong>ls -laSh<\/strong><\/p>\n\n\n\n<p>You can output the file sizes in human-readable format by adding the -h option as shown.<\/p>\n\n\n\n<p><code>ls -laSh \/var\/www\/html\/<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"184\" src=\"https:\/\/jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/3.png\" alt=\"\" class=\"wp-image-1708\" srcset=\"https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/3.png 907w, https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/3-768x156.png 768w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/figure>\n\n\n\n<p><strong>ls -laShr<\/strong><\/p>\n\n\n\n<p>And to sort in reverse order, add the -r flag as follows.<\/p>\n\n\n\n<p><code>ls -laShr \/var\/www\/html\/<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"183\" src=\"https:\/\/jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/4.png\" alt=\"\" class=\"wp-image-1709\" srcset=\"https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/4.png 907w, https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/4-768x155.png 768w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/figure>\n\n\n\n<p><strong>ls -laShR<\/strong><\/p>\n\n\n\n<p>Besides, you can list subdirectories recursively using the -R option.<\/p>\n\n\n\n<p><code>ls -laShR \/var\/www\/html\/<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"908\" height=\"290\" src=\"https:\/\/jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/5.png\" alt=\"\" class=\"wp-image-1710\" srcset=\"https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/5.png 908w, https:\/\/www.jaipurhosting.com\/blog\/wp-content\/uploads\/2021\/06\/5-768x245.png 768w\" sizes=\"auto, (max-width: 908px) 100vw, 908px\" \/><\/figure>\n\n\n\n<p>We hope you\u2019ve found this useful!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description The ls command is one of the basic commands that any Linux user should know. It is used to list information about files and directories within the file system. The ls utility is a part of the GNU core utilities package which is installed on all Linux distributions. In this article, we can see [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1711,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1704","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1704"}],"version-history":[{"count":2,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1704\/revisions"}],"predecessor-version":[{"id":1712,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1704\/revisions\/1712"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media\/1711"}],"wp:attachment":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}