如何仅将目录中的常规文件(忽略子目录和链接)复制到同一目标? (Linux上的bash) 非常多的文件
答案 0 :(得分:52)
for file in /source/directory/*
do
if [[ -f $file ]]; then
#copy stuff ....
fi
done
答案 1 :(得分:24)
列出/my/sourcedir/
中的常规文件,而不是在子目录中递归查找:
find /my/sourcedir/ -type f -maxdepth 1
将这些文件复制到/my/destination/
:
find /my/sourcedir/ -type f -maxdepth 1 -exec cp {} /my/destination/ \;
答案 2 :(得分:8)
要展开poplitea's answer,您不必为每个文件执行cp:使用xargs
一次复制多个文件:
find /my/sourcedir -maxdepth 1 -type f -print0 | xargs -0 cp -t /my/destination
或
find /my/sourcedir -maxdepth 1 -type f -exec cp -t /my/destination '{}' +