0

I've been trying to copy a entire folder to another and this it's simply adding the -r option

cp -r sourceFolder destFolder

But now i need exclude some files from sourceFolder. How achieve this?

1
  • Excluded files, spread over different directories/levels? Identified by name? May 6, 2016 at 15:40

1 Answer 1

1

You can do something like this

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

Not the answer you're looking for? Browse other questions tagged .