Let’s say you’re in /var/log and you want to find the last modified file. You’d type ls -lrt but this is not sufficient to find out which logfile was modified last, because that logifle might be hidden somewhere in a subdirectory. How do you find it easily ?
The following Bash code will help you out:
# find . -type f -exec stat --format '%Y :%y %n' {} \; | sort -nr | cut -d: -f2- | head
Put it in a function in your custom environment:
# Find the last modified file recursively
function lrtr
{
find "$@" -type f -exec stat --format '%Y :%y %n' {} \; | sort -nr | cut -d: -f2- | head
}
function lrtr
{
find "$@" -type f -exec stat --format '%Y :%y %n' {} \; | sort -nr | cut -d: -f2- | head
}
and just type:
$ lrtr
This command does a sort, which means that it can take a long time to execute if the directories you’re searching are very deep.
Laisser un commentaire
Participez-vous à la discussion?N'hésitez pas à contribuer!