Skip to content

Instantly share code, notes, and snippets.

@DreamerKlim
Created February 7, 2018 00:26
Show Gist options
  • Save DreamerKlim/f0e182f690c3a226aa2422a2f7bac30e to your computer and use it in GitHub Desktop.
Save DreamerKlim/f0e182f690c3a226aa2422a2f7bac30e to your computer and use it in GitHub Desktop.
Bash скрипт для удаления старых файлов
#!/bin/bash
#Проверяем количество входных параметров
if [ $# -lt 3 ]
then
echo Something wrong with parameters
exit
fi
x=1 # Счетчик файлов
path=$1 # Путь к удаляемым файлам
filemask=$2 # маска файлов
keep=$3 # сколько файлов (бэкапов) надо оставлять
for i in `ls -t $path/$filemask`
do
if [ $x -le $keep ]
then
((x++))
continue
fi
rm $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment