Linux shell脚本,将当前目录中的所有可执行文件移动到单独的文件夹中
我正在尝试编写shell脚本,该脚本将当前目录中的所有可执行文件移动到名为“executables”的文件夹中 当执行时,它说Linux shell脚本,将当前目录中的所有可执行文件移动到单独的文件夹中,linux,bash,shell,Linux,Bash,Shell,我正在尝试编写shell脚本,该脚本将当前目录中的所有可执行文件移动到名为“executables”的文件夹中 当执行时,它说 cp: cannot copy a directory, 'executable', into itself, './executable/executable'. 因此,我如何避免在if条件下检查“executable”文件夹。 或者有任何其他完美的解决方案 不要解析ls的输出 大多数目录都设置了可执行位 cp正在复制,mv正在移动 调整脚本: for f in *
cp: cannot copy a directory, 'executable', into itself, './executable/executable'.
因此,我如何避免在if条件下检查“executable”文件夹。
或者有任何其他完美的解决方案
ls
的输出cp
正在复制,mv
正在移动for f in *; do
if [ -f "$f" ] && [ -x "$f" ]; then
mv "$f" executables/
fi
done
使用GNU查找
:
$ find . -maxdepth 1 -type f -perm +a=x -print0 | xargs -0 -I {} mv {} executables/
ls
的输出cp
正在复制,mv
正在移动for f in *; do
if [ -f "$f" ] && [ -x "$f" ]; then
mv "$f" executables/
fi
done
使用GNU查找
:
$ find . -maxdepth 1 -type f -perm +a=x -print0 | xargs -0 -I {} mv {} executables/
尝试使用
find
实用程序进行此类操作。它提供了一些特定于文件处理的功能,而不是基于字符串的操作。例如,您可以将搜索限制为普通文件。尝试使用find
实用程序查找此类文件。它提供了一些特定于文件处理的功能,而不是基于字符串的操作。例如,您可以将搜索限制为普通文件。