开发者

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 locatio开发者_如何学Pythonn to another. I imagine this is a little more complicated than a simple cp command, how is it done?


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.


In bash, you could write something like:

   cp -a ${SOURCE_DIR} ${DEST_DIR} 

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜