返回列表 发帖

[问题求助] 以文件名为条件建立文件夹的shell脚本编写

http://bbs.bathome.net/viewthrea ... mp;extra=#pid109951

链接处的内容是win平台的问题,现已在4#得到了解决。
由初期的for循环中的delims问题最终定位到%%~na的有效应用,实现了问题的最终解决。

此帖是将思维扩展一下,到了linux平台下,结合链接处1#的具体内容,大家可否写一下脚本代码。

[seesea@bathome test]$ echo "aa" > atimetool_1.9.6.deb
[seesea@bathome test]$ echo "aa" > atimetool_1.9.7.deb
[seesea@bathome test]$ ls
atimetool_1.9.6.deb  atimetool_1.9.7.deb
[seesea@bathome test]$ for f in *; do mkdir ${f/.deb/} && mv $f ${f/.deb/}; done;
[seesea@bathome test]$ ls
atimetool_1.9.6  atimetool_1.9.7
[seesea@bathome test]$ ls *
atimetool_1.9.6:
atimetool_1.9.6.deb
atimetool_1.9.7:
atimetool_1.9.7.deb
[seesea@bathome test]$ for d in *; do mv $d/* .; rm -rf $d; done;
[seesea@bathome test]$ ls
atimetool_1.9.6.deb  atimetool_1.9.7.debCOPY

TOP

# 移入目录
[seesea@bathome test]$ for f in *; do mkdir ${f/.deb/} && mv $f ${f/.deb/}; done;
# 移出目录
[seesea@bathome test]$ for d in *; do mv $d/* .; rm -rf $d; done;COPY

TOP

谢谢楼上两位,我得消化一阵,shell脚本的功底还是不太好。

TOP

返回列表