Skip to content

Instantly share code, notes, and snippets.

@aks
Created March 16, 2018 15:02
Show Gist options
  • Select an option

  • Save aks/5f6f1226ef16c1460d9b32e9f5ac7400 to your computer and use it in GitHub Desktop.

Select an option

Save aks/5f6f1226ef16c1460d9b32e9f5ac7400 to your computer and use it in GitHub Desktop.
Bash script to zero out all the log files in `~/log`. Useful for Rails apps.
#!/usr/bin/env bash
if [[ -d log ]] ; then
set -- log
while (( $# > 0 )) ; do
file="$1"
shift
if [[ -f $file && -s $file ]] ; then
case "$file" in
*.log|*.txt|*.lst)
echo " $file"
cat /dev/null >$file
;;
esac
elif [[ -d $file ]]; then
set -- "$@" $file/*
fi
done
else
echo "No log directory"
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment