-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathto_lowercase.sh
38 lines (31 loc) · 931 Bytes
/
to_lowercase.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
#!/bin/bash
# Rename all directories. This will need to be done first.
# Process each directorys contents before the directory itself
find * -depth -type d | while read x
do
# Translate Caps to Small letters
y=$(echo "$x" | tr '[A-Z ]' '[a-z_]');
# create directory if it does not exit
if [ ! -d "$y" ]; then
mkdir -p "$y";
fi
# check if the source and destination is the same
if [ "$x" != "$y" ]; then
# move directory files before deleting
ls -A "$x" | while read i
do
mv "$x"/"$i" "$y";
done
rmdir "$x";
fi
done
# Rename all files
find * -type f | while read x ;
do
# Translate Caps to Small letters
y=$(echo "$x" | tr '[A-Z ]' '[a-z_]');
if [ "$x" != "$y" ]; then
mv "$x" "$y";
fi
done
exit 0