rename: Rename a file

Package: system

Usage

rename file newname

Parameters

file
A template specifying the file or files to be renamed.
newname
If a single file is being renamed, the new filename, else the new name of the field being renamed in a set of filenames. If newname is a directory the input files will be moved to this directory with the same name.
field = all
If set to "all" the file name remains unchanged and the newname is assumed to be a destination directory in the case of multiple input files, or the new filename (which may contain a new directory path) in the case of a single input file. If set to ldir the newname value is taken to be a destination directory and the file is moved to this directory. Setting to root will rename only the root portion of the filename, a value of extn will change or append the extension. newname cannot contain a directory path when changing the root or extn field.

Description

Rename renames either a single file to "newname", or a set of files, changing either the ldir, root or the extension part of each name. If newname is a directory or field is "ldir" the input files are moved to this directory and the filenames remain the same. When modifying the root or extension part of the filename newname is the new root or extension name for the input files, an extension will be added to the file name if it doesn't already exist and the extension field is being modified. For multiple input files it is assumed that newname is a directory if the value of field is "all", otherwise an error is generated to prevent overwriting files.

Examples

1. Rename file "fred" to "jay".

cl> rename fred jay

2. Change the root name of a set of files from "out" to "pkout".

cl> rename out.x,out.o,out.par pkout field=root

3. Change the extension of all ".f77" files from ".f77" to ".f".

cl> rename *.f77 f field=extn

4. Move all files with a ".dat" extension to a new directory.

cl> rename *.dat data$
cl> rename *.dat /data/user

5. Add a ".fits" extension to all files in a directory.

cl> rename im00* fits field=extn

Bugs

See also

movefiles, copy