[英]shell script which will move all executable files in the current directory to a seperate folder
I trying to write shell script which will move all executable files in the current directory to a folder called "executables". 我试图编写shell脚本,它将当前目录中的所有可执行文件移动到名为“ executables”的文件夹中。
1 for f in `ls`
2 do
3 if [ -x $f ]
4 then
5 cp -R $f ./executable/
6 fi
7 done
when executed ,it says 当执行时,它说
cp: cannot copy a directory, 'executable', into itself, './executable/executable'.
so how i avoid checking the 'executable' folder in the if condition. 因此,如何避免在if条件下检查“ executable”文件夹。 or there is any other perfect solution for this.
或对此有任何其他完美的解决方案。
ls
. ls
的输出。 cp
is copying, mv
is moving. cp
正在复制, mv
正在移动。 Adapting your script: 修改脚本:
for f in *; do
if [ -f "$f" ] && [ -x "$f" ]; then
mv "$f" executables/
fi
done
With GNU find
: 使用GNU
find
:
$ find . -maxdepth 1 -type f -perm +a=x -print0 | xargs -0 -I {} mv {} executables/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.