KVM VPS - как найти последние изменнные файлы в папке рекурсивно и отсортировать их по дате (how to recursively find the latest modified file in a directory)

Материал из Wiki - Iphoster - the best ever hosting and support. 2005 - 2023
Перейти к:навигация, поиск
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Доступная цена

KVM VPS - как найти последние изменнные файлы в папке рекурсивно и отсортировать их по дате (how to recursively find the latest modified file in a directory)

Поиск последних измененных файлов в директории рекурсивно и сортировка их по дате изменения сверху вниз:

#  find . -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2-

тоже самое только с сохранением в файл:

# find . -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- > files_last_mod.txt

вывести только последние 100 измененные файлы и отсортировать их по дате (применяем head -n число строк):

# find . -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head -n 100


Более медленный вариант команды:

# find . -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2-


Результат будет в ввиде списка

2020-06-17 14:06:58.643640273 +0200 ./system/storage/cache/cache.catalog.language.1592399218
2020-06-17 14:06:55.210586877 +0200 ./admin/view/stylesheet/bootstrap.css
2020-06-17 13:51:14.605921777 +0200 ./system/storage/cache/cache.manufacturer.0.1592398274
2020-06-17 13:32:35.449481096 +0200 ./av.php
2020-06-17 13:29:13.011329064 +0200 ./files_last_mod.txt
2020-06-17 13:28:00.299197148 +0200 ./admin/index.php
2020-06-17 13:22:50.164369251 +0200 ./index.php
2020-06-17 13:17:29.583378738 +0200 ./system/storage/cache/cache.currency.1592396249
2020-06-17 13:17:23.400282485 +0200 ./system/storage/cache/cache.store.1592396243