Инструменты пользователя

Инструменты сайта


os:linux:utils

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слеваПредыдущая версия
Следующая версия
Предыдущая версия
os:linux:utils [19.08.2024 07:49] – [logrotate] viacheslavos:linux:utils [18.03.2025 19:48] (текущий) – [read] viacheslav
Строка 311: Строка 311:
 # Отключить ошибки, в основном Permission denied # Отключить ошибки, в основном Permission denied
 find / -name 'ddd' 2> /dev/null find / -name 'ddd' 2> /dev/null
 +# Удалить файлы business-* старше 14 дней в каталогах business-*
 +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]]
Строка 326: Строка 333:
 https://stackoverflow.com/questions/16956810/how-to-find-all-files-containing-a-specific-text-string-on-linux https://stackoverflow.com/questions/16956810/how-to-find-all-files-containing-a-specific-text-string-on-linux
  
 +===== gzip =====
 +pigz - многопоточный gzip. Умеет также работать с zip и zlib (.zz).
 +<code bash>
 +# Не удалять оригинал, максимальное сжатие, использовать 4 потока
 +pigz -k -9 -p4 archlinux.iso
 +# Показать содержимое архива
 +pigz -l archlinux.iso.gz
 +# Сжать в zip
 +pigz -k -K archlinux.iso
 +# Сжатие каталогов, 2 варианта (-I = --use-compress-program=)
 +tar cf - Pictures/ | pigz > pictures.tar.gz
 +tar -I pigz -cf yourfile.tar.gz folder1 folder2
 +# Распаковать
 +pigz -d archlinux.iso.gz
 +</code>
 +https://ostechnix.com/pigz-compress-and-decompress-files-in-parallel-in-linux/
 ===== hdparm ===== ===== hdparm =====
 hdparm - get/set hard disk parameters hdparm - get/set hard disk parameters
Строка 530: Строка 553:
 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>
  
Строка 538: Строка 576:
 # если без звёздочки (или без /), то будет скопирован сам каталог conf.d как подпапка # если без звёздочки (или без /), то будет скопирован сам каталог conf.d как подпапка
 rsync --info=progress2 --recursive user@10.1.0.9:/etc/apache2/conf.d/* /etc/apache2/conf.d rsync --info=progress2 --recursive user@10.1.0.9:/etc/apache2/conf.d/* /etc/apache2/conf.d
 +
 +# -a - "делать копию максимально идентичной" (разрешения, владелец, время и т. д.), также "обновляй файлы только когда надо"
 +# -c - считать контрольные суммы. Большие файлы бьются на куски, и суммы считаются для кусков.
 +# -P - прогресс
 +rsync -a -c -P <source> <dest>
 +
 +# --ignore-existing - если имя файла есть в <dest>, не копировать (больше ничего не проверяется)
 +# -u - "если два файла различны, обновлять только если у файла в <source> новее дата изменения"
 +rsync -a -P -u --ignore-existing <source> <dest>
 </code> </code>
 https://linux.die.net/man/1/rsync\\ https://linux.die.net/man/1/rsync\\
-https://www.servers.ru/knowledge/linux-administration/how-to-copy-files-between-linux-servers-using-rsync+https://www.servers.ru/knowledge/linux-administration/how-to-copy-files-between-linux-servers-using-rsync\\ 
 +https://stackoverflow.com/questions/40024222/copy-with-rsync-when-files-are-different 
  
 ===== sed ===== ===== sed =====
os/linux/utils.1724053777.txt.gz · Последнее изменение: 19.08.2024 07:49 — viacheslav

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki