Reputation: 65
I want to list the last 1 hour files which has .sh
extension.
I am currently using the following:
ls -l *.sh | find "/root/" -mmin -60 | awk '{print $9}'
However this command isn't working as expected.
Can anyone help me? Thank you in advance.
Upvotes: 2
Views: 57
Reputation: 36259
Did you mean:
find . -name "*.sh" -mmin -60 -ls | awk '{print $9}'
1
1
The $9 then gives me the day of month.
A similar result is possible, purely by gnu-find:
find . -name "*.sh" -mmin -60 -printf "%Ad\n"
01
01
except for the leading zeros. There are 3 dates possible:
%Ak File's last access time in the format specified by k, which is either `@' or a directive for the C `strftime' function. The possible values for k
are listed below; some of them might not be available on all systems, due to differences in `strftime' between systems.
%Ck File's last status change time in the format specified by k, which is the same as for %A.
%Tk File's last modification time in the format specified by k, which is the same as for %A.
(from the manpage of gnu-find).
Upvotes: 1
Reputation: 12456
You can just use a find
command to do this:
find <DIR> -type f -name '*.sh' -mmin -60
or
find <DIR> -type f -name '*.sh' -mmin -60 -executable
Explanations:
<DIR>
is the target directory where you want to search-type f
to force to look for files-name '*.sh'
to look for files with the sh extension-mmin -60
to look for files that have been modified in less than 1 hour-executable
if you want to add the constraint that the file have execution permission.-maxdepth 1
to look only for files in folder or use a higher depth if you want to look until N levels. You command becomes: find <DIR> -maxdepth 1 -type f -name '*.sh' -mmin -60 -executable
Upvotes: 2