Lowercase files: Difference between revisions

From Freephile Wiki
No edit summary
 
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight"
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<pre>
<nowiki>


Simple bash approach. But this script will clobber files when there is a collision: e.g. What if you have John jOhn JOHN john joHN?
You could do the same with the '''rename''' command, which does account for collisions.  See <code>man rename(1)</code>
<syntaxhighlight lang="bash">
#! /bin/bash
#! /bin/bash
#
#
Line 24: Line 27:
exit 0
exit 0


</nowiki>
</syntaxhighlight>
</pre>
 
[[Category:Filesystems]]
[[Category:Files]]

Latest revision as of 13:29, 24 February 2025

Simple bash approach. But this script will clobber files when there is a collision: e.g. What if you have John jOhn JOHN john joHN?

You could do the same with the rename command, which does account for collisions. See man rename(1)

#! /bin/bash
#
# Changes every filename in working directory to all lowercase.
#
# Inspired by a script of john dubois,
# which was translated into into bash by Chet Ramey,
# and considerably simplified by Mendel Cooper,
# author of this HOWTO.


for filename in *  #Traverse all files in directory.
do
   fname=`basename $filename`
   n=`echo $fname | tr A-Z a-z`  #Change name to lowercase.
   if [ $fname != $n ]  # Rename only files not already lowercase.
   then
     mv $fname $n
   fi  
done   

exit 0