/ Published in: Bash
Description:
This script will loop through all the files in a directory and rename them to match
the name contained inside of a text file. This makes it easy to bulk rename files
by working iteratively in a single text file, until it contains a list of the file
names you want.
Instructions:
1) cd into the directory that contains a list of all the files you want to rename.
2) Type: \ls -1 ../replace.txt
3) cd ..
4) Edit replace.txt but don't change the order of any lines.
5) ./bulk-renamer.sh [directory of files to rename] replace.txt
6) If you don't like the results, just delete replace.txt and start over with step 1
Additional Instructions:
If you are careful, you can also rename just a subset of files in a directory by modifying step 2 to include a wildcard filter to the files you want to rename such as: *.mp3 but you will also need to change the "for loop" below to use the same wildcard filter
Usage: ./bulk-renamer.sh [directory to CD into] [path/to/replace.txt]
This script will loop through all the files in a directory and rename them to match
the name contained inside of a text file. This makes it easy to bulk rename files
by working iteratively in a single text file, until it contains a list of the file
names you want.
Instructions:
1) cd into the directory that contains a list of all the files you want to rename.
2) Type: \ls -1 ../replace.txt
3) cd ..
4) Edit replace.txt but don't change the order of any lines.
5) ./bulk-renamer.sh [directory of files to rename] replace.txt
6) If you don't like the results, just delete replace.txt and start over with step 1
Additional Instructions:
If you are careful, you can also rename just a subset of files in a directory by modifying step 2 to include a wildcard filter to the files you want to rename such as: *.mp3 but you will also need to change the "for loop" below to use the same wildcard filter
Usage: ./bulk-renamer.sh [directory to CD into] [path/to/replace.txt]
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/bin/bash # Title: # Bulk Renamer # Author: # By Dean Householder # 3/7/2014 # Description: # This script will loop through all the files in a directory and rename them to match # the name contained inside of a text file. This makes it easy to bulk rename files # by working iteratively in a single text file, until it contains a list of the file # names you want. # Instructions: # 1) cd into the directory that contains a list of all the files you want to rename. # 2) Type: \ls -1 ../replace.txt # 3) cd .. # 4) Edit replace.txt but don't change the order of any lines. # 5) ./bulk-renamer.sh [directory of files to rename] replace.txt # 6) If you don't like the results, just delete replace.txt and start over with step 1 # Additional Instructions: # If you are careful, you can also rename just a subset of files in a directory # by modifying step 2 to include a wildcard filter to the files you want to rename # such as: *.mp3 # but you will also need to change the "for loop" below to use the same wildcard filter # Usage: ./bulk-renamer.sh [directory to CD into] [path/to/replace.txt] if [ -z "$1" ]; then echo "Usage: `basename $0` [dirname] [replace.txt]" echo -e "\nYou can view additional instructions inside the script source.\n" exit 1 fi cd "$1" count=0 for filename in *; do count=$(($count+1)) replace=$(sed -n "$count,${count}p" "$2") mv "$filename" "$replace" done cd ..