Bash: rsync с проверкой файла
Краткое решение
<WRAP center round box 60%> #!/bin/bash #if file copy new fils dir write to raed folder and remove fils if no exit DIR='/home/samba/total/' filecount=`find $DIR | wc -l` if [ $filecount -eq 1 ]; then exit else rsync -a /home/samba/total/ /home/samba/script/ rm -rf /home/samba/total/ fi </WRAP> перем…
#!/bin/bash
#if file copy new fils dir write to raed folder and remove fils if no exit
DIR='/home/samba/total/'
filecount=find $DIR | wc -l
if [ $filecount -eq 1 ];
then
exit
else
rsync -a /home/samba/total/* /home/samba/script/
rm -rf /home/samba/total/*
fi
переменная обработки команд
Ищет файлы в папке и подсчитывает количество
filecount=find $DIR | wc -l
Если файл или папка нет выйдим если есть синхронизируем и удаляет из источника
if [ $filecount -eq 1 ];
then
exit
else
rsync -a /home/samba/total/* /home/samba/script/
rm -rf /home/samba/total/*
fi
Ищет больше 1 файла так как 1 будет сама папка..
if [ $filecount -eq 1 ];
Обновлено: 01.07.2026 · импорт из Linux-l Wiki