-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaimin.sh
More file actions
28 lines (26 loc) · 787 Bytes
/
maimin.sh
File metadata and controls
28 lines (26 loc) · 787 Bytes
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
#!/bin/sh
# Transforma arquivos com nomes em MAIUSCULAS para minusculas
#
# Testando se vc passou o diretorio como parametro
# default = diretorio corrente.
if [ $# -eq 1 ]
then
Dir=$1
else
Dir="."
fi
cd $Dir
for ArqMai in `ls | grep '^[A-Z].*$'`
do
# Da forma que eu coloquei acima todos os arquivos
# cujos nomes fossem formados somente por maiusculas.
# Se vc quiser carac especiais tb, como _ ou . fa(ss)a:
# for ArqMai in `ls | grep '^[^a-z].*$'`
ArqMin=`echo $ArqMai | tr "[A-Z]" "[a-z]"`
if [ -f "$ArqMin" ] #Existe minusculo?
then
# listando os 2 em ordem cronologica (-t) e
# pegando o + novo (head -1). Se for o Maiusculo...
[ `ls -t $ArqMai $ArqMin | head -1` -eq $ArqMai ] && mv -f $ArqMai $ArqMin
fi
done