Skip to content

Instantly share code, notes, and snippets.

@thehandsomezebra
Created January 14, 2022 02:02
Show Gist options
  • Save thehandsomezebra/2e4c3ced979116a3e24641d3e1dcd027 to your computer and use it in GitHub Desktop.
Save thehandsomezebra/2e4c3ced979116a3e24641d3e1dcd027 to your computer and use it in GitHub Desktop.
Rename files that have spaces - change to underscores
#!/bin/bash
for f in *; do
new="${f// /_}"
if [ "$new" != "$f" ]; then
if [ -e "$new" ]; then
echo not renaming "$f" because "$new" already exists
else
echo moving "$f" to "$new"
mv "$f" "$new"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment