In Bash
我正在尝试找到一种方法来复制所有子目录中的文件,chmod
:
例:
toto.txt in/home/a
但是在 中,我们可以找到 3 个dir
"b, c, d"
我想复制 b、c 、d 中的toto.txt
而不从 a 中删除toto.txt
。
这会
将 toto.txt 复制到 /home/a
下的所有子目录中
cd /home/a && for i in *
do
[ -d $i -a "$i" != ".." -a "$i" != "." ] && cp toto.txt "/home/a/$i/"
perm=$(stat -c "%a %n" xadmin/ | awk '{ print $1 }')
chmod $perm "/home/a/$i/toto.txt"
done
如果仅当目标是目录-d
并且文件目录未.
或..
时,if才会复制文件,这是当前目录和父目录。