📄 444.html
字号:
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colSpan=5>
<DIV align=right><FONT class=normalfont>当前位置:
<A href="index.html" tppabs="http://www.linuxhero.com/docs/index.html">本站首页</A>
<font color="#FF6699">>></font>
<A href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</A> | <A href="copyright.html" tppabs="http://www.linuxhero.com/docs/copyright.html">版权说明</A></font></DIV>
</TD>
<TD><IMG height=22 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1
border=0></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=10 cellPadding=0 width="100%" bgColor=#ffffff
border=0>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%" border=0>
<TR>
<TD vAlign=top align=middle width="60%">
<TABLE cellSpacing=0 cellPadding=0 width="100%"
background="images/back.gif" tppabs="http://www.linuxhero.com/docs/images/back.gif" border=0>
<TBODY>
<TR>
<TD vAlign=top width="80%">
<DIV align=center>
<FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
</FORM>
<TABLE cellSpacing=0 cellPadding=0 width="95%"
border=0><TBODY>
<TR>
<TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif"
height=30></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=3 width="95%"
align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%"
border=0>
<TBODY>
<TR>
<TD vAlign=top>
<p><FONT class=normalfont><B><font color=blue>很方便的两个shell script</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:作者<br>来自:Linux知识宝库<br>联系方式:无名<br><br>最近我把系统重作了一下,于是成了 WIN98 和 linux 共存的系统, 但工作久了,发现很不方便(在 WIN98 下的文件名都是大写,而 linux 下的文件名一般都是小写字符)。在使用 mcopy 的时候,拷过来的文件名都是大写的,很不方便 linux 操作!<br>
于是就写了两个shell脚本,这几天我用它们方便了许多操作,现在拿出来给双系统的朋友分享(我知道,像我这样用双系统的人很多哟! ;-) ),应该有人能用上它。 脚本很简单,不过在发此贴之前把它们包装了一下(这样看起来就像个系统命令了,呵呵)。不足的是,只能改当前的目录中的文件名(就是说,只可以:% upks2lowks * 或 % upks2lowks myfile, 而不能 % upks2lowks /mydir/myfile),其实后者也可以,不过会有错信息输出!<br>
<br>
脚本内容如下:<br>
<br>
#!/bin/sh<br>
<br>
# This Shell Script can change UPPER-CASE FILENAME to low-case filename.<br>
<br>
error=0;count=0<br>
number=$(echo * | /usr/bin/wc -w)<br>
<br>
if [ "$1" = "-h" -o "$1" = "--help" ]; then<br>
echo "Usage: upks2lowks [PATH] [FILENAME]..."<br>
echo "Description: Change "FILENAME" to "filename"!"<br>
echo ""<br>
echo " -h, --help display this info and exit"<br>
echo " -v, --version display version info and exit"<br>
echo ""<br>
echo "Report bugs to <sea___sky@sina.com>."<br>
echo "PS: I think U can modify it by nothing! It's just a shell script! ;-)"<br>
exit<br>
fi<br>
<br>
if [ "$1" = "-v" -o "$1" = "--version" ];then<br>
echo "A tool form my file-utils, no version info!"<br>
echo "(maybe ver0.0.0)?! (^o^)"<br>
echo "Written by Juner.L"<br>
echo ""<br>
echo "Copyright (C) Juner"<br>
echo "This is free software; see the source for copying conditions. There is NO"<br>
echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."<br>
exit<br>
fi<br>
<br>
if [ -z "$1" ]; then<br>
/usr/bin/printf "a"<br>
echo "Just put the "FILENAME" follow the command!"<br>
else<br>
for i in $*<br>
do<br>
if [ -e "$i" -a -w "$i" ]; then<br>
file=$(echo $i | /usr/bin/tr "[A-Z]" "[a-z]")<br>
if [ "$i" = "$file" ]; then<br>
echo "The file "$i" is already lowcased!"<br>
count=$(/usr/bin/expr 1 + $count)<br>
else<br>
echo "$i => $file"<br>
/bin/mv -f $i $file 2> /dev/null<br>
fi<br>
else<br>
echo "warning: file "$i" not exist OR you have no "w" right to file!"<br>
fi<br>
done<br>
if [ "$number" -eq "$count" ]; then<br>
echo " all file(s) is lowcased!"<br>
else<br>
echo " $count file(s) already lowcased!"<br>
fi<br>
fi<br>
<br>
还有一个和它差不多,只改了几个小地方,是把小写的文件名改成大写的,如下:<br>
<br>
#!/bin/sh<br>
<br>
# This Shell Script can change low-case filename to UPPER-CASE filename.<br>
<br>
error=0;count=0<br>
number=$(echo * | /usr/bin/wc -w)<br>
<br>
if [ "$1" = "-h" -o "$1" = "--help" ]; then<br>
echo "Usage: lowks2upks [path] [filename]..."<br>
echo "Description: Change "filename" to "FILENAME"!"<br>
echo ""<br>
echo " -h, --help display this info and exit"<br>
echo " -v, --version display version info and exit"<br>
echo ""<br>
echo "Report bugs to <sea___sky@sina.com>."<br>
echo "PS: I think U can modify it by nothing! It's just a shell script! ;-)"<br>
exit<br>
fi<br>
<br>
if [ "$1" = "-v" -o "$1" = "--version" ];then<br>
echo "A tool form my file-utils, no version info!"<br>
echo "(maybe ver0.0.0)?! (^o^)"<br>
echo "Written by Juner.L"<br>
echo ""<br>
echo "Copyright (C) Juner"<br>
echo "This is free software; see the source for copying conditions. There is NO"<br>
echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."<br>
exit<br>
fi<br>
<br>
if [ -z "$1" ]; then<br>
/usr/bin/printf "a"<br>
echo "Just put the "filename" follow the command!"<br>
else<br>
for i in $*<br>
do<br>
if [ -e "$i" -a -w "$i" ]; then<br>
file=$(echo $i | /usr/bin/tr "[a-z]" "[A-Z]")<br>
if [ "$i" = "$file" ]; then<br>
echo "THE FILE "$i" IS ALREADY UPPERCASED!"<br>
count=$(/usr/bin/expr 1 + $count)<br>
else<br>
echo "$i => $file"<br>
/bin/mv -f $i $file 2> /dev/null<br>
fi<br>
else<br>
echo "WARING: FILE "$i" NOT EXIST or YOU HAVE NO "w" RIGHT TO FILE!"<br>
fi<br>
done<br>
if [ "$number" -eq "$count" ]; then<br>
echo " ALL FILE(S) IS UPPERCASED!"<br>
else<br>
echo " $count FILE(S) ALREADY UPPERCASED!"<br>
fi<br>
fi<br>
<br>
完了!<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
经过进一步了解 gawk ,我已经把上面两个脚本优化了,改过后的脚本可以在任意目录下改任意目录(你有写权限的目录/文件)下的文件名,<br>
也就是说,可以在任意目录下<br>
% upks2lowks /home/juner/tmp/*<br>
而不必<br>
% cd /home/juner/tmp/<br>
% upks2lowks *<br>
<br>
改后的 shell script 如下:<br>
(如果命令路径和你机器上的不一样,改成一样的就行了)<br>
<br>
--------------------------------------<br>
#!/bin/sh<br>
<br>
# This Shell Script can change UPPER-CASE filename to low-case filename.<br>
<br>
# init the vars!<br>
<br>
error=0;count=0<br>
number=$(echo $* | /usr/bin/wc -w)<br>
<br>
# end of the "init the vars"!<br>
<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -