每天學點linux--(用shell實現將一個資料夾下面的所有檔案拷貝到另一個資料夾下/shell下如何重新命名一個檔案)
阿新 • • 發佈:2019-01-23
一、用shell實現將一個資料夾下面的所有檔案拷貝到另一個資料夾下
收穫:
1、在if test -d $1的時候,if後面一定要有空格
2、在使用變數的時候一定要用$!
3、學會`commad`的用法
下面給出程式碼,還有一些不完善的地方,有空補全一下,第一次shell程式,寫的有點醜,希望別介意
if test -d $1 then if test -d $2 then cd $1 for dir in `ls $1` do if test -f $dir then cp $dir $2 else echo "Error exist on $dir" fi done echo "cp_file complete!" else echo "$2 is not a diretory!" fi else echo "$1 is not a directory!" fi
二、shell下如何重新命名一個檔案
mv file1 file2,就可以重新命名一個檔案了,真的是神一樣的用法,把我給雷翻了= =!!