Previous Topic: mkdir Command--Create a Directory (Cmdlet)Next Topic: new-comObject Command--Instantiate a COM Object (Funclet)


mv, ren Commands--Move Files and Directories (Funclets)

These commands move files or directories to another location. Either the source or target location must be on the local server. Operations between two remote systems are not supported. To specify a remote host, prefix the pathname with the hostname followed by two colons (::). The operation is performed through SFTP. Thus the remote system does not necessarily have the client AutoShell installed, an SSH server with SFTP access is sufficient. You can write the output to a file using the set alternate command.

Moving or renaming is equivalent in this case.

The commands have the following syntax:

{mv|ren} src trg [-silent] [-retval] [-R] [-user username] [-pass password] [-key key phrase] [-port portnumber]
src

Defines a search mask that specifies the directories or files to move. The separation character on Windows can be a backslash (\) or a forward slash (/). For UNIX-like systems, it must be a forward slash. For cross-platform script compatibility, only use the forward slash in path specifications.

Search masks use a simplified regular expression syntax that is compatible with DOS wildcard matching:

All other characters are not special characters and match themselves.

trg

Specifies the path of the target location.

-silent

(Optional) Suppresses output to the active output stream.

-retval

(Optional) Creates an array representing the return value. The array contains information about new file names. Each element consists of a string representing the fully qualified name of one destination file.

-R

(Optional) Copies directories recursively.

-user username

(Optional) Specifies the user name to log in to the remote node. A user name is required for password or public key authentication. If no user name is specified, the user name entered during AutoShell login is used. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: $$User

-pass password

(Optional) Specifies password to use to log in to the remote node. If no password is specified, the password entered during AutoShell login is used. To enter a hidden password after issuing this command, specify PW_GET() with an optional prompt as argument. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: $$Pass

-key key

(Optional) Specifies an absolute or relative path to a file containing a private RSA key to use to log in to the remote node. If a private key and a password are specified, AutoShell attempts a public key logon first, and if that fails, a password logon. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses. This parameter is only required when creating an SSH session on the fly using public key authentication.

Default: ""

phrase

Specifies the passphrase for a private key. If the key is not encrypted, the phrase is not required. To enter a hidden password after issuing this command, specify PW_GET() with an optional prompt as argument. Unquoted argument tokens are automatically stringified. Prevent automatic quoting for expressions by placing expression code in parentheses.

Default: ""

-port portnumber

(Optional) Port on which to connect to the target system.

Default: SSH standard port 22.

Examples

Move file c:/test/test1.log to directory c:/test1:

mv c:/test/test1.log c:/test1

Move entire directory c:/test to directory c:/test1:

mv c:/test c:/test1 -R

Move entire directory c:/test to the remote host remotesys into the directory c:/test1:

mv c:/test1/ remotesys::c:/test1/ -R

See also:

copy, cp Commands--Copy Files and Directories (Funclets)