среда, 14 июня 2023 г.

Linux Bash remove old files more than 10 if exists

if [ $(expr $(ls -1 /test/111 | wc -l | tr -d ' ')) -gt 10 ]; then rm $(ls -d -1 -At /test/111/* | tail -n $(expr $(ls -1 /test/111 | wc -l | tr -d ' ') - 10)) ; fi 

to crontab

/bin/bash -c "if [ $(expr $(ls -1 /test/111 | wc -l | tr -d ' ')) -gt 10 ]; then rm $(ls -d -1 -At /test/111/* | tail -n $(expr $(ls -1 /test/111 | wc -l | tr -d ' ') - 10)) ; fi"

среда, 24 мая 2023 г.

Linux Bash rsync only specific a files list

Check rsync --help whether it supports --files-from= option 

lst content

./folder-source/1/1

./folder-source/2/2

...

cd to a folder where folder-source as a sub-folder (it's an explanation of period "." in rsync command)

rsync --files-from=/tmp/lst . /app/var/folder-sync

четверг, 6 апреля 2023 г.

Linux Bash find multiple conditions and move files

remove only *.dat and *.csv files older than 4 moths 

find /path -type f -mtime +120 \( -name '*.dat' -or -name '*.csv' \) -exec rm '{}' ';'

or move the files, but please be aware if destination is wrong or some bad happens then you'll lose files 

find /path -type f -mtime +120 \( -name '*.dat' -or -name '*.csv' \) -exec mv '{}' /destination/ ';'