This document lists commands for creating, copying, renaming and removing Unix files and directories. The instructions here apply to many other Unix machines; however, you may notice different behavior if you are not using the ITS Login Service. A file is a "container" for data. Unix makes no distinction among file types—a file may contain the text of a document, data for a program or the program itself. Directories provide a way to organize files, allowing you to group related files together.
Directories are analogous to Macintosh and Windows folders. Each file and directory has a name. Within a directory, each item that is, each file or directory must have a unique name, but items with the same name may exist in more than one directory.
A directory may have the same name as one of the items it contains. File and directory names may be up to characters long. Names may use almost any character except a space. Some characters have special meanings to Unix.
It is best to avoid using these characters in file names:. Unix is case-sensitive. Terminate file entry by typing Control-d on a line by itself. Hold down the Control key and type d. On your screen, you will see:. To make a duplicate copy of a file, use the command cp. For example, to create an exact copy of the file called firstfile, you would type:.
This results in two files with different names, each containing the same information. The cp command works by overwriting information. If you create a different file called thirdfile and then type the following command:. Unix does not have a command specifically for renaming files. Instead, the mv command is used both to change the name of a file and to move a file into a different directory.
To change the name of a file, use the following command format where thirdfile and file3 are sample file names :. This differs from fork 2 , where execution continues in the child from the point of the fork 2 call. The fn argument is a pointer to a function that is called by the child process at the beginning of its execution. The arg argument is passed to the fn function. When the fn arg function application returns, the child process terminates.
The integer returned by fn is the exit code for the child process. The child process may also terminate explicitly by calling exit 2 or after receiving a fatal signal.
Since the child and calling process may share memory, it is not possible for the child process to execute in the same stack as the calling process. The calling process must therefore set up memory space for the child stack and pass a pointer to this space to clone. The low byte of flags contains the number of the termination signal sent to the parent when the child dies. If no signal is specified, then the parent process is not signaled when the child terminates.
This includes the root of the file system, the current working directory, and the umask. Any call to chroot 2 , chdir 2 , or umask 2 performed by the calling process or the child process also affects the other process. Calls to chroot 2 , chdir 2 , umask 2 performed later by one of the processes do not affect the other process.
Any file descriptor created by the calling process or by the child process is also valid in the other process. The duplicated file descriptors in the child refer to the same open file descriptions see open 2 as the corresponding file descriptors in the calling process.
Subsequent operations that open or close file descriptors, or change file descriptor flags, performed by either the calling process or the child process do not affect the other process. Every process lives in a namespace. The namespace of a process is the data the set of mounts describing the file hierarchy as seen by that process. The system calls mount 2 and umount 2 change the namespace of the calling process, and hence affect all processes that live in the same namespace, but do not affect processes in a different namespace.
If the calling process or child process calls sigaction 2 to change the behavior associated with a signal, the behavior is changed in the other process as well. Viewed 32 times. I've got this code so far, but how best can it be achieved?
Improve this question. Richard Richard 7 1 1 silver badge 4 4 bronze badges. Do you want the same source file copied to the same target or a different target each time?. Richard, is that comment of yours your own suggestion as a starting point, or a solution that you're now using? Other than that, the approach works. Add a comment. Active Oldest Votes. You want a forever-repeating loop! Improve this answer. Thanks roaima : — Richard.
0コメント