Search for files in linux by time access to them

How do I display the first 5 directory files that were recently accessed in the /etc directory?

Author: striker92, 2017-07-01

1 answers

" access time " (access time) for a file/directory means either the time when its contents were last received, or when the contents were changed (which happened later).

To get a list of files/directories (inside the specified one) sorted in reverse order (starting with those that were accessed later), use the -u option of the ls :

$ ls -u каталог

You can select only the first five rows from the output, for example, by the program head:

$ ls -u каталог | head -n 5

Quite often, file systems are mounted with the noatime option (specify in the program output mount). in this case, access time will not be true.

Perhaps, in such a situation, the "modification time" (modification time) is suitable, which is updated only when the contents of the file/directory change (for a directory, this means that the file in it was created/deleted/renamed/modified file / directory).

To get a list of files/directories (inside the specified one) sorted in reverse order (starting with those that were changed later), use the -t option of the ls :

$ ls -t каталог

You can select only the first five lines from the output, for example, by the program head:

$ ls -t каталог | head -n 5

You can change the output order to the opposite (in both cases) by adding the option -r:

$ ls -ur каталог
$ ls -tr каталог
 1
Author: aleksandr barakin, 2017-07-03 19:53:12