2

Lets say we have two directories:

Directory A:

aaa.mov
bbb.mov
ccc.mov
ddd.mov
eee.mov

Directory B:

subdir1/aaa.mov
subdir1/bbb.mov
subdir2/subsubdir/ccc.mov

How could I transfer from A to B/newDir, all files which do not exist under any B's subdirectories (ddd.mov & eee.mov)?

2
  • Judging from /, operating system is Linux or Mac OS X?
    – Olli
    Feb 27, 2011 at 10:02
  • well..Mac OS X :)
    – nuc
    Feb 27, 2011 at 10:04

1 Answer 1

3

A simple shell script will achieve what you want...

#!/bin/sh

SRCDIR=dira
DSTDIR=dirb
SRCFILES=`find ${SRCDIR} -type f -exec basename '{}' \;`
mkdir -p ${DSTDIR}/NewDir

for FILE in ${SRCFILES}
do
        FOUND=`find ${DSTDIR} -name ${FILE} -type f`
        if [ -z ${FOUND} ]
        then
                echo -n "Copying ${FILE}..."
                cp ${SRCDIR}/${FILE} ${DSTDIR}/NewDir
                echo "done"
        fi
done
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.