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
?
1 Answer
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.
head
ortail
to grab the first or last one.