Skip to content

Instantly share code, notes, and snippets.

@umkl
Created November 19, 2023 09:43
Show Gist options
  • Save umkl/3a224bd98c39aa73dcd3be751b6a8302 to your computer and use it in GitHub Desktop.
Save umkl/3a224bd98c39aa73dcd3be751b6a8302 to your computer and use it in GitHub Desktop.
bash_script to remove filename prefixes
#!/bin/bash
# Check if the prefix is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <prefix>"
exit 1
fi
# Get the prefix from the command line argument
prefix="$1"
# Rename files by removing the specified prefix
for file in "${prefix}"*; do
new_name="${file#${prefix}}"
mv "$file" "$new_name"
echo "Renamed: $file to $new_name"
done
echo "Script executed successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment