A
A. Farber
Hi,
I need to lowercase all files and directories in the current
directory on Linux and have come up with the following script:
bolinux72:bin {74} cat lowercase.sh
#!/bin/sh
# Lowercase the files and sub-directores in the current directory
# BUGS: does not escape quotes, backslashes and dollars in path names
# Note: for Unix change -print0 to -print, -n0e to -ne, mv -v to mv
find . -depth -print0 | perl -n0e '
$old = $_;
s,([^/]+)$,\L$1,;
next if $old eq $_;
die qq{Can not move "$old" to "$_"\n} if -e;
print qq{mv -v "$old" "$_"\n}' | sh
And 1 line more for the same task, but with uppercased first letter:
bolinux72:bin {75} cat upfirst.sh
#!/bin/sh
# Uppercase the first letter and lowercase the rest for
# all files and sub-directores in the current directory
find . -depth -print0 | perl -n0e '
$old = $_;
s,([^/]+)$,\L$1,;
s,([^/]+)$,\u$1,;
next if $old eq $_;
die qq{Can not move "$old" to "$_"\n} if -e;
print qq{mv -v "$old" "$_"\n}' | sh
I wonder, if someone has a nicer solution and what
would be the best way to handle funny path names?
Regards
Alex
I need to lowercase all files and directories in the current
directory on Linux and have come up with the following script:
bolinux72:bin {74} cat lowercase.sh
#!/bin/sh
# Lowercase the files and sub-directores in the current directory
# BUGS: does not escape quotes, backslashes and dollars in path names
# Note: for Unix change -print0 to -print, -n0e to -ne, mv -v to mv
find . -depth -print0 | perl -n0e '
$old = $_;
s,([^/]+)$,\L$1,;
next if $old eq $_;
die qq{Can not move "$old" to "$_"\n} if -e;
print qq{mv -v "$old" "$_"\n}' | sh
And 1 line more for the same task, but with uppercased first letter:
bolinux72:bin {75} cat upfirst.sh
#!/bin/sh
# Uppercase the first letter and lowercase the rest for
# all files and sub-directores in the current directory
find . -depth -print0 | perl -n0e '
$old = $_;
s,([^/]+)$,\L$1,;
s,([^/]+)$,\u$1,;
next if $old eq $_;
die qq{Can not move "$old" to "$_"\n} if -e;
print qq{mv -v "$old" "$_"\n}' | sh
I wonder, if someone has a nicer solution and what
would be the best way to handle funny path names?
Regards
Alex