2.3.2 The cp Command

The cp command is used to copy files from the fatback environment out to the host file system. It has the following syntax:

cp options files to-directory

files can be specified as any number of file names, or patterns. Patterns are used to specify many files at once by using special sequences of characters. The most commonly used patters are ‘*’, ‘?’, and ‘[]’. The ‘*’ character is used to specify zero or more characters of any kind, ‘?’ specifies one character of any kind, and ‘[]’ specifies a single character of a specific set.

Patterns

When used by its self, the ‘*’ character will match all files in a directory. For example the following command would copy all the files in the current directory to the /mnt/data directory in the hosts file system:

cp * /mnt/data

The ‘*’ character can also be used in conjunction with other. For example, the following command will copy all files that end in ‘.exe’ to the /mnt/data directory:

cp *.exe /mnt/data

Here is an example of using the ‘?’ character to copy all the files in the SETUP directory that have a single character for an extension to the /mnt/data directory:

cp SETUP/*.? /mnt/data

The ‘[]’ pattern is a bit more complex than the previous examples. Between the left and right bracket is where a specific set of matching characters is specified. For example, the pattern ‘[abc]’ would match the letter ‘a’, ‘b’, or ‘c’. Ranges or characters can also be specified using the ‘-’ character in between two other characters. Using this syntax, all the letters in the alphabet can be specified using the pattern ‘[a-z]’.

Patterns can be combined for even greater power. If you copy all the files in the current directory that begin with a number and end with the extension ‘.dat’ to the /mnt/data directory, the following command could be used:

cp [0-9]*.dat /mnt/data

For more information on the syntax of the patterns, consult your systems man pages under globs(7).

cp command options

The cp command accepts two options, ‘-d’ and ‘-R’. The ‘-d’ option tells cp to only copy files that are deleted, and skip over active file entries. The ‘-R’ option makes the command recurse down any sub directories it finds. To undelete all the files in a partition to the /mnt/data directory, use the following command:

cp -d -R /* /mnt/data