Is there a way on Linux bash to highlight all files modified in last N mins of current path

Viewed 100

I see a lot of similar questions, but answers of those questions don't quite meet my needs. The most common answer is to use command like find . -mmin -60 -maxdepth 1. But this command only outputs matched files, the thing I want is to output all files like what ls -al does, and highlight (like different color) all files which are modified in last N minutes. I don't know if it is possible to combine find and grep to achieve this goal, thank you for your help in advance!!

1 Answers

Assuming your version of find supports the printf action and you would like to highlight with, e.g., a leading ***, the following should work:

find . -maxdepth 1 -mmin -60 -printf '*** %p\n' -o -print

If you prefer colors, and if your terminal supports it, you can use ANSI escape codes. Example for green:

find . -maxdepth 1 -mmin -60 -printf '\033[32m%p\033[0m\n' -o -print

Explanations:

If the file or directory was modified less than 60 minutes ago it is the printf action that will we executed, else it is the print action.

By default find tests and actions are combined with logical AND. -o is the logical OR. It has lower precedence than AND. Here find stops as soon as one of two ORed terms evaluates as true.

Related