Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder durangod's Avatar
    Join Date
    Nov 2010
    Location
    East Texas USA
    Posts
    2,068
    Thanks
    349
    Thanked 57 Times in 55 Posts

    How to sort directory contents

    hi,

    how do i sort directory contents using the ls command by date and size.

    Thanks
    If a php file only has php code within it you do not need to use the closing php tag
    A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
    durangod is short for durango dave

  2. #2
    Administrator chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    3,157
    Thanks
    29
    Thanked 185 Times in 176 Posts
    To sort current directory by last modified date, newest to oldest, including sample output:

    Code:
    # ls -lth
    total 66M
    -rw-r--r-- 1 www-data www-data  18M Mar 18 16:40 1521405188_5aaecd041a4703.96011429.flv
    -rw-r--r-- 1 www-data www-data  18M Mar 18 15:09 1521400163_5aaeb963768cf3.12605491.flv
    -rw-r--r-- 1 www-data www-data 9.2M Mar 18 14:58 1521399512_5aaeb6d81effe3.56647350.flv
    -rw-r--r-- 1 www-data www-data  22M Mar 18 13:41 1521394894_5aaea4cee69f11.13274165.flv
    To sort current directory by size, descending, including sample output:

    Code:
    # ls -lSh
    total 66M
    -rw-r--r-- 1 www-data www-data  22M Mar 18 13:41 1521394894_5aaea4cee69f11.13274165.flv
    -rw-r--r-- 1 www-data www-data  18M Mar 18 16:40 1521405188_5aaecd041a4703.96011429.flv
    -rw-r--r-- 1 www-data www-data  18M Mar 18 15:09 1521400163_5aaeb963768cf3.12605491.flv
    -rw-r--r-- 1 www-data www-data 9.2M Mar 18 14:58 1521399512_5aaeb6d81effe3.56647350.flv
    The flags: t = time, S = size, and h= human readable format

    See: ls(1) - Linux manual page

    You could add " | more" to the end of either command for large directories, to scroll through the output:

    Code:
    # ls -lth | more
    # ls -lSh | more
    But I have no idea how to sort by BOTH date and size
    Last edited by chump2877; Mar 19th, 2018 at 02:15 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like our YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
    Explore all products and services, view demos, review documentation, check prices, and more!
    ♪♪ …Need Web Hosting For Our YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  3. Users who have thanked chump2877 for this post:

    durangod (Mar 20th, 2018)


 

Tags for this Thread

Posting Permissions

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