sort files inside a directory and sub-directories by latest created
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
find /dir -type f -iname \*.jpg -print0 | xargs -0 ls -lrt | tail -10
However, if you have a very large number of files the list of arguments passed to xargs can be too long, resulting in an error. In that case we have to find another way.
PS - You can restrict the search using -newer. For example, if you know that the last 10 files are created in the last 3 hours you can do something like:
Just FYI, Unix doesn't actually have a creation time:
Quote:
Three fields in the inode structure contain the last access, change, and modification times: atime, ctime, and mtime. The atime field is updated each time the pointer to the file's data blocks is followed and the file's data is read. The mtime field is updated each time the file's data changes. The ctime field is updated each time the file's inode changes. The ctime is not creation time; there is no way under standard Unix to find a file's creation time.
Just FYI, Unix doesn't actually have a creation time:
But wouldn't you have something similar if you mounted your filesystem(s) noatime? Look at the difference between access time and the other time variables in the example here:
Just FYI, Unix doesn't actually have a creation time:
That's right. In this case we don't speak about "creation date". Just a matter of terminology: "file created", in place of "file modified". I would add that the new ext4 filesystem will store creation time as well. Here is a comparison table of filesystems that shows which support cration timestamps and which not.
For most people, mtime is what they really care about. Sometimes atime if its a read-only file.
Up until/including ext3, you have to embed the creation date in the filename (or store it elsewhere). eg
The output of the a timestamp field needs to be in a form that is sortable. The output of "ls -l ..." can change form depending on the age of the file.
Here I use seconds, which a numeric sort handles easily.
The timestamp in seconds is printed, followed by a tab, and then the filename.
To deal with filenames with whitespace, pipe the output through "tr '\n' '\0'" and use "xargs -0" to process the files.
You might want to add an -mtime option in the find command to limit the number of files `find' finds. A very long list could cause the sort command to run to slow. The -mtime argument you use might return 100 filenames, for example, but this is a lot better than piping 10,000 lines into sort.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.