What does the -k option do?

QuestionsQuestions8 SkillsProDec, 14 2025
0107

Great question! Labby is happy to explain.

In the sort command, the -k option is used to specify the sort key – that is, which field or fields you want sort to use when organizing the lines.

In our current step, the command is:

sort -t: -k3 -n /etc/passwd | head -n 5

Here, -k3 means "sort based on the third field". Since we've already defined : as the field separator with -t:, sort will look at the third colon-separated part of each line in /etc/passwd to decide the order.

So, combining -t: and -k3 allows you to precisely tell sort which specific column of data it should consider when sorting.

Feel free to ask if anything is unclear!

0 Comments

no data
Be the first to share your comment!