coffee
coffee

Reputation: 23

From a shell script, how to copy entire tree of files

I want to check if a file exists, and if not, copy an entire tree of files from one location to another. I imagine this is a little more complicated than a simple cp command, how is it done?

Upvotes: 0

Views: 268

Answers (2)

paxdiablo
paxdiablo

Reputation: 881383

Actually, it's only a little more complicated than a simple cp command inasmuch as it's a near-simple cp command. cp under Linux has a recursive option so you can do:

cp -R dir1 dir2

See here for details or execute man cp from a terminal window. To check if a file exists in bash, you can use:

if [[ -f file.txt ]] ; then
    # do something
fi

Execute man bash for details on [[ or see here.

Upvotes: 2

Marco Bizzarri
Marco Bizzarri

Reputation: 371

In bash, you could write something like:

   cp -a ${SOURCE_DIR} ${DEST_DIR} 

but again, this depends on the expect problem you have.

Upvotes: 0

Related Questions