如果我们在/opt目录
查找opt目录下的txt结尾的文件
find /opt -iname "*.txt" -exec cp -a {} /tmp{}.bak \;
其中 find 命令
/opt 是在opt目录下查找
-iname 找哪个文件名
"*.txt" 找.txt结尾的文件
-exec 将找到的文件进行程序化处理,后面跟着处理命令
cp -a 全部复制到
{} 代表之前找到的文件
/tmp{}.bak 将找到的文件后面添加一个.bak 完成改名
\; 固定格式,代表-exec的结束符
----------------------------------------------------
以下有个改动的小细节,请注意看
find /opt -iname "*.txt" -exec cp -a {} /tmp/{}.bak \;
查找opt目录下的txt结尾的文件
find /opt -iname "*.txt" -exec cp -a {} /tmp{}.bak \;
其中 find 命令
/opt 是在opt目录下查找
-iname 找哪个文件名
"*.txt" 找.txt结尾的文件
-exec 将找到的文件进行程序化处理,后面跟着处理命令
cp -a 全部复制到
{} 代表之前找到的文件
/tmp{}.bak 将找到的文件后面添加一个.bak 完成改名
\; 固定格式,代表-exec的结束符
----------------------------------------------------
以下有个改动的小细节,请注意看
find /opt -iname "*.txt" -exec cp -a {} /tmp/{}.bak \;