sort examples



Last revision July 20, 2004 .

  1. Sort the output of the ps command to group all processes owned by each user together. The username is the first blank-delimited field on the output lines:
      ps augx | sort
  2. Sort the output of ps by the process id number to put all processes in chronological order of their start time. The process id is the second blank-delimited field on each output line, and must be treated as a numeric value, not text, to sort correctly:
      ps augx | sort +1n -2
  3. Find out how many people are logged into pangea, not how many logins (one person can have multiple logins). First sort the output of the w command to get multiple logins from the same user together and use the option that removes the lines with duplicated user names to yield only one line per account name. Pipe the result through wc to count the number of lines, using option to only specify line count, not character and word count as well. This could be made into an alias:
      w | sort -u +0 -1 | wc -l

Comments or Questions?