#!/bin/bash set -e function clean_dir { count=1 for file in $(ls -t) do if [ $count -gt 50 ] then ls -l $file else let "count++" fi done if [ $count -le 50 ] then # nothing to do exit fi echo "Dateien löschen (Y/n)?" read a if [ "$a" = "n" ] then exit 0 fi count=1 for file in $(ls -t) do if [ $count -gt 50 ] then rm -r $file else let "count++" fi done } cd ~/tmp clean_dir cd ~/aasync/Aktuell clean_dir