Last active
December 24, 2015 00:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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