Mu *_*iao 59
for file in /source/directory/*
do
if [[ -f $file ]]; then
#copy stuff ....
fi
done
Run Code Online (Sandbox Code Playgroud)
pop*_*tea 25
要列出常规文件/my/sourcedir/
,而不是在子目录中递归查找:
find /my/sourcedir/ -type f -maxdepth 1
Run Code Online (Sandbox Code Playgroud)
要将这些文件复制到/my/destination/
:
find /my/sourcedir/ -type f -maxdepth 1 -exec cp {} /my/destination/ \;
Run Code Online (Sandbox Code Playgroud)
要扩展poplitea的答案,您不必为每个文件执行cp:用于一次xargs
复制多个文件:
find /my/sourcedir -maxdepth 1 -type f -print0 | xargs -0 cp -t /my/destination
Run Code Online (Sandbox Code Playgroud)
要么
find /my/sourcedir -maxdepth 1 -type f -exec cp -t /my/destination '{}' +
Run Code Online (Sandbox Code Playgroud)