批量创建文件及批量修改文件名实战
批量创建文件:
#!/bin/bash[!-d/data]&&mkdir/dataforiin{1..10}domkdir-p/data/xcn_$i.htmldone执行结果:[root@XCNfor]#shtest5.sh[root@XCNfor]#ll/data/total40drwxr-xr-x2rootroot4096Jul215:27xcn_1.htmldrwxr-xr-x2rootroot4096Jul215:27xcn_10.htmldrwxr-xr-x2rootroot4096Jul215:27xcn_2.htmldrwxr-xr-x2rootroot4096Jul215:27xcn_3.htmldrwxr-xr-x2rootroot4096Jul215:27xcn_4.htmldrwxr-xr-x2rootroot4096Jul215:27xcn_5.htmldrwxr-xr-x2rootroot4096Jul215:27xcn_6.htmldrwxr-xr-x2rootroot4096Jul215:27xcn_7.htmldrwxr-xr-x2rootroot4096Jul215:27xcn_8.htmldrwxr-xr-x2rootroot4096Jul215:27xcn_9.html
批量更改文件名:用for循环实现以上文件中的xcn全部改成Linux,并且扩展名为大写
注意:for环境体不能出现xcn字符串
#!/bin/bashcd/dataforfin`ls*.html`domv$f`echo$f|sed's#xcn#linux#g'|sed's#html#HTML#g'`done
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。