# Process every .log file safely (handles spaces / newlines in names)
while IFS= read -r -d '' file; do
echo "processing: $file"
# gzip "$file"
done < <(find /var/log -type f -name "*.log" -print0)
# Same idea with a callback function
walk_files() {
local root="$1" pattern="$2" callback="$3"
while IFS= read -r -d '' f; do
"$callback" "$f"
done < <(find "$root" -type f -name "$pattern" -print0)
}
count_lines() { wc -l < "$1"; }
walk_files /var/log "*.log" count_lines
Create a free account and build your private vault. Share publicly whenever you want.