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 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.