Created
February 7, 2018 00:26
-
-
Save DreamerKlim/f0e182f690c3a226aa2422a2f7bac30e to your computer and use it in GitHub Desktop.
Bash скрипт для удаления старых файлов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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