Skip to content

Instantly share code, notes, and snippets.

@shaoyanji
Created November 11, 2024 17:12
Show Gist options
  • Save shaoyanji/3e7f98e32a2b4306dcc0cca51f8214c2 to your computer and use it in GitHub Desktop.
Save shaoyanji/3e7f98e32a2b4306dcc0cca51f8214c2 to your computer and use it in GitHub Desktop.
removes spaces in filenames when run in a folder for pandoc parsing and other automated tasks
#!/usr/bin/env bash
find . -depth -name '* *' | while read fname; do
new_fname=$(echo $fname | tr " " "_")
if [ -e $new_fname ]; then
echo "File $new_fname already exists. Not replacing $fname"
else
echo "Creating new file $new_fname to replace $fname"
mv "$fname" $new_fname
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment