Skip to content

Instantly share code, notes, and snippets.

@imjared
Last active December 24, 2015 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imjared/6716780 to your computer and use it in GitHub Desktop.
Save imjared/6716780 to your computer and use it in GitHub Desktop.
if you get a bunch of files that have an undesirable prefix and you want to remove it, just tell this script the prefix
#!/bin/bash
# takes an argument of an undesired prefix then removes it from all files in dir
# if no arg is passed, prompt for name
if [ $# -eq 0 ]
then
read -p 'What prefix do you want to remove?: '
prefix=$REPLY
else
prefix=$1
fi
length=${#prefix}
removeLength=$(($length + 1))
for name in $prefix*
do
newname="$(echo "$name" | cut -b$removeLength-)"
mv "$name" "$newname"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment