About Us Documentation

Contact Site Map
 

  

WinPak
Documentation

Go to the previous, next chapter.

Basic operations

This chapter describes the commands for basic file manipulation: copying, moving (renaming), and deleting (removing).

cp: Copy files and directories

cp copies files (or, optionally, directories). The copy is completely independent of the original. You can either copy one file to another, or copy arbitrarily many files to a destination directory. Synopsis:

cp [option]... source dest
cp [option]... source... directory

If the last argument names an existing directory, cp copies each source file into that directory (retaining the same name). Otherwise, if only two files are given, it copies the first onto the second. It is an error if the last argument is not a directory and more than two non-option arguments are given.

If the source file contains holes, cp copies them and other blocks of zero bytes as holes. Otherwise, files are written just as they are read. (A hole is a sequence of zero bytes that does not occupy any physical disk blocks; the read system call reads these as zeroes.)

By default, cp does not copy directories. It also refuses to copy a file onto itself.

The program accepts the following options. Also see section Common options.

-a --archive -a --archive Preserve as much as possible of the structure and attributes of the original files in the copy. Equivalent to -dpR.

-b --backup -b --backup Make backups of files that are about to be overwritten or removed. See section Backup options.

-d --no-dereference -d --no-dereference Copy symbolic links as symbolic links rather than copying the files that they point to, and preserve hard links between source files in the copies.

-f --force -f --force Remove existing destination files.

-i --interactive -i --interactive Prompt whether to overwrite existing regular destination files.

-l --link -l --link Make hard links instead of copies of non-directories.

-p --preserve -p --preserve Preserve the original files' owner, group, permissions, and timestamps.

-P --parents -P --parents Form the name of each destination file by appending to the target directory a slash and the specified name of the source file. The last argument given to cp must be the name of an existing directory. For example, the command:

cp --parents a/b/c existing_dir

copies the file a/b/c to existing_dir/a/b/c, creating any missing intermediate directories.

-r Copy directories recursively, copying any non-directories and non-symbolic links (that is, FIFOs and special files) as if they were regular files. This means trying to read the data in each source file and writing it to the destination. Thus, with this option, cp may well hang indefinitely reading a FIFO, unless something else happens to be writing it.

-R --recursive -R --recursive Copy directories recursively, preserving non-directories (see -r just above).

-s --symbolic-link -s --symbolic-link Make symbolic links instead of copies of non-directories. All source filenames must be absolute (starting with /) unless the destination files are in the current directory. This option merely results in an error message on systems that do not support symbolic links.

-S suffix --suffix=suffix -S --suffix Append suffix to each backup file made with -b. See section Backup options.

-u --update -u --update Do not copy a nondirectory that has an existing destination with the same or newer modification time.

-v --verbose -v --verbose Print the name of each file before copying it.

-V method --version-control=method -V --version-control Change the type of backups made with -b. The method argument can be numbered (or t), existing (or nil), or never (or simple). See section Backup options.

-x --one-file-system -x --one-file-system Skip subdirectories that are on different filesystems from the one that the copy started on.

dd: Convert and copy a file

dd copies a file (from standard input to standard output, by default) with a changeable I/O blocksize, while optionally performing conversions on it. Synopsis:

dd [option]...

The program accepts the following options. Also see section Common options.

The numeric-valued options below (bytes and blocks) can be followed by a multiplier: b=512, c=1, k=1024, w=2, xm=m.

if=file if Read from file instead of standard input.

of=file of Write to file instead of standard output. Unless conv=notrunc is given, dd truncates file to zero bytes (or the size specified with seek=).

ibs=bytes ibs Read bytes bytes at a time.

obs=bytes obs Write bytes bytes at a time.

bs=bytes bs Both read and write bytes bytes at a time. This overrides ibs and obs.

cbs=bytes cbs Convert bytes bytes at a time.

skip=blocks skip Skip blocks ibs-byte blocks in the input file before copying.

seek=blocks seek Skip blocks obs-byte blocks in the output file before copying.

count=blocks count Copy blocks obs-byte blocks from the input file, instead of everything until the end of the file.

conv=conversion[,conversion]... conv Convert the file as specified by the conversion argument(s). (No spaces around any comma(s).)

Conversions:

ascii ascii, converting to Convert EBCDIC to ASCII.

ebcdic ebcdic, converting to Convert ASCII to EBCDIC.

ibm alternate ebcdic, converting to Convert ASCII to alternate EBCDIC.

block block (space-padding) For each line in the input, output cbs bytes, replacing the input newline with a space and padding with spaces as necessary.

unblock unblock Replace trailing spaces in each cbs-sized input block with a newline.

lcase lcase, converting to Change uppercase letters to lowercase.

ucase ucase, converting to Change lowercase letters to uppercase.

swab swab (byte-swapping) Swap every pair of input bytes. GNU dd, unlike others, works when an odd number of bytes are read---the last byte is simply copied (since there is nothing to swap it with).

noerror noerror Continue after read errors.

notrunc notrunc Do not truncate the output file.

sync sync (padding with nulls) Pad every input block to size of ibs with trailing zero bytes.

install: Copy files and set attributes

install copies files while setting their permission modes and, if possible, their owner and group. Synopses:

install [option]... source dest
install [option]... source... directory
install -d [option]... directory...

In the first of these, the source file is copied to the dest target file. In the second, each of the source files are copied to the destination directory. In the last, each directory (and any missing parent directories) is created.

install is similar to cp, but allows you to control the attributes of destination files. It is typically used in Makefiles to copy programs into their destination directories. It refuses to copy files onto themselves.

The program accepts the following options. Also see section Common options.

-c -c Ignored; for compatibility with old Unix versions of install.

-d --directory -d --directory Create each given directory and any missing parent directories, setting the owner, group and mode as given on the command line or to the defaults. It also gives any parent directories it creates those attributes. (This is different from the SunOS 4.x install, which gives directories that it creates the default attributes.)

-g group --group=group -g --group Set the group ownership of installed files or directories to group. The default is the process's current group. group may be either a group name or a numeric group id.

-m mode --mode=mode -m --mode Set the permissions for the installed file or directory to mode, which can be either an octal number, or a symbolic mode as in chmod, with 0 as the point of departure (see section File permissions). The default mode is 0755---read, write, and execute for the owner, and read and execute for group and other.

-o owner --owner=owner -o --owner If install has appropriate privileges (is run as root), set the ownership of installed files or directories to owner. The default is root. owner may be either a user name or a numeric user ID.

-s --strip -s --strip Strip the symbol tables from installed binary executables.

mv: Move (rename) files

mv moves or renames files (or directories). Synopsis:

mv [option]... source dest
mv [option]... source... directory

If the last argument names an existing directory, mv moves each other given file into a file with the same name in that directory. Otherwise, if only two files are given, it renames the first as the second. It is an error if the last argument is not a directory and more than two files are given.

mv can move only regular files across filesystems.

If a destination file exists but is normally unwritable, standard input is a terminal, and the -f or --force option is not given, mv prompts the user for whether to replace the file. (You might own the file, or have write permission on its directory.) If the response does not begin with y or Y, the file is skipped.

The program accepts the following options. Also see section Common options.

-b --backup -b --backup Make backups of files that are about to be overwritten or removed. See section Backup options.

-f --force -f --force Remove existing destination files and never prompt the user.

-i --interactive -i --interactive Prompt whether to overwrite each existing destination file, regardless of its permissions. If the response does not begin with y or Y, the file is skipped.

-u --update -u --update Do not move a nondirectory that has an existing destination with the same or newer modification time.

-v --verbose -v --verbose Print the name of each file before moving it.

-S suffix --suffix=suffix -S --suffix Append suffix to each backup file made with -b. See section Backup options.

-V method --version-control=method -V --version-control Change the type of backups made with -b. The method argument can be numbered (or t), existing (or nil), or never (or simple). See section Backup options.

rm: Remove files or directories

rm removes each given file. By default, it does not remove directories. Synopsis:

rm [option]... [file]...

If a file is unwritable, standard input is a terminal, and the -f or --force option is not given, or the -i or --interactive option is given, rm prompts the user for whether to remove the file. If the response does not begin with y or Y, the file is skipped.

The program accepts the following options. Also see section Common options.

-d --directory -d --directory Remove directories with unlink instead of rmdir, and don't require a directory to be empty before trying to unlink it. Only works if you have appropriate privileges. Because unlinking a directory causes any files in the deleted directory to become unreferenced, it is wise to fsck the filesystem after doing this.

-f --force -f --force Ignore nonexistent files and never prompt the user.

-i --interactive -i --interactive Prompt whether to remove each file. If the response does not begin with y or Y, the file is skipped.

-r -R --recursive -r -R --recursive Remove the contents of directories recursively.

-v --verbose -v --verbose Print the name of each file before removing it.

One common question is how to remove files whose names being with a -. GNU rm, like every program that uses the getopt function to parse its arguments, lets you use the -- option to indicate that all following arguments are non-options. To remove a file called -f in the current directory, you could type either:

rm -- -f

or:

rm ./-f

- and Unix rm The Unix rm program's use of a single - for this purpose predates the development of the getopt standard syntax.


 

 

Email addresses listed on this site may  NOT be used for unsolicited commercial email.

Ready-to-Run Software, Inc Privacy Statement

Portions (c)Copyright, 1996-2005 by Ready-to-Run Software, Inc
(All rights reserved.)
212 Cedar Cove
Lansing, NY 14882
Phone: 607 533 UNIX (8649)
Fax: 607 533 4002