Amazon Have you ever wanted to sort files by the access date from oldest to latest? Have you ever wanted to sort files by the creation date from latest to oldest? This tutorial will walk you through how to display a file's access time or create time, and how to show files in a directory in any chronological order based on file access or create time you want.
First let's go over the following commands.
To show the creation time of a file:
ls -l --time=status --full-time some-file.txt
To show the access time of a file:
ls -l --time=access --full-time some-file.txt
Next we'll look at how to display the files in a certain chronological order based on file access or create time.
Show files in descending order of file access time.
In other words, show latest file first. Sort files in reverse chronological order based on file access time, or sort files from latest to oldest. "access" includes read or write it with any tool such as vi.
1 | $ ls -lt -- time =access --full- time |more |
3 | -rwxrwxrwx 1 www-data www-data 55752 2015-11-13 15:31:50.000000000 +0800 some-file.txt |
4 | -rwxrwxrwx 1 www-data www-data 43643 2015-11-13 15:31:47.000000000 +0800 some-file2.txt |
If you want to sort files in descending order of file creation time, simply replace "access" with "status" like the following:
$ ls -lt --time=status --full-time |more
Show files in ascending order of file access time.
In other words, show oldest file first. Sort files in chronological order based on file access time, or sort files from oldest to latest. "access" includes read or write it with any tool such as vi.
1 | $ ls -ltr -- time =access --full- time |more |
3 | -rwxrwxrwx 1 www-data www-data 46375 2015-10-21 12:05:19.088000000 +0800 some-file3.txt |
4 | -rwxrwxrwx 1 www-data www-data 46588 2015-10-21 12:28:58.300000000 +0800 some-file4.txt |
If you want to sort files by file creation time, simply replace "access" with "status".
Questions? Let me know!