> For the complete documentation index, see [llms.txt](https://book.ice-wzl.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.ice-wzl.xyz/linux/sort.md).

# sort

### Show the sorted version of file

`sort test.txt`

### Show the sorted version of file in the reverse order

`sort -r test.txt`

### Show the sorted version of file according to 2nd column (n is used if column contains numerical values)

`sort -nk2 test.txt`

### Show the sorted version of file according to 3rd column (no numerical value in column 3)

`sort -k3 test.txt`

### Use sort command with a pipeline (without any file)

`ls -lah | sort -nk2`

### Sort the lines and remove duplicates (again this is just showing, not changing any content)

`sort -u test.txt`

### Sort the contents of 2 files and concetenate the output

`sort file1.txt file2.txt`

### Sort the contents of 2 files and concetenate the output, then remove the duplicates

`sort -u file1.txt file2.txt`

### `Credit`

[`https://github.com/areyou1or0/Bash-Fu/blob/master/sort`](https://github.com/areyou1or0/Bash-Fu/blob/master/sort)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.ice-wzl.xyz/linux/sort.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
