Get in touch!Get in touch!

Rename Multiple Files

This script renames several files by

    removing a specified number of characters at the beginning,
    adding a suffix,
    adding a prefix.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
###############################################################
# This script renames several files by 
    #1. removing a specified number of chars at the beginning, 
    #2. adding a suffix, 
    #3. adding a prefix
# The script was first written to solve the problem of  
# renaming some pdf files that were plotted from 
# AutoCAD Civil 3D.
# The original files were in the form
    # 1 1011.pdf
# I wanted them to be named in the following manner:
    # 1302-NWP.CH-1011-T-00.pdf
###############################################################
# @author Victor Miti <[email protected]>
# @date 2014-July-17
###############################################################
 
#Step 1: we first remove the first two leading chars in the filenames
#adapted from http://community.linuxmint.com/tutorial/view/1162
 
for file in *pdf;
    do mv "$file" "${file:2}";
done
 
###############################################################
 
#Step 2: we append a string to each filename
#adapted from http://unix.stackexchange.com/questions/56810/adding-text-to-filename-before-extension
 
for f in *.pdf; 
    do mv "$f" "${f%.pdf}-T-00.pdf"; 
done
 
###############################################################
 
#Step 3: we add a string at the beginning of each filename
for i in *.pdf; 
    do mv $i 1302-NWP.ZA-$i; 
done
#!/bin/sh
###############################################################
# This script renames several files by 
	#1. removing a specified number of chars at the beginning, 
	#2. adding a suffix, 
	#3. adding a prefix
# The script was first written to solve the problem of  
# renaming some pdf files that were plotted from 
# AutoCAD Civil 3D.
# The original files were in the form
	# 1 1011.pdf
# I wanted them to be named in the following manner:
	# 1302-NWP.CH-1011-T-00.pdf
###############################################################
# @author Victor Miti <[email protected]>
# @date 2014-July-17
###############################################################

#Step 1: we first remove the first two leading chars in the filenames
#adapted from http://community.linuxmint.com/tutorial/view/1162

for file in *pdf;
	do mv "$file" "${file:2}";
done

###############################################################

#Step 2: we append a string to each filename
#adapted from http://unix.stackexchange.com/questions/56810/adding-text-to-filename-before-extension

for f in *.pdf; 
	do mv "$f" "${f%.pdf}-T-00.pdf"; 
done

###############################################################

#Step 3: we add a string at the beginning of each filename
for i in *.pdf; 
	do mv $i 1302-NWP.ZA-$i; 
done


Comments are closed.