-1

I'm looking for a way to sort related files (files created at almost the same time)

My best solution atm revolves grabbing the earliest file and move it to a folder, then proceed to the next file, check if that file is created within say.. 5 min. If so, move it to the same folder and check the following file. If not go to next file, create a new folder, move it there and check the following file.

There must be a better/smarter way. One that could detect a pattern based on the files as a whole and sort them accordingly.

EDIT: I want to continuously find files create at roughly the same time.

Lohardt
  • 1,027
  • 1
  • 12
  • 26
  • 2
    Dream up about 10 filenames that would cover the cases you anticipate. Edit them into the Q using 4 spaces at the front of each line. Now copy those names and show the sorting and grouping you expect and paste those into your Q. We can only work on facts and evidence. Good luck. – shellter Jan 15 '18 at 21:33
  • 1
    http://mywiki.wooledge.org/UsingFind#Searching_based_on_times – M. Becerra Jan 15 '18 at 21:34
  • https://stackoverflow.com/questions/14842195/how-to-get-file-creation-date-time-in-bash-debian#answer-30109008 – M. Becerra Jan 15 '18 at 21:38
  • Not what I'm looking for. You're are assuming that i have a specific timeframe to search for. I want to continuously find files create at roughly the same time. – Lohardt Jan 24 '18 at 12:10

1 Answers1

0

If i understood the task correctly...For example:

$ ls -l
-rw-rw-r-- 1 vkd vkd 0 янв 16 13:15 file1
-rw-rw-r-- 1 vkd vkd 0 янв 16 13:15 file2
-rw-rw-r-- 1 vkd vkd 0 янв 16 13:15 file3
-rw-rw-r-- 1 vkd vkd 0 янв 16 13:15 file4
-rw-rw-r-- 1 vkd vkd 0 янв 16 13:15 file5

Try to use ls with options --full-time, -t:

$ ls --full-time -t
total 0
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:06.697332260 +0600 file5
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:05.609343871 +0600 file4
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:04.737353175 +0600 file3
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:03.557365763 +0600 file2
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:02.601375961 +0600 file1

reverse:

ls --full-time -t -r
total 0
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:02.601375961 +0600 file1
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:03.557365763 +0600 file2
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:04.737353175 +0600 file3
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:05.609343871 +0600 file4
-rw-rw-r-- 1 vkd vkd 0 2018-01-16 13:15:06.697332260 +0600 file5
Konstantin Vustin
  • 3,506
  • 2
  • 10
  • 26
  • Not what I'm looking for. I want to group files based on the interval of their creation or modify date. For instance: Find chunks of files create max 5min apart. – Lohardt Jan 20 '18 at 23:20
  • `ls` provides no grouping capabilities on its own, but `find` does. – David C. Rankin Jan 21 '18 at 00:04
  • @DavidC.Rankin could you provide an example. I could find a reference. -group refers to user groups. – Lohardt Jan 24 '18 at 12:15
  • @Lohardt To find files between any given interval of time you can use `find /path -type f -newermt 2014-01-01 ! -newermt 2015-01-01` (example for a year) where files are newer than the first date (bast on the *modification time* `.....mt` including the time down to the second) and `'!'` (not) newer than the second. You can generate the rage with, e.g. `date -d "+ 5 minutes" "+%F %T"` if you want 5 minute blocks. – David C. Rankin Jan 24 '18 at 18:40