Glindra
Documentation Index Download
Command Line File Handling and ASCII Tools

cop - Copy


Copies one or more files, or an entire directory tree.

Example (Linux)
> cop '***/*.html' '/backup/***/*.htm' -before=yesterday
Copied to:   /home/chris/backup/about.htm
Copied to:   /home/chris/backup/index.htm
Created dir: /home/chris/backup/doc/
Copied to:   /home/chris/backup/doc/00readme.htm
Created dir: /home/chris/backup/doc/old
Copied to:   /home/chris/backup/doc/old/index.htm
  19 kb copied, 4 files


cop accepts the same wildcards and file selection options as the d directory command.

Under Linux, filenames that contain wildcards must be enclosed in quotes, to prevent the shell from expanding the wildcards.

The cop command supports version numbers. If an output file already exists, it is not overwritten. Instead it is renamed with a version number before the input file is copied.

cop cannot be used to concatenate files.

Parameters

Input File Specification

Example
> cop a.xyz b.xyz


The first parameter is an input file specification.  cop accepts the same wildcards as the d directory command. See File Specifications.

The command will normally not copy directory files. If you want it to, you must add the -directories option to the command line.

No default wildcards for input file

Unlike the d directory command, cop does not add any defaults to the input file specification, so you must specify all wildcards explicitly.

This makes cop a bit more less generous than the d directory command, just like the rena (rename) command. This stinginess is intentional.

Wildcards to use with cop and rena:
*.*.* All versions of all files in the directory.
*.*
*.*.
The highest version of all files in the directory, but not the previous versions.

Both variants have the same meaning. The first one is shortest.

*
*.
The highest version of all files in the directory that have an empty extension.

Note that this is different from how a Unix shell would interpret a single asterisk. It is also different from the meaning it has in the d directory command, where wildcards for extension and version number are added automatically.

*..*
*.~*~
All versions of all files in the directory that have an empty extension.

If you use the syntax with only one dot, the tildes are required, or the last asterisk will be interpreted as "all extensions" rather than "all versions".


Multiple input files

If you want to give a list of input files, they must be enclosed in parentheses (to separate them from the second parameter, which is the output file specification).

Example (Windows)
> cop (*.html x.css *.gif) publish\
Example (Linux)
> cop \('*.html' x.css '*.gif'\) publish/

Output File Specification

Example
> cop a.xyz b.xyz

The second parameter is an output file specification, which is described on the page Output File Specifications.

The rest of the description here deals with specifics for the cop command.

Output file default is *.* in current working directory
The default output file specification is "*.*".  If you do not specify any output directory, the files will be copied to the current working directory.

In cop you must always specify something as the output file specification, or you will get an error message saying "required parameter missing". If you just want to copy files to the current working directory without changing their names, the easiest is to write a dot . (for current directory) as the output specification.

Example (Windows)
> cop \somewhere\else\*.html .
copies the files to the current directory.

If you want to copy files to another directory without changing their names, you can omit the name and extension wildcards in the output file specification.

Example (Windows)
> cop *.html publish\
Example (Linux)
> cop '*.html' publish/
Copying directory trees
To copy a directory and all its contents, including subdirectories, use the *** directory wildcard in both the input and output file specifications.
Example (Windows)
> cop mydir\***\*.*.* backup\mydir\*** -directories=also
Example (Linux)
> cop 'mydir/***/*.*.*' 'backup/mydir/***' -directories=also
The -directories option is only required if you want the cop command to copy empty subdirectories from the input directory tree as well. These will otherwise be ignored, as the cop command has the option -nodirectories set by default.

The output subdirectories that are needed to hold the output files will always be created as required when you use the *** directory wildcard, however, whether you use the -directories=also option or not.


If you try to copy a directory by just giving its name (without any directory wildcards like ***), the best you can achieve is to create a new empty directory.

Example (Windows)
> cop mydir backup\
[warning] No such file: mydir -nodirectories
  No files copied
Nothing at all gets copied (even if mydir does in fact exist), since the -directories file selection option was not specified.


> cop mydir backup\ -directories=also
Created dir: E:\glindra\test\backup\mydir
  0 byte copied, 1 file
Okay, but the newly created backup\mydir will be empty even if mydir contained files and/or subdirectories.


Options

File Selection Options

Example (Windows)
> cop ***\*.* data\*** -exclude=(.doc .txt) -before=today -min_size=2mb -hidden=also
Example (Linux)
> cop '***/*.*' 'data/***' -exclude=(.doc .txt) -before=today -min_size=2mb -hidden=also
Options
-since [= datetime] Select files that were created on or after a certain date/time.
-before [= datetime] Select file that were created before a certain date/time.
-min_size [= size] Specify a minimum file size in bytes, Mb, or some other unit
-max_size [= size] Specify a maximum file size .
-directories [= only/also/not]
List directory files (only/also/not) . Default is also.
-hidden [= only/also/not] List hidden files (only/also/not). Default is not.
-nodefault Do not add any default wildcards or other filename parts to the filename.
For the cop command, option is used to suppress wildcards in the output file specification. (The input file specifications has no default wildcards to suppress.)
-exclude [= filespec] Exclude files that match the file specification given as option value. If the option value is enclosed in parenthesis, it can contain a full file specification, including recursive file selection options.

These options control which files are selected. See File Selection Options.

Filename Cleanup Options

Example (Windows)
> cop *.* \export\*.* -nospace
Example (Linux)
> cop '*.*' '/export/*.*' -nospace
Copies files and makes sure that the output filenames do not contain any spaces or any of the most problematic characters.
Options
-safe
  • Maps leading dashes (hyphens) to underscores.
  • Collapses spaces.
  • Maps problematic characters like *?:[]"<>|(){} to underscore.
-portable Performs the same cleanup operations as -safe, and additionally:
  • Maps all 8-bit characters from the upper half of the Latin 1 alphabet to reasonable 7-bit fallback characters.
  • Maps the single quote characters '`´ to underscore.
-lower
-upper
-title
Converts the filenames to lower, UPPER, or Title Case.
-nospace Maps all spaces to underscore.
-nodash Maps all dashes (hyphens) to underscore.

These options  are used to clean up filenames while copying files. See Filename Cleanup Options.

Help and Information Options

Example (Windows)
> cop *.log *.oldlog -nowarning
Example (Linux)
> cop '*.log' '*.oldlog' -nowarning
Options
-help   -h   -?
Print out a brief help text with a summary of each of the different options, and exit from the program.
-version Show the name and version number of the program, and exit. This option must be written out in full, and cannot be abbreviated.
-verbose   -v
-statistics
-noverbose
Specify the amount of informational messages.
-warning
-nowarning
-noerror
Specify the level of error reporting.

See Help and Information Options.