Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Sort Command - Aescending and Descending Sort

    I'm trying to figure out how to pipe the current directory listing into sort so that the output is the date in descending order (primary sort key). If there are multiple entries with the same date, I'd like the times sorted in ascending order.

    It seems simple but for some reason this isn't working:

    ls -l | sort -k 6r -k 7

    For some reason it doesn't seem to ever get to the second sort key when using column 6 (last modified date).

    Thanks in advance!

  2. #2
    Problem solved! Was a lot more complicated than I thought, but I figured out a solution. It's a homework question and I know a few people from my class browse these forums so I'll post the solution tomorrow .
    Last edited by pacapaca; 10-20-2010 at 06:48 PM.

  3. #3
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    BC Canada
    If your homework is an exercise in how to read a man page, it would have told you that the sort order of files listed can be by time, using the '-t' argument, and that it can be given in reverse order, by adding the '-r' argument. If it was an exercise in using sort , then good for you to have a solution.

    --- rod.
    Stuff happens. Then stays happened.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts