How to list files sorted by modification date recursively (no stat command available!) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionHow to get counts of the files present in remote directory using sftp commandOutputting last modification date to another file?How to sort results from ls command by modification date (directories first)?Transform list of files (with date) into list of datesHow to enter date as an option in a bash command?Sort files with a specific extension by modified time and store them into an arrayList files in all subdirectories by creation dateHow to copy a certain amount of sorted files? (e.g. 11 GB)How to sort results of Find statement by date?Sorting files into folders based on date in filename?How to merge pre-sorted files into a single BIG file, without excessive memory or temporary disk use

What do you call a plan that's an alternative plan in case your initial plan fails?

Bonus calculation: Am I making a mountain out of a molehill?

Why is black pepper both grey and black?

When is phishing education going too far?

Is there any avatar supposed to be born between the death of Krishna and the birth of Kalki?

Letter Boxed validator

What is this single-engine low-wing propeller plane?

Do I really need recursive chmod to restrict access to a folder?

How widely used is the term Treppenwitz? Is it something that most Germans know?

Stars Make Stars

Check which numbers satisfy the condition [A*B*C = A! + B! + C!]

How to do this path/lattice with tikz

Should I discuss the type of campaign with my players?

What is a Meta algorithm?

Why does Python start at index -1 when indexing a list from the end?

Determinant is linear as a function of each of the rows of the matrix.

Dominant seventh chord in the major scale contains diminished triad of the seventh?

Is the Standard Deduction better than Itemized when both are the same amount?

What would be the ideal power source for a cybernetic eye?

Are my PIs rude or am I just being too sensitive?

Is 1 ppb equal to 1 μg/kg?

Super Attribute Position on Product Page Magento 1

Antler Helmet: Can it work?

I need to find the potential function of a vector field.



How to list files sorted by modification date recursively (no stat command available!)



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionHow to get counts of the files present in remote directory using sftp commandOutputting last modification date to another file?How to sort results from ls command by modification date (directories first)?Transform list of files (with date) into list of datesHow to enter date as an option in a bash command?Sort files with a specific extension by modified time and store them into an arrayList files in all subdirectories by creation dateHow to copy a certain amount of sorted files? (e.g. 11 GB)How to sort results of Find statement by date?Sorting files into folders based on date in filename?How to merge pre-sorted files into a single BIG file, without excessive memory or temporary disk use



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








30















How can I get the list of all files under current directory along with their modification date and sorted by that date?



Now I know how to achieve that with find, stat and sort, but for some weird reason the stat is not installed on the box and it's unlikely that I can get it installed.



Any other option?



PS: gcc is not installed either










share|improve this question






















  • Can you upload a compiled binary and run it there?

    – imz -- Ivan Zakharyaschev
    Mar 14 '11 at 19:58











  • @imz: yes, that's another way to go. The find -printf action seems to be the easiest though.

    – alex
    Mar 15 '11 at 10:09

















30















How can I get the list of all files under current directory along with their modification date and sorted by that date?



Now I know how to achieve that with find, stat and sort, but for some weird reason the stat is not installed on the box and it's unlikely that I can get it installed.



Any other option?



PS: gcc is not installed either










share|improve this question






















  • Can you upload a compiled binary and run it there?

    – imz -- Ivan Zakharyaschev
    Mar 14 '11 at 19:58











  • @imz: yes, that's another way to go. The find -printf action seems to be the easiest though.

    – alex
    Mar 15 '11 at 10:09













30












30








30


5






How can I get the list of all files under current directory along with their modification date and sorted by that date?



Now I know how to achieve that with find, stat and sort, but for some weird reason the stat is not installed on the box and it's unlikely that I can get it installed.



Any other option?



PS: gcc is not installed either










share|improve this question














How can I get the list of all files under current directory along with their modification date and sorted by that date?



Now I know how to achieve that with find, stat and sort, but for some weird reason the stat is not installed on the box and it's unlikely that I can get it installed.



Any other option?



PS: gcc is not installed either







files date sort






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 14 '11 at 19:01









alexalex

4,33931928




4,33931928












  • Can you upload a compiled binary and run it there?

    – imz -- Ivan Zakharyaschev
    Mar 14 '11 at 19:58











  • @imz: yes, that's another way to go. The find -printf action seems to be the easiest though.

    – alex
    Mar 15 '11 at 10:09

















  • Can you upload a compiled binary and run it there?

    – imz -- Ivan Zakharyaschev
    Mar 14 '11 at 19:58











  • @imz: yes, that's another way to go. The find -printf action seems to be the easiest though.

    – alex
    Mar 15 '11 at 10:09
















Can you upload a compiled binary and run it there?

– imz -- Ivan Zakharyaschev
Mar 14 '11 at 19:58





Can you upload a compiled binary and run it there?

– imz -- Ivan Zakharyaschev
Mar 14 '11 at 19:58













@imz: yes, that's another way to go. The find -printf action seems to be the easiest though.

– alex
Mar 15 '11 at 10:09





@imz: yes, that's another way to go. The find -printf action seems to be the easiest though.

– alex
Mar 15 '11 at 10:09










6 Answers
6






active

oldest

votes


















27














My shortest method uses zsh:



print -rl -- **/*(.Om)


(add the D glob qualifiers if you also want to list the hidden files or the files in hidden directories).



If you have GNU find, make it print the file modification times and sort by that. I assume there are no newlines in file names.



find . -type f -printf '%T@ %pn' | sort -k 1 -n | sed 's/^[^ ]* //'


If you have Perl (again, assuming no newlines in file names):



find . -type f -print |
perl -l -ne '
$_$_ = -M; # store file age (mtime - now)
END
$,="n";
print sort $_$b <=> $_$a keys %_; # print by decreasing age
'


If you have Python (again, assuming no newlines in file names):



find . -type f -print |
python -c 'import os, sys; times =
for f in sys.stdin.readlines(): f = f[0:-1]; times[f] = os.stat(f).st_mtime
for f in sorted(times.iterkeys(), key=lambda f:times[f]): print f'


If you have SSH access to that server, mount the directory over sshfs on a better-equipped machine:



mkdir mnt
sshfs server:/path/to/directory mnt
zsh -c 'cd mnt && print -rl **/*(.Om)'
fusermount -u mnt


With only POSIX tools, it's a lot more complicated, because there's no good way to find the modification time of a file. The only standard way to retrieve a file's times is ls, and the output format is locale-dependent and hard to parse.



If you can write to the files, and you only care about regular files, and there are no newlines in file names, here's a horrible kludge: create hard links to all the files in a single directory, and sort them by modification time.



set -ef # disable globbing
IFS='
' # split $(foo) only at newlines
set -- $(find . -type f) # set positional arguments to the file names
mkdir links.tmp
cd links.tmp
i=0 list=
for f; do # hard link the files to links.tmp/0, links.tmp/1, …
ln "../$f" $i
i=$(($i+1))
done
set +f
for f in $(ls -t [0-9]*); do # for each file, in reverse mtime order:
eval 'list="$'$i' # prepend the file name to $list
$list"'
done
printf %s "$list" # print the output
rm -f [0-9]* # clean up
cd ..
rmdir links.tmp





share|improve this answer

























  • The easiest way is probably find . -print | xargs -n99999 -s999999 ls -ltr. But that has the problem that (1) xargs may not allow -m greater than 512 or -s greater than 5120, and (b) even if you can get around that, there's still a kernel-imposed maximum size of the combined argument list and environment. Most of your ideas (save the Perl and Python ones) have the same problem, which is why I specifically avoided building long command lines.

    – geekosaur
    Mar 14 '11 at 22:49











  • In particular, I regularly get "argument list too long" errors using zsh recursive globs in the general case.

    – geekosaur
    Mar 14 '11 at 22:51











  • @geekosaur: Only the last horrible kludge has a problem with long command lines. In zsh, you can do a lot with built-ins (e.g. print -rl **/*'s only limit is how much free memory you have), and beyond that there's zargs. Your proposal of find … | xargs … ls will sort correctly if xargs ends up invoking ls only once, and won't work if there are special characters in file names.

    – Gilles
    Mar 14 '11 at 23:00











  • many thanks for extremely detailed answer with lot of options! :)

    – alex
    Mar 15 '11 at 6:35











  • And that’s why I love zsh.

    – Profpatsch
    Nov 8 '13 at 20:35


















14














Assuming GNU find:



find . -printf '%T@ %c %pn' | sort -k 1n,1 -k 7 | cut -d' ' -f2-


Change 1n,1 to 1nr,1 if you want the files listed most recent first.



If you don't have GNU find it becomes more difficult because ls's timestamp format varies so much (recently modified files have a different style of timestamp, for example).






share|improve this answer























  • Actually you can also change the date and time format with ls --time-style="..." - I'm not sure whether this is standard or GNU ls, likely GNU.

    – asoundmove
    Mar 14 '11 at 22:22












  • Definitely GNU.

    – geekosaur
    Mar 14 '11 at 22:28











  • @asoundmove: unfortunately, the box is too old (RedHat 7.2) and ls doesn't have that option.

    – alex
    Mar 15 '11 at 6:19


















6














On a mac there is no -printf argument to find, but you can do this instead:



find . -print0 | xargs -0 -n 100 stat -f"%m %Sm %N" | sort -n|awk '$1="";print'






share|improve this answer
































    0














    one can try this (one has to build it oneself though) https://github.com/shadkam/recentmost






    share|improve this answer


















    • 5





      Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

      – slm
      Mar 7 '14 at 10:51



















    0














    Ignoring hidden files — with nice & fast time stamp



    Handles spaces in filenames well — not that you should use those!



    $ find . -type f -not -path '*/.*' -printf '%TY.%Tm.%Td %THh%TM %Ta %pn' |sort -nr |head -n 10

    2017.01.25 18h23 Wed ./indenting/Shifting blocks visually.mht
    2016.12.11 12h33 Sun ./tabs/Converting tabs to spaces.mht
    2016.12.02 01h46 Fri ./advocacy/2016.Vim or Emacs - Which text editor do you prefer?.mht
    2016.11.09 17h05 Wed ./Word count - Vim Tips Wiki.mht


    More find galore can be found by following the link.






    share|improve this answer
































      0














      Speaking generally of finding files by date (this won't work for the original poster, but I ended up here so I thought others might as well). In my use case I want to list the files for the purpose of reviewing them before deletion.



      With findutils 4.6.0 I like:



      find . -type f -mtime +270 -exec ls -laFGht --time-style=iso +


      The above command finds files (-type f), in the current working directory (.) that were modified more than 270 days ago (-mtime +270 Also -mtime 0 will produce the last 24 hours, and -mtime -5 shows the last 5 days). It then uses ls to list them by date, newest first (-exec ls -laFGht --time-style=iso +)



      Here's a sample of the output:



      -rwxrwx---+ 1 user1 208M 2018-07-16 ./filename.bak*
      -rwxrwx---+ 1 user1 702 2018-07-15 ./filename.ldf*
      -rwxrwx---+ 1 user1 208M 2018-07-15 ./filename.bak*


      The great thing about this is that once the list has been reviewed, its a simple matter to replace the list part with the find delete command:



      find . -type f -mtime +270 -delete





      share|improve this answer








      New contributor




      Steph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f9247%2fhow-to-list-files-sorted-by-modification-date-recursively-no-stat-command-avail%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        27














        My shortest method uses zsh:



        print -rl -- **/*(.Om)


        (add the D glob qualifiers if you also want to list the hidden files or the files in hidden directories).



        If you have GNU find, make it print the file modification times and sort by that. I assume there are no newlines in file names.



        find . -type f -printf '%T@ %pn' | sort -k 1 -n | sed 's/^[^ ]* //'


        If you have Perl (again, assuming no newlines in file names):



        find . -type f -print |
        perl -l -ne '
        $_$_ = -M; # store file age (mtime - now)
        END
        $,="n";
        print sort $_$b <=> $_$a keys %_; # print by decreasing age
        '


        If you have Python (again, assuming no newlines in file names):



        find . -type f -print |
        python -c 'import os, sys; times =
        for f in sys.stdin.readlines(): f = f[0:-1]; times[f] = os.stat(f).st_mtime
        for f in sorted(times.iterkeys(), key=lambda f:times[f]): print f'


        If you have SSH access to that server, mount the directory over sshfs on a better-equipped machine:



        mkdir mnt
        sshfs server:/path/to/directory mnt
        zsh -c 'cd mnt && print -rl **/*(.Om)'
        fusermount -u mnt


        With only POSIX tools, it's a lot more complicated, because there's no good way to find the modification time of a file. The only standard way to retrieve a file's times is ls, and the output format is locale-dependent and hard to parse.



        If you can write to the files, and you only care about regular files, and there are no newlines in file names, here's a horrible kludge: create hard links to all the files in a single directory, and sort them by modification time.



        set -ef # disable globbing
        IFS='
        ' # split $(foo) only at newlines
        set -- $(find . -type f) # set positional arguments to the file names
        mkdir links.tmp
        cd links.tmp
        i=0 list=
        for f; do # hard link the files to links.tmp/0, links.tmp/1, …
        ln "../$f" $i
        i=$(($i+1))
        done
        set +f
        for f in $(ls -t [0-9]*); do # for each file, in reverse mtime order:
        eval 'list="$'$i' # prepend the file name to $list
        $list"'
        done
        printf %s "$list" # print the output
        rm -f [0-9]* # clean up
        cd ..
        rmdir links.tmp





        share|improve this answer

























        • The easiest way is probably find . -print | xargs -n99999 -s999999 ls -ltr. But that has the problem that (1) xargs may not allow -m greater than 512 or -s greater than 5120, and (b) even if you can get around that, there's still a kernel-imposed maximum size of the combined argument list and environment. Most of your ideas (save the Perl and Python ones) have the same problem, which is why I specifically avoided building long command lines.

          – geekosaur
          Mar 14 '11 at 22:49











        • In particular, I regularly get "argument list too long" errors using zsh recursive globs in the general case.

          – geekosaur
          Mar 14 '11 at 22:51











        • @geekosaur: Only the last horrible kludge has a problem with long command lines. In zsh, you can do a lot with built-ins (e.g. print -rl **/*'s only limit is how much free memory you have), and beyond that there's zargs. Your proposal of find … | xargs … ls will sort correctly if xargs ends up invoking ls only once, and won't work if there are special characters in file names.

          – Gilles
          Mar 14 '11 at 23:00











        • many thanks for extremely detailed answer with lot of options! :)

          – alex
          Mar 15 '11 at 6:35











        • And that’s why I love zsh.

          – Profpatsch
          Nov 8 '13 at 20:35















        27














        My shortest method uses zsh:



        print -rl -- **/*(.Om)


        (add the D glob qualifiers if you also want to list the hidden files or the files in hidden directories).



        If you have GNU find, make it print the file modification times and sort by that. I assume there are no newlines in file names.



        find . -type f -printf '%T@ %pn' | sort -k 1 -n | sed 's/^[^ ]* //'


        If you have Perl (again, assuming no newlines in file names):



        find . -type f -print |
        perl -l -ne '
        $_$_ = -M; # store file age (mtime - now)
        END
        $,="n";
        print sort $_$b <=> $_$a keys %_; # print by decreasing age
        '


        If you have Python (again, assuming no newlines in file names):



        find . -type f -print |
        python -c 'import os, sys; times =
        for f in sys.stdin.readlines(): f = f[0:-1]; times[f] = os.stat(f).st_mtime
        for f in sorted(times.iterkeys(), key=lambda f:times[f]): print f'


        If you have SSH access to that server, mount the directory over sshfs on a better-equipped machine:



        mkdir mnt
        sshfs server:/path/to/directory mnt
        zsh -c 'cd mnt && print -rl **/*(.Om)'
        fusermount -u mnt


        With only POSIX tools, it's a lot more complicated, because there's no good way to find the modification time of a file. The only standard way to retrieve a file's times is ls, and the output format is locale-dependent and hard to parse.



        If you can write to the files, and you only care about regular files, and there are no newlines in file names, here's a horrible kludge: create hard links to all the files in a single directory, and sort them by modification time.



        set -ef # disable globbing
        IFS='
        ' # split $(foo) only at newlines
        set -- $(find . -type f) # set positional arguments to the file names
        mkdir links.tmp
        cd links.tmp
        i=0 list=
        for f; do # hard link the files to links.tmp/0, links.tmp/1, …
        ln "../$f" $i
        i=$(($i+1))
        done
        set +f
        for f in $(ls -t [0-9]*); do # for each file, in reverse mtime order:
        eval 'list="$'$i' # prepend the file name to $list
        $list"'
        done
        printf %s "$list" # print the output
        rm -f [0-9]* # clean up
        cd ..
        rmdir links.tmp





        share|improve this answer

























        • The easiest way is probably find . -print | xargs -n99999 -s999999 ls -ltr. But that has the problem that (1) xargs may not allow -m greater than 512 or -s greater than 5120, and (b) even if you can get around that, there's still a kernel-imposed maximum size of the combined argument list and environment. Most of your ideas (save the Perl and Python ones) have the same problem, which is why I specifically avoided building long command lines.

          – geekosaur
          Mar 14 '11 at 22:49











        • In particular, I regularly get "argument list too long" errors using zsh recursive globs in the general case.

          – geekosaur
          Mar 14 '11 at 22:51











        • @geekosaur: Only the last horrible kludge has a problem with long command lines. In zsh, you can do a lot with built-ins (e.g. print -rl **/*'s only limit is how much free memory you have), and beyond that there's zargs. Your proposal of find … | xargs … ls will sort correctly if xargs ends up invoking ls only once, and won't work if there are special characters in file names.

          – Gilles
          Mar 14 '11 at 23:00











        • many thanks for extremely detailed answer with lot of options! :)

          – alex
          Mar 15 '11 at 6:35











        • And that’s why I love zsh.

          – Profpatsch
          Nov 8 '13 at 20:35













        27












        27








        27







        My shortest method uses zsh:



        print -rl -- **/*(.Om)


        (add the D glob qualifiers if you also want to list the hidden files or the files in hidden directories).



        If you have GNU find, make it print the file modification times and sort by that. I assume there are no newlines in file names.



        find . -type f -printf '%T@ %pn' | sort -k 1 -n | sed 's/^[^ ]* //'


        If you have Perl (again, assuming no newlines in file names):



        find . -type f -print |
        perl -l -ne '
        $_$_ = -M; # store file age (mtime - now)
        END
        $,="n";
        print sort $_$b <=> $_$a keys %_; # print by decreasing age
        '


        If you have Python (again, assuming no newlines in file names):



        find . -type f -print |
        python -c 'import os, sys; times =
        for f in sys.stdin.readlines(): f = f[0:-1]; times[f] = os.stat(f).st_mtime
        for f in sorted(times.iterkeys(), key=lambda f:times[f]): print f'


        If you have SSH access to that server, mount the directory over sshfs on a better-equipped machine:



        mkdir mnt
        sshfs server:/path/to/directory mnt
        zsh -c 'cd mnt && print -rl **/*(.Om)'
        fusermount -u mnt


        With only POSIX tools, it's a lot more complicated, because there's no good way to find the modification time of a file. The only standard way to retrieve a file's times is ls, and the output format is locale-dependent and hard to parse.



        If you can write to the files, and you only care about regular files, and there are no newlines in file names, here's a horrible kludge: create hard links to all the files in a single directory, and sort them by modification time.



        set -ef # disable globbing
        IFS='
        ' # split $(foo) only at newlines
        set -- $(find . -type f) # set positional arguments to the file names
        mkdir links.tmp
        cd links.tmp
        i=0 list=
        for f; do # hard link the files to links.tmp/0, links.tmp/1, …
        ln "../$f" $i
        i=$(($i+1))
        done
        set +f
        for f in $(ls -t [0-9]*); do # for each file, in reverse mtime order:
        eval 'list="$'$i' # prepend the file name to $list
        $list"'
        done
        printf %s "$list" # print the output
        rm -f [0-9]* # clean up
        cd ..
        rmdir links.tmp





        share|improve this answer















        My shortest method uses zsh:



        print -rl -- **/*(.Om)


        (add the D glob qualifiers if you also want to list the hidden files or the files in hidden directories).



        If you have GNU find, make it print the file modification times and sort by that. I assume there are no newlines in file names.



        find . -type f -printf '%T@ %pn' | sort -k 1 -n | sed 's/^[^ ]* //'


        If you have Perl (again, assuming no newlines in file names):



        find . -type f -print |
        perl -l -ne '
        $_$_ = -M; # store file age (mtime - now)
        END
        $,="n";
        print sort $_$b <=> $_$a keys %_; # print by decreasing age
        '


        If you have Python (again, assuming no newlines in file names):



        find . -type f -print |
        python -c 'import os, sys; times =
        for f in sys.stdin.readlines(): f = f[0:-1]; times[f] = os.stat(f).st_mtime
        for f in sorted(times.iterkeys(), key=lambda f:times[f]): print f'


        If you have SSH access to that server, mount the directory over sshfs on a better-equipped machine:



        mkdir mnt
        sshfs server:/path/to/directory mnt
        zsh -c 'cd mnt && print -rl **/*(.Om)'
        fusermount -u mnt


        With only POSIX tools, it's a lot more complicated, because there's no good way to find the modification time of a file. The only standard way to retrieve a file's times is ls, and the output format is locale-dependent and hard to parse.



        If you can write to the files, and you only care about regular files, and there are no newlines in file names, here's a horrible kludge: create hard links to all the files in a single directory, and sort them by modification time.



        set -ef # disable globbing
        IFS='
        ' # split $(foo) only at newlines
        set -- $(find . -type f) # set positional arguments to the file names
        mkdir links.tmp
        cd links.tmp
        i=0 list=
        for f; do # hard link the files to links.tmp/0, links.tmp/1, …
        ln "../$f" $i
        i=$(($i+1))
        done
        set +f
        for f in $(ls -t [0-9]*); do # for each file, in reverse mtime order:
        eval 'list="$'$i' # prepend the file name to $list
        $list"'
        done
        printf %s "$list" # print the output
        rm -f [0-9]* # clean up
        cd ..
        rmdir links.tmp






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 12 hours ago









        Stéphane Chazelas

        314k57596954




        314k57596954










        answered Mar 14 '11 at 20:05









        GillesGilles

        548k13011131631




        548k13011131631












        • The easiest way is probably find . -print | xargs -n99999 -s999999 ls -ltr. But that has the problem that (1) xargs may not allow -m greater than 512 or -s greater than 5120, and (b) even if you can get around that, there's still a kernel-imposed maximum size of the combined argument list and environment. Most of your ideas (save the Perl and Python ones) have the same problem, which is why I specifically avoided building long command lines.

          – geekosaur
          Mar 14 '11 at 22:49











        • In particular, I regularly get "argument list too long" errors using zsh recursive globs in the general case.

          – geekosaur
          Mar 14 '11 at 22:51











        • @geekosaur: Only the last horrible kludge has a problem with long command lines. In zsh, you can do a lot with built-ins (e.g. print -rl **/*'s only limit is how much free memory you have), and beyond that there's zargs. Your proposal of find … | xargs … ls will sort correctly if xargs ends up invoking ls only once, and won't work if there are special characters in file names.

          – Gilles
          Mar 14 '11 at 23:00











        • many thanks for extremely detailed answer with lot of options! :)

          – alex
          Mar 15 '11 at 6:35











        • And that’s why I love zsh.

          – Profpatsch
          Nov 8 '13 at 20:35

















        • The easiest way is probably find . -print | xargs -n99999 -s999999 ls -ltr. But that has the problem that (1) xargs may not allow -m greater than 512 or -s greater than 5120, and (b) even if you can get around that, there's still a kernel-imposed maximum size of the combined argument list and environment. Most of your ideas (save the Perl and Python ones) have the same problem, which is why I specifically avoided building long command lines.

          – geekosaur
          Mar 14 '11 at 22:49











        • In particular, I regularly get "argument list too long" errors using zsh recursive globs in the general case.

          – geekosaur
          Mar 14 '11 at 22:51











        • @geekosaur: Only the last horrible kludge has a problem with long command lines. In zsh, you can do a lot with built-ins (e.g. print -rl **/*'s only limit is how much free memory you have), and beyond that there's zargs. Your proposal of find … | xargs … ls will sort correctly if xargs ends up invoking ls only once, and won't work if there are special characters in file names.

          – Gilles
          Mar 14 '11 at 23:00











        • many thanks for extremely detailed answer with lot of options! :)

          – alex
          Mar 15 '11 at 6:35











        • And that’s why I love zsh.

          – Profpatsch
          Nov 8 '13 at 20:35
















        The easiest way is probably find . -print | xargs -n99999 -s999999 ls -ltr. But that has the problem that (1) xargs may not allow -m greater than 512 or -s greater than 5120, and (b) even if you can get around that, there's still a kernel-imposed maximum size of the combined argument list and environment. Most of your ideas (save the Perl and Python ones) have the same problem, which is why I specifically avoided building long command lines.

        – geekosaur
        Mar 14 '11 at 22:49





        The easiest way is probably find . -print | xargs -n99999 -s999999 ls -ltr. But that has the problem that (1) xargs may not allow -m greater than 512 or -s greater than 5120, and (b) even if you can get around that, there's still a kernel-imposed maximum size of the combined argument list and environment. Most of your ideas (save the Perl and Python ones) have the same problem, which is why I specifically avoided building long command lines.

        – geekosaur
        Mar 14 '11 at 22:49













        In particular, I regularly get "argument list too long" errors using zsh recursive globs in the general case.

        – geekosaur
        Mar 14 '11 at 22:51





        In particular, I regularly get "argument list too long" errors using zsh recursive globs in the general case.

        – geekosaur
        Mar 14 '11 at 22:51













        @geekosaur: Only the last horrible kludge has a problem with long command lines. In zsh, you can do a lot with built-ins (e.g. print -rl **/*'s only limit is how much free memory you have), and beyond that there's zargs. Your proposal of find … | xargs … ls will sort correctly if xargs ends up invoking ls only once, and won't work if there are special characters in file names.

        – Gilles
        Mar 14 '11 at 23:00





        @geekosaur: Only the last horrible kludge has a problem with long command lines. In zsh, you can do a lot with built-ins (e.g. print -rl **/*'s only limit is how much free memory you have), and beyond that there's zargs. Your proposal of find … | xargs … ls will sort correctly if xargs ends up invoking ls only once, and won't work if there are special characters in file names.

        – Gilles
        Mar 14 '11 at 23:00













        many thanks for extremely detailed answer with lot of options! :)

        – alex
        Mar 15 '11 at 6:35





        many thanks for extremely detailed answer with lot of options! :)

        – alex
        Mar 15 '11 at 6:35













        And that’s why I love zsh.

        – Profpatsch
        Nov 8 '13 at 20:35





        And that’s why I love zsh.

        – Profpatsch
        Nov 8 '13 at 20:35













        14














        Assuming GNU find:



        find . -printf '%T@ %c %pn' | sort -k 1n,1 -k 7 | cut -d' ' -f2-


        Change 1n,1 to 1nr,1 if you want the files listed most recent first.



        If you don't have GNU find it becomes more difficult because ls's timestamp format varies so much (recently modified files have a different style of timestamp, for example).






        share|improve this answer























        • Actually you can also change the date and time format with ls --time-style="..." - I'm not sure whether this is standard or GNU ls, likely GNU.

          – asoundmove
          Mar 14 '11 at 22:22












        • Definitely GNU.

          – geekosaur
          Mar 14 '11 at 22:28











        • @asoundmove: unfortunately, the box is too old (RedHat 7.2) and ls doesn't have that option.

          – alex
          Mar 15 '11 at 6:19















        14














        Assuming GNU find:



        find . -printf '%T@ %c %pn' | sort -k 1n,1 -k 7 | cut -d' ' -f2-


        Change 1n,1 to 1nr,1 if you want the files listed most recent first.



        If you don't have GNU find it becomes more difficult because ls's timestamp format varies so much (recently modified files have a different style of timestamp, for example).






        share|improve this answer























        • Actually you can also change the date and time format with ls --time-style="..." - I'm not sure whether this is standard or GNU ls, likely GNU.

          – asoundmove
          Mar 14 '11 at 22:22












        • Definitely GNU.

          – geekosaur
          Mar 14 '11 at 22:28











        • @asoundmove: unfortunately, the box is too old (RedHat 7.2) and ls doesn't have that option.

          – alex
          Mar 15 '11 at 6:19













        14












        14








        14







        Assuming GNU find:



        find . -printf '%T@ %c %pn' | sort -k 1n,1 -k 7 | cut -d' ' -f2-


        Change 1n,1 to 1nr,1 if you want the files listed most recent first.



        If you don't have GNU find it becomes more difficult because ls's timestamp format varies so much (recently modified files have a different style of timestamp, for example).






        share|improve this answer













        Assuming GNU find:



        find . -printf '%T@ %c %pn' | sort -k 1n,1 -k 7 | cut -d' ' -f2-


        Change 1n,1 to 1nr,1 if you want the files listed most recent first.



        If you don't have GNU find it becomes more difficult because ls's timestamp format varies so much (recently modified files have a different style of timestamp, for example).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 14 '11 at 19:42









        geekosaurgeekosaur

        23.1k36053




        23.1k36053












        • Actually you can also change the date and time format with ls --time-style="..." - I'm not sure whether this is standard or GNU ls, likely GNU.

          – asoundmove
          Mar 14 '11 at 22:22












        • Definitely GNU.

          – geekosaur
          Mar 14 '11 at 22:28











        • @asoundmove: unfortunately, the box is too old (RedHat 7.2) and ls doesn't have that option.

          – alex
          Mar 15 '11 at 6:19

















        • Actually you can also change the date and time format with ls --time-style="..." - I'm not sure whether this is standard or GNU ls, likely GNU.

          – asoundmove
          Mar 14 '11 at 22:22












        • Definitely GNU.

          – geekosaur
          Mar 14 '11 at 22:28











        • @asoundmove: unfortunately, the box is too old (RedHat 7.2) and ls doesn't have that option.

          – alex
          Mar 15 '11 at 6:19
















        Actually you can also change the date and time format with ls --time-style="..." - I'm not sure whether this is standard or GNU ls, likely GNU.

        – asoundmove
        Mar 14 '11 at 22:22






        Actually you can also change the date and time format with ls --time-style="..." - I'm not sure whether this is standard or GNU ls, likely GNU.

        – asoundmove
        Mar 14 '11 at 22:22














        Definitely GNU.

        – geekosaur
        Mar 14 '11 at 22:28





        Definitely GNU.

        – geekosaur
        Mar 14 '11 at 22:28













        @asoundmove: unfortunately, the box is too old (RedHat 7.2) and ls doesn't have that option.

        – alex
        Mar 15 '11 at 6:19





        @asoundmove: unfortunately, the box is too old (RedHat 7.2) and ls doesn't have that option.

        – alex
        Mar 15 '11 at 6:19











        6














        On a mac there is no -printf argument to find, but you can do this instead:



        find . -print0 | xargs -0 -n 100 stat -f"%m %Sm %N" | sort -n|awk '$1="";print'






        share|improve this answer





























          6














          On a mac there is no -printf argument to find, but you can do this instead:



          find . -print0 | xargs -0 -n 100 stat -f"%m %Sm %N" | sort -n|awk '$1="";print'






          share|improve this answer



























            6












            6








            6







            On a mac there is no -printf argument to find, but you can do this instead:



            find . -print0 | xargs -0 -n 100 stat -f"%m %Sm %N" | sort -n|awk '$1="";print'






            share|improve this answer















            On a mac there is no -printf argument to find, but you can do this instead:



            find . -print0 | xargs -0 -n 100 stat -f"%m %Sm %N" | sort -n|awk '$1="";print'







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 18 '12 at 2:20

























            answered Feb 18 '12 at 2:12









            killdash9killdash9

            16114




            16114





















                0














                one can try this (one has to build it oneself though) https://github.com/shadkam/recentmost






                share|improve this answer


















                • 5





                  Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

                  – slm
                  Mar 7 '14 at 10:51
















                0














                one can try this (one has to build it oneself though) https://github.com/shadkam/recentmost






                share|improve this answer


















                • 5





                  Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

                  – slm
                  Mar 7 '14 at 10:51














                0












                0








                0







                one can try this (one has to build it oneself though) https://github.com/shadkam/recentmost






                share|improve this answer













                one can try this (one has to build it oneself though) https://github.com/shadkam/recentmost







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 '14 at 10:47









                user3392225user3392225

                1




                1







                • 5





                  Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

                  – slm
                  Mar 7 '14 at 10:51













                • 5





                  Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

                  – slm
                  Mar 7 '14 at 10:51








                5




                5





                Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

                – slm
                Mar 7 '14 at 10:51






                Welcome to Unix & Linux Stack Exchange! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

                – slm
                Mar 7 '14 at 10:51












                0














                Ignoring hidden files — with nice & fast time stamp



                Handles spaces in filenames well — not that you should use those!



                $ find . -type f -not -path '*/.*' -printf '%TY.%Tm.%Td %THh%TM %Ta %pn' |sort -nr |head -n 10

                2017.01.25 18h23 Wed ./indenting/Shifting blocks visually.mht
                2016.12.11 12h33 Sun ./tabs/Converting tabs to spaces.mht
                2016.12.02 01h46 Fri ./advocacy/2016.Vim or Emacs - Which text editor do you prefer?.mht
                2016.11.09 17h05 Wed ./Word count - Vim Tips Wiki.mht


                More find galore can be found by following the link.






                share|improve this answer





























                  0














                  Ignoring hidden files — with nice & fast time stamp



                  Handles spaces in filenames well — not that you should use those!



                  $ find . -type f -not -path '*/.*' -printf '%TY.%Tm.%Td %THh%TM %Ta %pn' |sort -nr |head -n 10

                  2017.01.25 18h23 Wed ./indenting/Shifting blocks visually.mht
                  2016.12.11 12h33 Sun ./tabs/Converting tabs to spaces.mht
                  2016.12.02 01h46 Fri ./advocacy/2016.Vim or Emacs - Which text editor do you prefer?.mht
                  2016.11.09 17h05 Wed ./Word count - Vim Tips Wiki.mht


                  More find galore can be found by following the link.






                  share|improve this answer



























                    0












                    0








                    0







                    Ignoring hidden files — with nice & fast time stamp



                    Handles spaces in filenames well — not that you should use those!



                    $ find . -type f -not -path '*/.*' -printf '%TY.%Tm.%Td %THh%TM %Ta %pn' |sort -nr |head -n 10

                    2017.01.25 18h23 Wed ./indenting/Shifting blocks visually.mht
                    2016.12.11 12h33 Sun ./tabs/Converting tabs to spaces.mht
                    2016.12.02 01h46 Fri ./advocacy/2016.Vim or Emacs - Which text editor do you prefer?.mht
                    2016.11.09 17h05 Wed ./Word count - Vim Tips Wiki.mht


                    More find galore can be found by following the link.






                    share|improve this answer















                    Ignoring hidden files — with nice & fast time stamp



                    Handles spaces in filenames well — not that you should use those!



                    $ find . -type f -not -path '*/.*' -printf '%TY.%Tm.%Td %THh%TM %Ta %pn' |sort -nr |head -n 10

                    2017.01.25 18h23 Wed ./indenting/Shifting blocks visually.mht
                    2016.12.11 12h33 Sun ./tabs/Converting tabs to spaces.mht
                    2016.12.02 01h46 Fri ./advocacy/2016.Vim or Emacs - Which text editor do you prefer?.mht
                    2016.11.09 17h05 Wed ./Word count - Vim Tips Wiki.mht


                    More find galore can be found by following the link.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 28 '17 at 6:50

























                    answered Jan 27 '17 at 22:55









                    Serge StroobandtSerge Stroobandt

                    85321427




                    85321427





















                        0














                        Speaking generally of finding files by date (this won't work for the original poster, but I ended up here so I thought others might as well). In my use case I want to list the files for the purpose of reviewing them before deletion.



                        With findutils 4.6.0 I like:



                        find . -type f -mtime +270 -exec ls -laFGht --time-style=iso +


                        The above command finds files (-type f), in the current working directory (.) that were modified more than 270 days ago (-mtime +270 Also -mtime 0 will produce the last 24 hours, and -mtime -5 shows the last 5 days). It then uses ls to list them by date, newest first (-exec ls -laFGht --time-style=iso +)



                        Here's a sample of the output:



                        -rwxrwx---+ 1 user1 208M 2018-07-16 ./filename.bak*
                        -rwxrwx---+ 1 user1 702 2018-07-15 ./filename.ldf*
                        -rwxrwx---+ 1 user1 208M 2018-07-15 ./filename.bak*


                        The great thing about this is that once the list has been reviewed, its a simple matter to replace the list part with the find delete command:



                        find . -type f -mtime +270 -delete





                        share|improve this answer








                        New contributor




                        Steph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.
























                          0














                          Speaking generally of finding files by date (this won't work for the original poster, but I ended up here so I thought others might as well). In my use case I want to list the files for the purpose of reviewing them before deletion.



                          With findutils 4.6.0 I like:



                          find . -type f -mtime +270 -exec ls -laFGht --time-style=iso +


                          The above command finds files (-type f), in the current working directory (.) that were modified more than 270 days ago (-mtime +270 Also -mtime 0 will produce the last 24 hours, and -mtime -5 shows the last 5 days). It then uses ls to list them by date, newest first (-exec ls -laFGht --time-style=iso +)



                          Here's a sample of the output:



                          -rwxrwx---+ 1 user1 208M 2018-07-16 ./filename.bak*
                          -rwxrwx---+ 1 user1 702 2018-07-15 ./filename.ldf*
                          -rwxrwx---+ 1 user1 208M 2018-07-15 ./filename.bak*


                          The great thing about this is that once the list has been reviewed, its a simple matter to replace the list part with the find delete command:



                          find . -type f -mtime +270 -delete





                          share|improve this answer








                          New contributor




                          Steph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






















                            0












                            0








                            0







                            Speaking generally of finding files by date (this won't work for the original poster, but I ended up here so I thought others might as well). In my use case I want to list the files for the purpose of reviewing them before deletion.



                            With findutils 4.6.0 I like:



                            find . -type f -mtime +270 -exec ls -laFGht --time-style=iso +


                            The above command finds files (-type f), in the current working directory (.) that were modified more than 270 days ago (-mtime +270 Also -mtime 0 will produce the last 24 hours, and -mtime -5 shows the last 5 days). It then uses ls to list them by date, newest first (-exec ls -laFGht --time-style=iso +)



                            Here's a sample of the output:



                            -rwxrwx---+ 1 user1 208M 2018-07-16 ./filename.bak*
                            -rwxrwx---+ 1 user1 702 2018-07-15 ./filename.ldf*
                            -rwxrwx---+ 1 user1 208M 2018-07-15 ./filename.bak*


                            The great thing about this is that once the list has been reviewed, its a simple matter to replace the list part with the find delete command:



                            find . -type f -mtime +270 -delete





                            share|improve this answer








                            New contributor




                            Steph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.










                            Speaking generally of finding files by date (this won't work for the original poster, but I ended up here so I thought others might as well). In my use case I want to list the files for the purpose of reviewing them before deletion.



                            With findutils 4.6.0 I like:



                            find . -type f -mtime +270 -exec ls -laFGht --time-style=iso +


                            The above command finds files (-type f), in the current working directory (.) that were modified more than 270 days ago (-mtime +270 Also -mtime 0 will produce the last 24 hours, and -mtime -5 shows the last 5 days). It then uses ls to list them by date, newest first (-exec ls -laFGht --time-style=iso +)



                            Here's a sample of the output:



                            -rwxrwx---+ 1 user1 208M 2018-07-16 ./filename.bak*
                            -rwxrwx---+ 1 user1 702 2018-07-15 ./filename.ldf*
                            -rwxrwx---+ 1 user1 208M 2018-07-15 ./filename.bak*


                            The great thing about this is that once the list has been reviewed, its a simple matter to replace the list part with the find delete command:



                            find . -type f -mtime +270 -delete






                            share|improve this answer








                            New contributor




                            Steph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            Steph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered 12 hours ago









                            StephSteph

                            1




                            1




                            New contributor




                            Steph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            Steph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            Steph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f9247%2fhow-to-list-files-sorted-by-modification-date-recursively-no-stat-command-avail%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                -date, files, sort

                                Popular posts from this blog

                                Frič See also Navigation menuinternal link

                                Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant

                                fontconfig warning: “/etc/fonts/fonts.conf”, line 100: unknown “element blank” The 2019 Stack Overflow Developer Survey Results Are In“tar: unrecognized option --warning” during 'apt-get install'How to fix Fontconfig errorHow do I figure out which font file is chosen for a system generic font alias?Why are some apt-get-installed fonts being ignored by fc-list, xfontsel, etc?Reload settings in /etc/fonts/conf.dTaking 30 seconds longer to boot after upgrade from jessie to stretchHow to match multiple font names with a single <match> element?Adding a custom font to fontconfigRemoving fonts from fontconfig <match> resultsBroken fonts after upgrading Firefox ESR to latest Firefox