我一直试图将整个文件夹复制到另一个文件夹,这只是添加了-r
选项
cp -r sourceFolder destFolder
但现在我需要从 sourceFolder 中排除一些文件。如何实现?
答案1
你可以做这样的事情
for f in sourceFolder/*
do
if [ "f$" != "filename-to-exclude1" ] || [ "f$" != "filename-to-exclude2" ] # || ...can be extended
then
cp -r f$ destinationFolder # this will copy files and folders regardless so if you need to exclude a file from a subfolder you need to extend that if then structure
fi
done