| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter describes commands which create special types of files (and
rmdir, which removes directories, one special file type).
Although Unix-like operating systems have markedly fewer special file types than others, not everything can be treated only as the undifferentiated byte stream of normal files. For example, when a file is created or removed, the system must record this information, which it does in a directory--a special type of file. Although you can read directories as normal files, if you're curious, in order for the system to do its job it must impose a structure, a certain order, on the bytes of the file. Thus it is a "special" type of file.
Besides directories, other special file types include named pipes (FIFOs), symbolic links, sockets, and so-called special files.
12.1 link: Make a hard link via the link syscall | Make a hard link via the link syscall | |
12.2 ln: Make links between files | Make links between files. | |
12.3 mkdir: Make directories | Make directories. | |
12.4 mkfifo: Make FIFOs (named pipes) | Make FIFOs (named pipes). | |
12.5 mknod: Make block or character special files | Make block or character special files. | |
12.6 readlink: Print value of a symlink or canonical file name | Print value of a symlink or canonical file name. | |
12.7 rmdir: Remove empty directories | Remove empty directories. | |
12.8 unlink: Remove files via the unlink syscall | Remove files via the unlink syscall |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
link: Make a hard link via the link syscall link creates a single hard link at a time.
It is a minimalist interface to the system-provided
link function. See (libc)Hard Links section `Hard Links' in The GNU C Library Reference Manual.
It avoids the bells and whistles of the more commonly-used
ln command (see section ln: Make links between files).
Synopsis:
link filename linkname |
filename must specify an existing file, and linkname
must specify a nonexistent entry in an existing directory.
link simply calls link (filename, linkname)
to create the link.
On a GNU system, this command acts like `ln --directory
--no-target-directory filename linkname'. However, the
`--directory' and `--no-target-directory' options are
not specified by POSIX, and the link command is
more portable in practice.
If filename is a symbolic link, it is unspecified whether
linkname will be a hard link to the symbolic link or to the
target of the symbolic link. Use ln -P or ln -L
to specify which behavior is desired.
An exit status of zero indicates success, and a nonzero value indicates failure.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
ln: Make links between files ln makes links between files. By default, it makes hard links;
with the `-s' option, it makes symbolic (or soft) links.
Synopses:
ln [option]… [-T] target linkname ln [option]… target ln [option]… target… directory ln [option]… -t directory target… |
ln creates a link to the first
file from the second.
ln creates a link to that file
in the current directory.
ln creates a link to each target file in the specified
directory, using the targets' names.
Normally ln does not remove existing files. Use the
`--force' (`-f') option to remove them unconditionally,
the `--interactive' (`-i') option to remove them
conditionally, and the `--backup' (`-b') option to
rename them.
A hard link is another name for an existing file; the link and the original are indistinguishable. Technically speaking, they share the same inode, and the inode contains all the information about a file--indeed, it is not incorrect to say that the inode is the file. Most systems prohibit making a hard link to a directory; on those where it is allowed, only the super-user can do so (and with caution, since creating a cycle will cause problems to many other utilities). Hard links cannot cross file system boundaries. (These restrictions are not mandated by POSIX, however.)
Symbolic links (symlinks for short), on the other hand, are a special file type (which not all kernels support: System V release 3 (and older) systems lack symlinks) in which the link file actually refers to a different file, by name. When most operations (opening, reading, writing, and so on) are passed the symbolic link file, the kernel automatically dereferences the link and operates on the target of the link. But some operations (e.g., removing) work on the link file itself, rather than on its target. The owner and group of a symlink are not significant to file access performed through the link, but do have implications on deleting a symbolic link from a directory with the restricted deletion bit set. On the GNU system, the mode of a symlink has no significance and cannot be changed, but on some BSD systems, the mode can be changed and will affect whether the symlink will be traversed in file name resolution. See (libc)Symbolic Links section `Symbolic Links' in The GNU C Library Reference Manual.
Symbolic links can contain arbitrary strings; a dangling symlink occurs when the string in the symlink does not resolve to a file. There are no restrictions against creating dangling symbolic links. There are trade-offs to using absolute or relative symlinks. An absolute symlink always points to the same file, even if the directory containing the link is moved. However, if the symlink is visible from more than one machine (such as on a networked file system), the file pointed to might not always be the same. A relative symbolic link is resolved in relation to the directory that contains the link, and is often useful in referring to files on the same device without regards to what name that device is mounted on when accessed via networked machines.
When creating a relative symlink in a different location than the current directory, the resolution of the symlink will be different than the resolution of the same string from the current directory. Therefore, many users prefer to first change directories to the location where the relative symlink will be created, so that tab-completion or other file resolution will find the same target as what will be placed in the symlink.
The program accepts the following options. Also see Common options.
See section Backup options. Make a backup of each file that would otherwise be overwritten or removed.
Allow users with appropriate privileges to attempt to make hard links to directories. However, note that this will probably fail due to system restrictions, even for the super-user.
Remove existing destination files.
Prompt whether to remove existing destination files.
If `-s' is not in effect, and the source file is a symbolic link, create the hard link to the file referred to by the symbolic link, rather than the symbolic link itself.
Do not treat the last operand specially when it is a symbolic link to a directory. Instead, treat it as if it were a normal file.
When the destination is an actual directory (not a symlink to one),
there is no ambiguity. The link is created in that directory.
But when the specified destination is a symlink to a directory,
there are two ways to treat the user's request. ln can
treat the destination just as it would a normal directory and create
the link in it. On the other hand, the destination can be viewed as a
non-directory--as the symlink itself. In that case, ln
must delete or backup that symlink before creating the new link.
The default is to treat a destination that is a symlink to a directory
just like a directory.
This option is weaker than the `--no-target-directory' (`-T') option, so it has no effect if both options are given.
If `-s' is not in effect, and the source file is a symbolic link, create the hard link to the symbolic link itself. On platforms where this is not supported by the kernel, this option creates a symbolic link with identical contents; since symbolic link contents cannot be edited, any file name resolution performed through either link will be the same as if a hard link had been created.
Make symbolic links instead of hard links. This option merely produces an error message on systems that do not support symbolic links.
Append suffix to each backup file made with `-b'. See section Backup options.
Specify the destination directory. See section Target directory.
Do not treat the last operand specially when it is a directory or a symbolic link to a directory. See section Target directory.
Print the name of each file after linking it successfully.
If `-L' and `-P' are both given, the last one takes
precedence. If `-s' is also given, `-L' and `-P'
are silently ignored. If neither option is given, then this
implementation defaults to `-P' if the system link supports
hard links to symbolic links (such as the GNU system), and `-L'
if link follows symbolic links (such as on BSD).
An exit status of zero indicates success, and a nonzero value indicates failure.
Examples:
Bad Example: # Create link ../a pointing to a in that directory. # Not really useful because it points to itself. ln -s a .. Better Example: # Change to the target before creating symlinks to avoid being confused. cd .. ln -s adir/a . Bad Example: # Hard coded file names don't move well. ln -s $(pwd)/a /some/dir/ Better Example: # Relative file names survive directory moves and also # work across networked file systems. ln -s afile anotherfile ln -s ../adir/afile yetanotherfile |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
mkdir: Make directories mkdir creates directories with the specified names. Synopsis:
mkdir [option]… name… |
mkdir creates each directory name in the order given.
It reports an error if name already exists, unless the
`-p' option is given and name is a directory.
The program accepts the following options. Also see Common options.
Set the file permission bits of created directories to mode,
which uses the same syntax as
in chmod and uses `a=rwx' (read, write and execute allowed for
everyone) for the point of the departure. See section File permissions.
Normally the directory has the desired file mode bits at the moment it is created. As a GNU extension, mode may also mention special mode bits, but in this case there may be a temporary window during which the directory exists but its special mode bits are incorrect. See section Directories and the Set-User-ID and Set-Group-ID Bits, for how the set-user-ID and set-group-ID bits of directories are inherited unless overridden in this way.
Make any missing parent directories for each argument, setting their file permission bits to the umask modified by `u+wx'. Ignore existing parent directories, and do not change their file permission bits.
To set the file permission bits of any newly-created parent
directories to a value that includes `u+wx', you can set the
umask before invoking mkdir. For example, if the shell
command `(umask u=rwx,go=rx; mkdir -p P/Q)' creates the parent
`P' it sets the parent's permission bits to `u=rwx,go=rx'.
To set a parent's special mode bits as well, you can invoke
chmod after mkdir. See section Directories and the Set-User-ID and Set-Group-ID Bits, for how the set-user-ID and set-group-ID bits of
newly-created parent directories are inherited.
Print a message for each created directory. This is most useful with `--parents'.
Set the default SELinux security context to be used for created directories.
An exit status of zero indicates success, and a nonzero value indicates failure.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
mkfifo: Make FIFOs (named pipes) mkfifo creates FIFOs (also called named pipes) with the
specified names. Synopsis:
mkfifo [option] name… |
A FIFO is a special file type that permits independent processes to communicate. One process opens the FIFO file for writing, and another for reading, after which data can flow as with the usual anonymous pipe in shells or elsewhere.
The program accepts the following option. Also see Common options.
Set the mode of created FIFOs to mode, which is symbolic as in
chmod and uses `a=rw' (read and write allowed for everyone)
for the point of departure. mode should specify only file
permission bits. See section File permissions.
Set the default SELinux security context to be used for created FIFOs.
An exit status of zero indicates success, and a nonzero value indicates failure.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
mknod: Make block or character special files mknod creates a FIFO, character special file, or block special
file with the specified name. Synopsis:
mknod [option]… name type [major minor] |
Unlike the phrase "special file type" above, the term special
file has a technical meaning on Unix: something that can generate or
receive data. Usually this corresponds to a physical piece of hardware,
e.g., a printer or a disk. (These files are typically created at
system-configuration time.) The mknod command is what creates
files of this type. Such devices can be read either a character at a
time or a "block" (many characters) at a time, hence we say there are
block special files and character special files.
Due to shell aliases and built-in mknod command, using an
unadorned mknod interactively or in a script may get you
different functionality than that described here. Invoke it via
env (i.e., env mknod …) to avoid interference
from the shell.
The arguments after name specify the type of file to make:
for a FIFO
for a block special file
for a character special file
When making a block or character special file, the major and minor device numbers must be given after the file type. If a major or minor device number begins with `0x' or `0X', it is interpreted as hexadecimal; otherwise, if it begins with `0', as octal; otherwise, as decimal.
The program accepts the following option. Also see Common options.
Set the mode of created files to mode, which is symbolic as in
chmod and uses `a=rw' as the point of departure.
mode should specify only file permission bits.
See section File permissions.
Set the default SELinux security context to be used for created files.
An exit status of zero indicates success, and a nonzero value indicates failure.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
readlink: Print value of a symlink or canonical file name readlink may work in one of two supported modes:
readlink outputs the value of the given symbolic link.
If readlink is invoked with an argument other than the name
of a symbolic link, it produces no output and exits with a nonzero exit code.
readlink outputs the absolute name of the given file which contains
no `.', `..' components nor any repeated separators
(`/') or symbolic links.
readlink [option] file |
By default, readlink operates in readlink mode.
The program accepts the following options. Also see Common options.
Activate canonicalize mode.
If any component of the file name except the last one is missing or unavailable,
readlink produces no output and exits with a nonzero exit
code. A trailing slash is ignored.
Activate canonicalize mode.
If any component is missing or unavailable, readlink produces
no output and exits with a nonzero exit code. A trailing slash
requires that the name resolve to a directory.
Activate canonicalize mode.
If any component is missing or unavailable, readlink treats it
as a directory.
Do not output the trailing newline.
Suppress most error messages.
Report error messages.
The readlink utility first appeared in OpenBSD 2.1.
There is a realpath command on some systems
which operates like readlink in canonicalize mode.
An exit status of zero indicates success, and a nonzero value indicates failure.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
rmdir: Remove empty directories rmdir removes empty directories. Synopsis:
rmdir [option]… directory… |
If any directory argument does not refer to an existing empty directory, it is an error.
The program accepts the following options. Also see Common options.
Ignore each failure to remove a directory that is solely because the directory is non-empty.
Remove directory, then try to remove each component of directory.
So, for example, `rmdir -p a/b/c' is similar to `rmdir a/b/c a/b a'.
As such, it fails if any of those directories turns out not to be empty.
Use the `--ignore-fail-on-non-empty' option to make it so such
a failure does not evoke a diagnostic and does not cause rmdir to
exit unsuccessfully.
Give a diagnostic for each successful removal. directory is removed.
See section rm: Remove files or directories, for how to remove non-empty directories (recursively).
An exit status of zero indicates success, and a nonzero value indicates failure.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
unlink: Remove files via the unlink syscall unlink deletes a single specified file name.
It is a minimalist interface to the system-provided
unlink function. See (libc)Deleting Files section `Deleting Files' in The GNU C Library Reference Manual. Synopsis:
It avoids the bells and whistles of the more commonly-used
rm command (see section rm: Remove files or directories).
unlink filename |
On some systems unlink can be used to delete the name of a
directory. On others, it can be used that way only by a privileged user.
In the GNU system unlink can never delete the name of a directory.
The unlink command honors the `--help' and
`--version' options. To remove a file whose name begins with
`-', prefix the name with `./', e.g., `unlink ./--help'.
An exit status of zero indicates success, and a nonzero value indicates failure.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on January, 20 2010 using texi2html 1.76.