#!/bin/sh initialPath=$(pwd) find . -type f -name '*.doc*' | sed -r 's|/[^/]+$||' | sort -u | while read dir; do cd "$dir" find . -type f -name '*.doc*' | while read file; do soffice --headless --convert-to pdf "$file" echo "$file" | sed -e 's|^\./||' | sed 's/docx?/pdf/' | tee -a contents done cd "$initialPath" done