{"id":12692,"date":"2024-03-14T16:24:54","date_gmt":"2024-03-14T16:24:54","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/"},"modified":"2025-08-05T05:27:54","modified_gmt":"2025-08-05T05:27:54","slug":"detailed-explanation-of-the-linux-sort-command","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/","title":{"rendered":"Linux Sort Command: Complete Guide"},"content":{"rendered":"<p>The sort command is a very commonly used command in the Linux system that is used to perform sorting operations on text files. There are many different options available for the sort command, here is an explanation of some commonly used options for the sort command.<\/p>\n<ol>\n<li>-b: Sort ignoring leading whitespace characters on each line.<\/li>\n<li>Sort the text in alphabetical order, ignoring non-alphanumeric characters.<\/li>\n<li>Ignoring character case, sort the data.<\/li>\n<li>-g: Sort in numerical order (e.g. 10 will come after 2, not before).<\/li>\n<li>-n: Sorting in numerical order.<\/li>\n<li>&#8211; r: Sort in reverse order (descending).<\/li>\n<li>&#8211; Separator: specifies the field separator used during sorting, defaulting to a tab.<\/li>\n<li>-k <starting position> [<ending position>]: Specify the range of fields to be sorted.<\/li>\n<li>-u: Remove duplicate lines.<\/li>\n<li>-o<output file>: save the sorted results to the specified file.<\/li>\n<\/ol>\n<p>The basic syntax for sorting using the sort command is as follows:<br \/>\nsort [options] [file name]<\/p>\n<p>For example, to sort a text file in dictionary order and output the result to another file, you can use the following command:<br \/>\nsort -d input.txt -o output.txt<\/p>\n<p>This will output the contents of input.txt sorted in dictionary order to output.txt.<\/p>\n<p>It is important to note that the sort command by default treats all text lines as sorting keys, so if you need to sort by specific fields, you can use the -k option to specify the range of fields. For example, to sort a tab-delimited text file in dictionary order by the second field, you can use the following command:<br \/>\nsort -t$\u2018\\t\u2019 -k2 input.txt -o output.txt<\/p>\n<p>The content in input.txt will be sorted in dictionary order based on the second field and then output to output.txt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The sort command is a very commonly used command in the Linux system that is used to perform sorting operations on text files. There are many different options available for the sort command, here is an explanation of some commonly used options for the sort command. -b: Sort ignoring leading whitespace characters on each line. [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[16678,16679,16676,16677,6762],"class_list":["post-12692","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-command-line-tutorial","tag-file-sorting-linux","tag-linux-sort-command","tag-linux-text-processing","tag-linux-utilities"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux Sort Command: Complete Guide - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Master the Linux sort command with practical examples. Learn key options for efficient text file sorting and data organization.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux Sort Command: Complete Guide\" \/>\n<meta property=\"og:description\" content=\"Master the Linux sort command with practical examples. Learn key options for efficient text file sorting and data organization.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-14T16:24:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-05T05:27:54+00:00\" \/>\n<meta name=\"author\" content=\"Sophia Anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sophia Anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/\"},\"author\":{\"name\":\"Sophia Anderson\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30\"},\"headline\":\"Linux Sort Command: Complete Guide\",\"datePublished\":\"2024-03-14T16:24:54+00:00\",\"dateModified\":\"2025-08-05T05:27:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/\"},\"wordCount\":286,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"Command line tutorial\",\"File sorting Linux\",\"Linux sort command\",\"Linux text processing\",\"Linux utilities\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/\",\"name\":\"Linux Sort Command: Complete Guide - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-14T16:24:54+00:00\",\"dateModified\":\"2025-08-05T05:27:54+00:00\",\"description\":\"Master the Linux sort command with practical examples. Learn key options for efficient text file sorting and data organization.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux Sort Command: Complete Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30\",\"name\":\"Sophia Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g\",\"caption\":\"Sophia Anderson\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/sophiaanderson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Linux Sort Command: Complete Guide - Blog - Silicon Cloud","description":"Master the Linux sort command with practical examples. Learn key options for efficient text file sorting and data organization.","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:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/","og_locale":"en_US","og_type":"article","og_title":"Linux Sort Command: Complete Guide","og_description":"Master the Linux sort command with practical examples. Learn key options for efficient text file sorting and data organization.","og_url":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-14T16:24:54+00:00","article_modified_time":"2025-08-05T05:27:54+00:00","author":"Sophia Anderson","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Sophia Anderson","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/"},"author":{"name":"Sophia Anderson","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30"},"headline":"Linux Sort Command: Complete Guide","datePublished":"2024-03-14T16:24:54+00:00","dateModified":"2025-08-05T05:27:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/"},"wordCount":286,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["Command line tutorial","File sorting Linux","Linux sort command","Linux text processing","Linux utilities"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/","url":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/","name":"Linux Sort Command: Complete Guide - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-14T16:24:54+00:00","dateModified":"2025-08-05T05:27:54+00:00","description":"Master the Linux sort command with practical examples. Learn key options for efficient text file sorting and data organization.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/detailed-explanation-of-the-linux-sort-command\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Linux Sort Command: Complete Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/19a24313de9c988db3d69226b4a40a30","name":"Sophia Anderson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c726c09aa40e37115fb5c62d0c3ed62c16ca255d3763e2e3ae83a70ddf8c2175?s=96&d=mm&r=g","caption":"Sophia Anderson"},"url":"https:\/\/www.silicloud.com\/blog\/author\/sophiaanderson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/12692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=12692"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/12692\/revisions"}],"predecessor-version":[{"id":156516,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/12692\/revisions\/156516"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=12692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=12692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=12692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}