如何获取目录中的所有文件?

Wil*_*den 8 bash

为什么这不起作用?

find . -maxdepth 1 -type f -print0 | xargs -0 .
Run Code Online (Sandbox Code Playgroud)

我得到的只是xargs: .: Permission denied.

Mat*_*Mat 15

当你运行时. file,你调用一个内置的shell ..您的xargs变体尝试执行当前目录.
即使它确实调用了内置函数,该命令也会在子shell中运行,因此所有"采购"都将毫无用处.

使用shell globbing和一个循环:

for file in * ; do
  if [ -f "$file" ] ; then
    . "$file"
  fi
done
Run Code Online (Sandbox Code Playgroud)