0

Following is a basic output of ls -ltrh (in Solaris):

-rw--r--r-- 57 oracle  dba   1.9K Jan 18 14:38 file001.log
-rw--r--r-- 30 oracle  dba   1.0K Jan 18 14:41 file002.log
-rw--r--r--  8 oracle  dba   272B Jan 18 15:33 file003.log
-rw--r--r--  8 oracle  dba   272B Jan 18 15:35 file004.log

The application output for time is always in the following format (can not be changed), based on which I need to select the files >= date:

01/18/2016 14:41

In the above case, I need all files from Jan 18, with timestamp of 14:41 and newer.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
orionb
  • 9
  • 3
  • [Please also post your attempt to solve this](http://stackoverflow.com/help/mcve). Your question should include your own code, your expect results, along with your actual results or any errors that were produced when you tried to run your code. – ghoti Jan 18 '16 at 21:43
  • Parsing `ls` is [not considered](http://mywiki.wooledge.org/ParsingLs) a good idea. – dawg Jan 18 '16 at 22:20

2 Answers2

2

After cutting/ sed / whatever, transform the date 01/18/2016 14:41 into 201601181441.00. Now create a tmp file with that timestamp and look for newer files:

touch -t 201601181441.00 /tmp/olddate
find . -newer /tmp/olddate -print
rm -f /tmp/olddate
Walter A
  • 19,067
  • 2
  • 23
  • 43
1

I'd use a different approach here- instead of using ls and parsing the output, you can use unix find command.

for example, this will give you files modified in the past week:

find . -mtime -7 

you can also use -newer flag to get all files newer than some specific file (and then use the trick shown on the second answer here to get newer than specific date)

Community
  • 1
  • 1
Nir Levy
  • 12,750
  • 3
  • 21
  • 38
  • Thanks Nir. However, my challenge remains of converting the search based on the date/time output shown above. Also, this is Solaris. – orionb Jan 18 '16 at 20:56