Using find command, you can search files by type, size, creation date, or modified time etc. Or files that access within certain time. For example:

Check files access in last 2 minutes, cmin or mmin can be used in the same way

$find ./mtx-1.3.12/  -amin +0 -amin -2
./mtx-1.3.12/
./mtx-1.3.12/mtx-inventory.c
./mtx-1.3.12/mtx-driveinfo.c
However, what if you have a huge list of files within the time period you want to search, or for some reason, you are not sure the time. is there way to list files by time order?
 
Some of problems can be solved by one Linux utility, some can be identified by combination of these basic linux commands, here are example of them. Here I show you some examples


1. List Files Based on Modification Time

The below command lists files in long listing format, and sorts files based on modification time, newest first. To sort in reverse order, use '-r' switch with this command.
# ls -lt
total 211976
drwxr-xr-x 2 fibrevillage fibrevillage 3375104 May  2 16:52 ./
-rw-r--r-- 1 fibrevillage fibrevillage    1357 May  2 16:52 75483b560b22e2a7d6a5186a14624323.js
-rw-r--r-- 1 fibrevillage fibrevillage    1341 May  2 16:50 00b9d9dbea64509efc7797904e00f918.js
-rw-r--r-- 1 fibrevillage fibrevillage    1330 May  2 16:48 1ff578de083aac220387e1470173cbbb.js
-rw-r--r-- 1 fibrevillage fibrevillage    1319 May  2 16:47 33dabe320a5fe485b7b2f79e7cf88f6a.js
-rw-r--r-- 1 fibrevillage fibrevillage    1346 May  2 16:45 112b3be7cb9e7887ed5f0f50139df85b.js
...

Older files first

# ls -rlt
total 211984
drwxr-xr-x 3 fibrevillage fibrevillage    4096 Sep 21  2015 ../
-rw-r--r-- 1 fibrevillage fibrevillage    1340 Mar  1 00:00 d23517a2261319ceae90a0b119492f35.js
-rw-r--r-- 1 fibrevillage fibrevillage    1320 Mar  1 00:08 672399345f29a4c380303f8a5d3eee3e.js
-rw-r--r-- 1 fibrevillage fibrevillage    1325 Mar  1 00:11 99629f2bbd53b46a1d2775251fca731e.js
-rw-r--r-- 1 fibrevillage fibrevillage    1310 Mar  1 00:14 9fe2cdd9e97b80a7ab95af8f01e33459.js
-rw-r--r-- 1 fibrevillage fibrevillage    1351 Mar  1 00:18 e5f1c995822a4f3319660c22b0b38be8.js
-rw-r--r-- 1 fibrevillage fibrevillage    1348 Mar  1 00:19 31a1632a2ab29bbe053c450ed7a3ab3c.js
-rw-r--r-- 1 fibrevillage fibrevillage    1314 Mar  1 00:20 524777e1df79363010e88177f361e6f6.js
-rw-r--r-- 1 fibrevillage fibrevillage    1310 Mar  1 00:22 32b63b7f2e2926d0fb5c21468c6615e3.js
-rw-r--r-- 1 fibrevillage fibrevillage    1349 Mar  1 00:23 343bdb74f42591dca3c3cfbac863310a.js
-rw-r--r-- 1 fibrevillage fibrevillage    1339 Mar  1 00:25 17fad6b7ace6b0b5f9a32f05b531600b.js
...

2. List Files Based on Last Access Time

Listing of files in directory based on last access time, i.e. based on time the file was last accessed, not modified.
# ls -ltu 
total 211988
drwxr-xr-x 2 fibrevillage fibrevillage 3375104 May  2 16:55 ./
-rw-r--r-- 1 fibrevillage fibrevillage    1309 May  2 16:54 2c750414796dab930714071a2ba6828f.js
-rw-r--r-- 1 fibrevillage fibrevillage    1330 May  2 16:53 e2bbd241a09b8bdacc45f96d20e79c4a.js
-rw-r--r-- 1 fibrevillage fibrevillage    1357 May  2 16:52 75483b560b22e2a7d6a5186a14624323.js
-rw-r--r-- 1 fibrevillage fibrevillage    1341 May  2 16:50 00b9d9dbea64509efc7797904e00f918.js
-rw-r--r-- 1 fibrevillage fibrevillage    1364 May  2 16:48 529ac96e59e17cdf33aeb9ec904feb57.js
-rw-r--r-- 1 fibrevillage fibrevillage    1319 May  2 16:47 33dabe320a5fe485b7b2f79e7cf88f6a.js
...

3. List Files Based on Last Modification Time

Listing of files in directory based on last modification time of file’s status information, or the 'ctime'. This command would list that file first whose any status information like: owner, group, permissions, size etc has been recently changed.
# ls -ltc
total 720
drwxr-xr-x  2 fibrevillage fibrevillage 24576 May  2 00:30 ./
-rw-r--r--  1 fibrevillage fibrevillage  4109 May  2 00:30 cache_com_tags_20582fe4cc147447db-ac
-rw-r--r--  1 fibrevillage fibrevillage  3755 Apr 26 02:25 cache_com_tags_2077582fe4cc147447db-
-rw-r--r--  1 fibrevillage fibrevillage  4404 Apr 25 17:17 cache_com_tags_20c77582fe4cc147447db
-rw-r--r--  1 fibrevillage fibrevillage  3752 Apr 21 04:22 cache_com_tags_20582fe4cc147447db-ad
-rw-r--r--  1 fibrevillage fibrevillage  4734 Apr 15 08:32 20cbdc4fe945fc77db-cache-com_tags-2f
-rw-r--r--  1 fibrevillage fibrevillage  4644 Apr  9 20:17 20cbdc4fe945fc77db-cache-com_tags-95
-rw-r--r--  1 fibrevillage fibrevillage  4736 Apr  9 19:04 20cbdc4fe945fc77547db-cache-com_tags
-rw-r--r--  1 fibrevillage fibrevillage  4110 Apr  9 12:36 20cbdc4fe945fc7757db-cache-com_tags
...

If '-a' switch is used with above commands, they can list and sort even the hidden files in current directory, and '-r' switch lists the output in reverse order.

4. Sorting Files based on Month

Use find command to find all files in root (‘/’) directory and then print the result as: Month in which file was accessed and then filename. Of that complete result, here we list out top 11 entries.
# find / -type f -printf "\n%Ab %p" | head -n 11
Nov /lib/crda/regulatory.bin
Nov /lib/crda/pubkeys/key.pub.pem
Nov /lib/crda/pubkeys/linville.key.pub.pem
Nov /lib/firmware/usb8388.bin
Nov /lib/firmware/ctfw-3.0.3.1.bin
Nov /lib/firmware/cbfw-3.1.0.0.bin
Feb /lib/firmware/keyspan/usa18x.fw
Feb /lib/firmware/keyspan/usa19.fw
Feb /lib/firmware/keyspan/usa49wlc.fw
Feb /lib/firmware/keyspan/usa28xa.fw

The below command sorts the output using key as first field, specified by '-k1' and then it sorts on Month as specified by 'M' ahead of it.

# find / -type f -printf "\n%Ab %p" | head -n 11 | sort -k1M
Apr /usr/lib/libcdr-0.0.so.0.0.15
Apr /usr/lib/libchromeXvMCPro.so.1.0.0
Apr /usr/lib/libchromeXvMC.so.1.0.0
Apr /usr/lib/libt1.so.5.1.2
Nov /usr/lib/ldscripts/elf32_x86_64.xr
Nov /usr/lib/ldscripts/elf_i386.xbn
Nov /usr/lib/ldscripts/i386linux.xn
Dec /usr/lib/libcpufreq.so.0.0.0
Dec /usr/lib/msttcorefonts/update-ms-fonts
Dec /usr/lib/nvidia/pre-install

5. Sort Files Based on Date

Use find command to find all the files in root directory, but now we will print the result as: last date the file was accessed, last time the file was accessed and then filename. Of that we take out top 11 entries.
# find / -type f -printf "\n%AD %AT %p" | head -n 11
03/07/13 10:56:22.0000000000 /opt/glite/yaim/node-info.d/emi-nagios
03/07/13 10:56:22.0000000000 /opt/glite/yaim/node-info.d/glite-vobox
03/07/13 10:56:22.0000000000 /opt/glite/yaim/node-info.d/glite-wn
03/07/13 10:56:22.0000000000 /opt/glite/yaim/node-info.d/glite-ui
03/07/13 10:56:22.0000000000 /opt/glite/yaim/node-info.d/emi-ui_tar
03/07/13 10:56:22.0000000000 /opt/glite/yaim/node-info.d/glite-ui_tar
03/07/13 10:56:22.0000000000 /opt/glite/yaim/node-info.d/glite-wn_tar
04/19/13 13:21:41.0000000000 /opt/glite/yaim/libexec/xmlUtils.pyc
04/19/13 13:21:41.0000000000 /opt/glite/yaim/libexec/xmlUtils.py
04/19/13 13:21:41.0000000000 /opt/glite/yaim/libexec/ClassAd.pyc
The below sort command first sorts on basis of last digit of the year, then sorts on basis of last digit of month in reverse order and finally sorts on basis of first field. Here, ‘1.8‘ means 8th column of first field and ‘n’ ahead of it means numerical sort, while ‘r’ indicates reverse order sorting.
# find / -type f -printf "\n%AD %AT %p" | head -n 11 | sort -k1.8n -k1.1nr -k1
12/07/15 10:34:45.2694776230 /usr/lib/libcpufreq.so.0.0.0
12/08/15 11:30:38.0000000000 /usr/lib/nvidia/pre-install
12/18/15 11:19:25.2656728990 /usr/lib/msttcorefonts/update-ms-fonts
11/12/15 12:56:34.0000000000 /usr/lib/ldscripts/elf32_x86_64.xr
11/12/15 12:56:34.0000000000 /usr/lib/ldscripts/elf_i386.xbn
11/12/15 12:56:34.0000000000 /usr/lib/ldscripts/i386linux.xn
04/11/15 06:08:34.9819910430 /usr/lib/libchromeXvMCPro.so.1.0.0
04/11/15 06:08:34.9939910430 /usr/lib/libt1.so.5.1.2
04/11/15 06:08:35.0099910420 /usr/lib/libcdr-0.0.so.0.0.15
04/11/15 06:08:35.0099910420 /usr/lib/libchromeXvMC.so.1.0.0

6. Sorting Files Based on Time

Use find command to list out top 11 files in root directory and print the result in format: last time file was accessed and then filename.
#find /usr -type f -printf "\n%AT %p" | head -n 11
10:34:50.5730550180 /usr/lib/libcairo.so.2.10800.8
03:32:47.6028603980 /usr/lib/libGLU.so.1.3.1
03:32:33.3837485510 /usr/lib/libXft.so.2.3.1
03:32:47.6028603980 /usr/lib/libglapi.so.0.0.0
15:31:01.6565739170 /usr/lib/libnssdbm3.so
03:32:47.6198605320 /usr/lib/libpciaccess.so.0.11.1
03:32:47.6198605320 /usr/lib/libxcb-damage.so.0.0.0
10:34:50.6240554140 /usr/lib/libfreetype.so.6.3.22
03:32:47.6198605320 /usr/lib/libxcb-res.so.0.0.0
19:50:41.1937325490 /usr/lib/vmware/messages/zh_CN/vmware.vmsg
The below command sorts the output based on first column of the first field of the output which is first digit of hour.
#find /usr -type f -printf "\n%AT %p" | head -n 11 | sort -k1.1n
03:32:33.3837485510 /usr/lib/libXft.so.2.3.1
03:32:47.6028603980 /usr/lib/libglapi.so.0.0.0
03:32:47.6028603980 /usr/lib/libGLU.so.1.3.1
03:32:47.6198605320 /usr/lib/libpciaccess.so.0.11.1
03:32:47.6198605320 /usr/lib/libxcb-damage.so.0.0.0
03:32:47.6198605320 /usr/lib/libxcb-res.so.0.0.0
10:34:50.5730550180 /usr/lib/libcairo.so.2.10800.8
10:34:50.6240554140 /usr/lib/libfreetype.so.6.3.22
15:31:01.6565739170 /usr/lib/libnssdbm3.so
19:50:41.1937325490 /usr/lib/vmware/messages/zh_CN/vmware.vmsg

7. Sorting Ouptut of ls -l based on Date

Sort output of ls -l based on date, month(6th field) and date(7th field).
#ls -l | sort -k6M -k7n
total 76692
drwxr-xr-x  4 root     root      4096 Feb 23 15:45 chromium-browser
drwxr-xr-x  5 root     root      4096 Mar  7  2013 glite
drwxr-xr-x  5 root     root      4096 Apr  4  2014 komodo
drwxr-xr-x  3 root     root      4096 Apr 25 13:27 vidyo
drwxr-xr-x  2 root     root         0 May  4 02:10 mirror
drwxr-xr-x. 3 root     root      4096 Jun  6  2013 Adobe

Comments powered by CComment