Предыдущая версия справа и слеваПредыдущая версияСледующая версия | Предыдущая версия |
os:linux:utils [04.10.2024 06:46] – [find] viacheslav | os:linux:utils [18.03.2025 19:48] (текущий) – [read] viacheslav |
---|
# Удалить файлы business-* старше 14 дней в каталогах business-* | # Удалить файлы business-* старше 14 дней в каталогах business-* |
find "/opt/app/business-*" -name "business-*" -type f -mtime +14 -delete | find "/opt/app/business-*" -name "business-*" -type f -mtime +14 -delete |
| # Создать подкаталог old, заархивировать файлы (нерекурсивно) старше вчерашнего дня, удалить оригиналы, удалить архивы старше 30 дней |
| mkdir -p /opt/archive/jfr/old |
| find /opt/archive/jfr -maxdepth 1 -daystart -mtime +1 -type f | \ |
| xargs tar czf /opt/archive/jfr/old/$(date -d '-2 day' +%F-%s).tar.gz --remove-files && \ |
| find /opt/archive/jfr/old -mtime +30 -delete |
</code> | </code> |
The command termination ''+'' instead of ''\;'' highly optimizes the exec clause by not running the rm command for each file present on the file system. It is more ubiquitous, being specified by POSIX. ''-delete'' is from FreeBSD from 1996, not added to GNU find until 2004, ''-exec cmd {} +'' is from SysV in 80s, standardised by POSIX in 1992, added to GNU ''find'' in 2005. [[https://unix.stackexchange.com/questions/167823/finds-exec-rm-vs-delete]] | The command termination ''+'' instead of ''\;'' highly optimizes the exec clause by not running the rm command for each file present on the file system. It is more ubiquitous, being specified by POSIX. ''-delete'' is from FreeBSD from 1996, not added to GNU find until 2004, ''-exec cmd {} +'' is from SysV in 80s, standardised by POSIX in 1992, added to GNU ''find'' in 2005. [[https://unix.stackexchange.com/questions/167823/finds-exec-rm-vs-delete]] |
echo "$server" | echo "$server" |
srv-mail1 | srv-mail1 |
| |
| # Разделить строку на 2 части |
| $ i="v2.2.187 3826893 Very important commit, absolutely brilliant" |
| $ read -r tag description <<< $i |
| $ echo $tag |
| v2.2.187 |
| $ echo $description |
| 3826893 Very important commit, absolutely brilliant |
| </code> |
| [[https://stackoverflow.com/questions/10520623/how-to-split-one-string-into-multiple-variables-in-bash-shell|How to split one string into multiple variables in bash shell]] |
| ===== rm ===== |
| remove files or directories |
| <code bash> |
| # Удалить всё, в т. ч. файлы с точками в начале имени |
| rm -rf -- ..?* .[!.]* * |
</code> | </code> |
| |