{"id":76983,"date":"2023-07-12T14:04:17","date_gmt":"2023-07-12T12:04:17","guid":{"rendered":"https:\/\/jotelulu.com\/en-gb\/blog\/"},"modified":"2025-12-12T15:16:31","modified_gmt":"2025-12-12T14:16:31","slug":"files-sorted-size-linux","status":"publish","type":"post","link":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/","title":{"rendered":"How to display files sorted by size using a GNU\/Linux script"},"content":{"rendered":"<p>Discover <strong>how to show files sorted by size in GNU\/Linux<\/strong> using a simple one-liner script you can reuse whenever needed.<\/p>\n<p>This command helps <strong>identify the largest files<\/strong> in a filesystem that&#8217;s running out of space, so you can <strong>purge or relocate<\/strong> unnecessary files to free up space and prevent disk full conditions that could crash your system.<\/p>\n<p>Since we&#8217;re in the <strong>GNU\/Linux world<\/strong>, we&#8217;ll use <strong>native commands available on any system<\/strong>\u2014no scripting languages like Python or Perl required.<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>How to show files sorted by size using GNU\/Linux commands<\/strong><\/h2>\n<p>The one-liner command is:<\/p>\n<pre><code># du -a | sort -n -r | less<\/code><\/pre>\n<p>This combines <strong><code>du<\/code> and <code>sort<\/code><\/strong> commands with pipes (pipelines) to process the output step by step.<\/p>\n<p><strong><code>du<\/code> (Disk Usage)<\/strong> is a standard UNIX\/Linux command for checking disk space usage. Its basic structure is:<\/p>\n<pre><code># du [options] [file\/system]<\/code><\/pre>\n<p><code>du<\/code> recursively scans the file structure, summing up space used by each file. The <strong><code>-a<\/code><\/strong> flag includes <strong>all files<\/strong>, not just directories.<\/p>\n<p><strong>NOTE:<\/strong> <em>For more on <code>du<\/code>, see the manual page: <a href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/du.1.html\" target=\"_blank\" rel=\"noopener\">du(1) &#8211; Linux manual page<\/a><\/em><\/p>\n<p>The <code>du -a<\/code> output pipes to <strong><code>sort -n -r<\/code><\/strong>:<\/p>\n<ul>\n<li><strong><code>-n<\/code><\/strong>: Sorts numerically by value<\/li>\n<li><strong><code>-r<\/code><\/strong>: Reverse order (largest first). Remove <code>-r<\/code> for smallest first.<\/li>\n<\/ul>\n<p><strong>NOTE:<\/strong> <em>For more on <code>sort<\/code>, see: <a href=\"https:\/\/man7.org\/linux\/man-pages\/man1\/sort.1.html\" target=\"_blank\" rel=\"noopener\">sort(1) &#8211; Linux manual page<\/a><\/em><\/p>\n<p>Finally, it pipes to <strong><code>less<\/code><\/strong> for paged viewing (use <code>more<\/code> if preferred):<\/p>\n<pre><code># du -a | sort -n -r | more<\/code><\/pre>\n<p>Or save to a file for later review:<\/p>\n<pre><code># du -a | sort -n -r &gt;&gt; filelist.txt<\/code><\/pre>\n<figure class=\"wp-caption\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19201\" src=\"https:\/\/jotelulu.com\/wp-content\/uploads\/2023\/07\/Paso-1.-Ejecucion-del-listado-ordenando-por-tamano-de-mayor-a-menor-1.jpg\" alt=\"Step 1. Executing file list sorted by size (largest first) using Linux script\" width=\"1935\" height=\"1035\" \/><figcaption>Step 1. Executing file list sorted by size (largest first)<\/figcaption><\/figure>\n<figure class=\"wp-caption\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19202\" src=\"https:\/\/jotelulu.com\/wp-content\/uploads\/2023\/07\/Paso-1.-Primera-ventana-de-la-salida-de-la-ejecucion-1.jpg\" alt=\"Step 1. First window of command output using Linux script\" width=\"1935\" height=\"1035\" \/><figcaption>Step 1. First window of command execution output<\/figcaption><\/figure>\n<h2 id=\"one-liner\"><strong>One-liner: Show files sorted by size in GNU\/Linux<\/strong><\/h2>\n<p>To list filesystem files sorted largest to smallest:<\/p>\n<pre><code># du -a | sort -n -r | less<\/code><\/pre>\n<p>That&#8217;s it\u2014your complete one-liner script.<\/p>\n<h2><strong>Conclusions<\/strong><\/h2>\n<p>As shown in this <strong>how to show files sorted by size in GNU\/Linux<\/strong> tutorial, a few well-chained commands provide critical disk usage insights to prevent filesystem full conditions. This is a quick troubleshooting workaround\u2014implement <strong>disk quotas<\/strong> and <strong>filesystem monitoring<\/strong> for production environments.<\/p>\n<p>The command works on all GNU\/Linux systems. If you encounter issues, contact us\u2014we&#8217;re happy to help.<\/p>\n<p>Find more Linux tutorials on the <a href=\"https:\/\/jotelulu.com\/en-gb\/blog\" target=\"_blank\" rel=\"noopener\">Jotelulu blog<\/a>.<\/p>\n<p><strong>Thanks for reading!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Discover how to show files sorted by size in GNU\/Linux using a simple one-liner script you can reuse whenever needed. This command helps identify the largest files in a filesystem that&#8217;s running out of space, so you can purge or relocate unnecessary files to free up space and prevent disk full conditions that could crash [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":76986,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[287],"tags":[],"class_list":["post-76983","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sysadmin-en-gb"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to display files sorted by size using a GNU\/Linux script - Jotelulu<\/title>\n<meta name=\"description\" content=\"Find largest files fast with this Linux one-liner: du -a | sort -n -r | less. Identify space hogs, free disk space, and prevent full filesystem crashes. Native GNU\/Linux commands.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to display files sorted by size using a GNU\/Linux script - Jotelulu\" \/>\n<meta property=\"og:description\" content=\"Find largest files fast with this Linux one-liner: du -a | sort -n -r | less. Identify space hogs, free disk space, and prevent full filesystem crashes. Native GNU\/Linux commands.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Jotelulu\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-12T12:04:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-12T14:16:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jotelulu.com\/wp-content\/uploads\/2025\/12\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1549\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Juan Ignacio Oller Aznar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Juan Ignacio Oller Aznar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/\"},\"author\":{\"name\":\"Juan Ignacio Oller Aznar\",\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/#\\\/schema\\\/person\\\/2ae97818cae086c48f108cd74234aca9\"},\"headline\":\"How to display files sorted by size using a GNU\\\/Linux script\",\"datePublished\":\"2023-07-12T12:04:17+00:00\",\"dateModified\":\"2025-12-12T14:16:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/\"},\"wordCount\":335,\"image\":{\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jotelulu.com\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg\",\"articleSection\":[\"Sysadmin\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/\",\"url\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/\",\"name\":\"How to display files sorted by size using a GNU\\\/Linux script - Jotelulu\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jotelulu.com\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg\",\"datePublished\":\"2023-07-12T12:04:17+00:00\",\"dateModified\":\"2025-12-12T14:16:31+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/#\\\/schema\\\/person\\\/2ae97818cae086c48f108cd74234aca9\"},\"description\":\"Find largest files fast with this Linux one-liner: du -a | sort -n -r | less. Identify space hogs, free disk space, and prevent full filesystem crashes. Native GNU\\\/Linux commands.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jotelulu.com\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg\",\"contentUrl\":\"https:\\\/\\\/jotelulu.com\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg\",\"width\":2560,\"height\":1549},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/blog\\\/files-sorted-size-linux\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to display files sorted by size using a GNU\\\/Linux script\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/#website\",\"url\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/\",\"name\":\"Jotelulu\",\"description\":\"Cloud Paradise for Tech Companies\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/#\\\/schema\\\/person\\\/2ae97818cae086c48f108cd74234aca9\",\"name\":\"Juan Ignacio Oller Aznar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/87efd80399b2c40a1d78dd5cee4e788d3f6c29d33e3b67bcfbc6abbf91d0fdcf?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/87efd80399b2c40a1d78dd5cee4e788d3f6c29d33e3b67bcfbc6abbf91d0fdcf?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/87efd80399b2c40a1d78dd5cee4e788d3f6c29d33e3b67bcfbc6abbf91d0fdcf?s=96&d=mm&r=g\",\"caption\":\"Juan Ignacio Oller Aznar\"},\"url\":\"https:\\\/\\\/jotelulu.com\\\/en-gb\\\/author\\\/juanignaciooller\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to display files sorted by size using a GNU\/Linux script - Jotelulu","description":"Find largest files fast with this Linux one-liner: du -a | sort -n -r | less. Identify space hogs, free disk space, and prevent full filesystem crashes. Native GNU\/Linux commands.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/","og_locale":"en_GB","og_type":"article","og_title":"How to display files sorted by size using a GNU\/Linux script - Jotelulu","og_description":"Find largest files fast with this Linux one-liner: du -a | sort -n -r | less. Identify space hogs, free disk space, and prevent full filesystem crashes. Native GNU\/Linux commands.","og_url":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/","og_site_name":"Jotelulu","article_published_time":"2023-07-12T12:04:17+00:00","article_modified_time":"2025-12-12T14:16:31+00:00","og_image":[{"width":2560,"height":1549,"url":"https:\/\/jotelulu.com\/wp-content\/uploads\/2025\/12\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg","type":"image\/jpeg"}],"author":"Juan Ignacio Oller Aznar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Juan Ignacio Oller Aznar","Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/#article","isPartOf":{"@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/"},"author":{"name":"Juan Ignacio Oller Aznar","@id":"https:\/\/jotelulu.com\/en-gb\/#\/schema\/person\/2ae97818cae086c48f108cd74234aca9"},"headline":"How to display files sorted by size using a GNU\/Linux script","datePublished":"2023-07-12T12:04:17+00:00","dateModified":"2025-12-12T14:16:31+00:00","mainEntityOfPage":{"@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/"},"wordCount":335,"image":{"@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/jotelulu.com\/wp-content\/uploads\/2025\/12\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg","articleSection":["Sysadmin"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/","url":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/","name":"How to display files sorted by size using a GNU\/Linux script - Jotelulu","isPartOf":{"@id":"https:\/\/jotelulu.com\/en-gb\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/#primaryimage"},"image":{"@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/jotelulu.com\/wp-content\/uploads\/2025\/12\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg","datePublished":"2023-07-12T12:04:17+00:00","dateModified":"2025-12-12T14:16:31+00:00","author":{"@id":"https:\/\/jotelulu.com\/en-gb\/#\/schema\/person\/2ae97818cae086c48f108cd74234aca9"},"description":"Find largest files fast with this Linux one-liner: du -a | sort -n -r | less. Identify space hogs, free disk space, and prevent full filesystem crashes. Native GNU\/Linux commands.","breadcrumb":{"@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/#primaryimage","url":"https:\/\/jotelulu.com\/wp-content\/uploads\/2025\/12\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg","contentUrl":"https:\/\/jotelulu.com\/wp-content\/uploads\/2025\/12\/SCRIPT-linux-ordenar-archivos-scaled-2.jpg","width":2560,"height":1549},{"@type":"BreadcrumbList","@id":"https:\/\/jotelulu.com\/en-gb\/blog\/files-sorted-size-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"https:\/\/jotelulu.com\/en-gb\/"},{"@type":"ListItem","position":2,"name":"How to display files sorted by size using a GNU\/Linux script"}]},{"@type":"WebSite","@id":"https:\/\/jotelulu.com\/en-gb\/#website","url":"https:\/\/jotelulu.com\/en-gb\/","name":"Jotelulu","description":"Cloud Paradise for Tech Companies","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jotelulu.com\/en-gb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/jotelulu.com\/en-gb\/#\/schema\/person\/2ae97818cae086c48f108cd74234aca9","name":"Juan Ignacio Oller Aznar","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/87efd80399b2c40a1d78dd5cee4e788d3f6c29d33e3b67bcfbc6abbf91d0fdcf?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/87efd80399b2c40a1d78dd5cee4e788d3f6c29d33e3b67bcfbc6abbf91d0fdcf?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/87efd80399b2c40a1d78dd5cee4e788d3f6c29d33e3b67bcfbc6abbf91d0fdcf?s=96&d=mm&r=g","caption":"Juan Ignacio Oller Aznar"},"url":"https:\/\/jotelulu.com\/en-gb\/author\/juanignaciooller\/"}]}},"_links":{"self":[{"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/posts\/76983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/comments?post=76983"}],"version-history":[{"count":2,"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/posts\/76983\/revisions"}],"predecessor-version":[{"id":77051,"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/posts\/76983\/revisions\/77051"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/media\/76986"}],"wp:attachment":[{"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/media?parent=76983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/categories?post=76983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jotelulu.com\/en-gb\/wp-json\/wp\/v2\/tags?post=76983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}