SORT command is the most commonly used command for sorting files in linux. It is a command line utility that can be used to sort files according to various criteria, like alphabetically, numerically and chronologically.

成都创新互联为您提适合企业的网站设计 让您的网站在搜索引擎具有高度排名,让您的网站具备超强的网络竞争力!结合企业自身,进行网站设计及把握,最后结合企业文化和具体宗旨等,才能创作出一份性化解决方案。从网站策划到成都网站设计、网站制作, 我们的网页设计师为您提供的解决方案。
Sort command provides many options/flags to sort files in different manners. It also accepts options to sort in reverse order, to ignore differences between folded and upper/lower cases and to discard empty lines.
Example 1:
Sort Alphabetically
The below example shows how to sort a file containing a list of words in alphabetic order.
$sort words.txt
apple
banana
cat
dog
Example 2:
Sort Numerically
The below example shows how to sort a file containing a list of numbers in a numerical order.
$sort -n numbers.txt
1
2
3
4
Example 3:
Sort in Reverse order
The below example shows how to sort a file containing a list of words in reverse alphabetical order.
$sort -r words.txt
dog
cat
banana
apple
Example 4:
Ignore Case differences
The below example shows how to sort a file containing a list of words ignoring their case differences.
$sort -f words.txt
apple
banana
Cat
dog
Example 5:
Discard empty lines
The below example shows how to sort a file containing a list of words and dropping empty lines in the output.
$sort -z words.txt
apple
banana
cat
dog
In conclusion, the sort command is a useful utility to arrange files in Linux according to various criteria. It provides many options which can be used to sort files with different conditions and produce expected result. With the help of these examples, you can easily understand more about sorting files using this command.
成都网站建设选创新互联(☎:028-86922220),专业从事成都网站制作设计,高端小程序APP定制开发,成都网络营销推广等一站式服务。
文章题目:深入了解Linux命令中的排序方法(linux命令排序)
地址分享:http://www.jxjierui.cn/article/dhhecje.html


咨询
建站咨询
