-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename_commands.sh
67 lines (40 loc) · 1.98 KB
/
rename_commands.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
####################### Remove single quotes from filenames & folders (recursively -- not verbose): #####################
Dry Run:
for file in * ; do echo ${file}| sed -e "s/ / /g" -e "s/[\[{\\']//g" ; done
Rename command:
for file in * ; do mv ${file}|sed -e "s/ / /g" -e "s/[\[{\\']//g" ; done
############### REMOVE '' QUOTES - RENAME FILES & FOLDERS (RECURSIVELY to replace period & space with underscore - e.g. 1. Filename = 1_Filename --- verbose ) ######################
Dry Run:
for file in *; do dest="${file//[[:space:]]/_}" && echo "$file = ${dest//[^[:alnum:]._ ]/}"; done
Rename command:
for file in *; do dest="${file//[[:space:]]/_}" && mv -i "$file" "${dest//[^[:alnum:]._-]/}"; done
Note: If files/folders have '' in the names then run the remove single quote command above first)
###################### Match FILES ONLY that start with "1. Filename" & RECURSIVELY to replace period & space with underscore - e.g. 1. Filename = 1_Filename --- verbose ) ######################
Dry Run:
set -- *.*
for file; do
echo "$file == ${file//. /_}"
done
Rename cmd:
#!/bin/bash
set -- *.*
for file; do
mv -- "$file" "${file//. /_}"
done
############################### rename folders by removing everything before the first _ characater ########################
Dry Run:
rename -n 's/[^_]*[_]//' *
Rename cmd:
rename 's/[^_]*[_]//' *
################################REPLACE PERIOD IN WITH SPACE IN FOLDERS##############################################################
mv -- "$file = ${file//./ }"
##############################################################EPLACE PERIOD WITH SPACE IN FOLDERS (top level only): ################
for i in *.*; do
[ -d "$i" ] || continue
echo "$i == ${i//./ }"
done
############################################################## REPLACE PERIOD WITH SPACE IN FOLDERS (top level only) ################
dir=/home/rtorrent/radarr
while IFS= read -r -d '' dir; do
echo "$dir = ${dir//./ }"
done < <(find . -maxdepth 1 -type d -name '*.*' -print0)