I have been told never to parse ls, but I would like to use the last edited directory in myDir as a variable in my bash script. I know I could capture this via ls -ltr myDir | tail -n1 | awk '{print $NF}' but this parses ls. Is there a 'best way' to find the last edited directory inside of myDir?
Asked
Active
Viewed 76 times
0
drjrm3
- 1,476
- 6
- 26
- 44
-
Possible duplicate of [Unix/Linux find and sort by date modified](http://superuser.com/questions/294161/unix-linux-find-and-sort-by-date-modified). There are a number of non-ls ways listed to sort directories there, and you need only use `head` or `tail` to grab the first or last one. – Darth Android Feb 25 '16 at 22:52
1 Answers
0
you can use something like this:
find /target_directory -type f -mtime -2
this will search for all files that have been modified in the target_directory and the sub_directory in the last 2 days.
Jay T.
- 211
- 1
- 6