101

I have a directory: /home/user/

How can I list every file in this directory (including those in sub directories) and order them by the date that they were last modified?

163

You can use:

$ ls -Rt

where -R means recursive (include subdirectories) and -t means "sort by last modification date".


To see a list of files sorted by date modified, use:

$ ls -l -Rt

An alias can also be created to achieve this:

alias ll='ls -l'; ll -Rt
71

If you'd like a master list in which all the files are sorted together by modification date, showing the directory they're in, but not grouped by directory, you can use this:

find . -type f -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | cut -f 2- -d ' '

The result looks a lot like ls -l:

-rw-r--r-- 1 root     root         3892 08/11/2009 11:03:36 /usr/share/man/man1/xmllint.1.gz
-rw-r--r-- 1 root     root        22946 08/13/2009 11:59:20 /usr/share/man/man1/curl.1.gz
-rw-r--r-- 1 root     root          728 08/17/2009 12:06:33 /usr/share/man/man1/thunderbird.1.gz
-rw-r--r-- 1 root     root          873 08/18/2009 10:52:47 /usr/share/man/man1/libgnutls-config.1.gz
-rw-r--r-- 1 root     root         2552 08/19/2009 02:00:34 /usr/share/man/man3/Purple.3pm.gz
-rw-r--r-- 1 root     root         9546 08/19/2009 02:02:00 /usr/share/man/man1/pidgin.1.gz
-rw-r--r-- 1 root     root         2201 08/19/2009 02:02:46 /usr/share/man/man3/Pidgin.3pm.gz
-rw-r--r-- 1 root     root          926 08/19/2009 02:03:05 /usr/share/man/man1/purple-remote.1.gz
-rw-r--r-- 1 root     root        18052 08/19/2009 04:11:47 /usr/share/man/man1/mono.1.gz
-rw-r--r-- 1 root     root         1845 08/19/2009 04:11:47 /usr/share/man/man5/mono-config.5.gz

Mac OS X

For those of you using Mac OS X, option -printf is not available on BSD find (you will get this error: find: -printf: unknown primary or operator). Fortunately you can Install GNU find through Homebrew (there should be an option to Fink and Macports as well):

brew install findutils

After install it the GNU find should be available to you as gfind. So, all you need to do is change the line above to:

gfind . -type f -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | cut -f 2- -d ' '

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["<li class=\"-item\"><a href=\"https://www.facebook.com/officialstackoverflow/\" class=\"-link\">Facebook</a></li>\r\n                    <li class=\"-item\"><a href=\"https://twitter.com/stackoverflow\" class=\"-link\">Twitter</a></li>\r\n                    <li class=\"-item\"><a href=\"https://linkedin.com/company/stack-overflow\" class=\"-link\">LinkedIn</a></li>\r\n                </ul>\r\n\r\n                <p class=\"mt-auto mb24\">\r\nsite design / logo &#169; 2019 Stack Exchange Inc; user contributions licensed under <a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a>\r\n                            with <a href=\"https://stackoverflow.blog/2009/06/25/attribution-required/\" rel=\"license\">attribution required</a>.\r\n                    <span id=\"svnrev\">rev&nbsp;2019.7.17.34341</span>\r\n                </p>\r\n            </div>\r\n        </div>\r\n\r\n            </footer>\r\n            <script>StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); })</script>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works b"], "copyright__copyright__copyright": ["ere should be an option to Fink and Macports as well):\n\nbrew install findutils\n\nAfter install it the GNU find should be available to you as gfind. So, all you need to do is change the line above to:\n\ngfind . -type f -printf \"%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\\n\" | sort | cut -f 2- -d ' '\n\nYour Answer\n\nBy clicking \u201cPost Your Answer\u201d, you agree to our terms of service, privacy policy and cookie policy\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}