📄 lowercase.sh
字号:
#!/bin/bash## Changes every filename in working directory to all lowercase.## Inspired by a script of John Dubois,#+ which was translated into Bash by Chet Ramey,#+ and considerably simplified by the author of the ABS Guide.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 $?# Code below this line will not execute because of "exit".#--------------------------------------------------------## To run it, delete script above line.# The above script will not work on filenames containing blanks or newlines.# Stephane Chazelas therefore suggests the following alternative:for filename in * # Not necessary to use basename, # since "*" won't return any file containing "/".do n=`echo "$filename/" | tr '[:upper:]' '[:lower:]'`# POSIX char set notation.# Slash added so that trailing newlines are not# removed by command substitution. # Variable substitution: n=${n%/} # Removes trailing slash, added above, from filename. [[ $filename == $n ]] || mv "$filename" "$n" # Checks if filename already lowercase.doneexit $?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -