O'Reilly logo

Expert Shell Scripting by Ron Peters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 20Directory Copying

Copying files from one place to another seems a trivial task hardly worth mentioning in an advanced shell-scripting book. However, copying groups of files with the typical cp command doesn't result in a true copy. You might expect an exact duplicate of the source files, but there may be soft links, hard links, subdirectories, pipes, dot files, and regular files, among others, and the cp command doesn't work as you might expect with all of them. You need to make a few tweaks to get a copy command that performs well for all file and link types. For testing purposes, I created a directory that contains some of each of these file types that can be used to check whether the copy has been performed correctly.

Using cp

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required