What is the UNIX sort command?

The sort command is used to sort a complete file by arranging the records in a specific order. By default, the sort command sorts files assuming that the contents are ASCII characters. The file is sorted line by line​, and the blank space is used as the field separator. The following slides will explain the sort command better.

Example

Suppose there exists a "file.txt" with a few names of the students enrolled in a music class. The sort command is used to sort all the names in the file.

The file contains these names in the following order:

Wayne

George

Alex

Brandon

Cooper

Tom

svg viewer

Code

To sort these names, run the following code:

main.sh
file.txt
sort file.txt
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved