[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12. Special file types

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 rmdir: Remove empty directories  Remove empty directories.
12.7 unlink: Remove files via the unlink syscall  Remove files via the unlink syscall


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.1 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 section `Hard Links' in The GNU C Library Reference Manual. 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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.2 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]... target [linkname]
ln [option]... target... directory

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. On all existing implementations, you cannot make a hard link to a directory, and hard links cannot cross filesystem 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. See section `Symbolic Links' in The GNU C Library Reference Manual.

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

`-b'
`--backup[=method]'
See section 2.1 Backup options. Make a backup of each file that would otherwise be overwritten or removed.

`-d'
`-F'
`--directory'
Allow the super-user to make hard links to directories.

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

`-i'
`--interactive'
Prompt whether to remove existing destination files.

`-n'
`--no-dereference'
When given an explicit destination that is a symlink to a directory, treat that destination 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.

`-s'
`--symbolic'
Make symbolic links instead of hard links. This option merely produces an error message on systems that do not support symbolic links.

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

`--target-directory=directory'
Specify the destination directory. See section 2.3 Target directory.

`-v'
`--verbose'
Print the name of each file before linking it.

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

Examples:

 
ln -s /some/name  # creates link ./name pointing to /some/name
ln -s /some/name myname  # creates link ./myname pointing to /some/name
ln -s a b ..      # creates links ../a and ../b pointing to ./a and ./b


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.3 mkdir: Make directories

mkdir creates directories with the specified names. Synopsis:

 
mkdir [option]... name...

If a name is an existing file but not a directory, mkdir prints a warning message on stderr and will exit with a status of 1 after processing any remaining names. The same is done when a name is an existing directory and the -p option is not given. If a name is an existing directory and the -p option is given, mkdir will ignore it. That is, mkdir will not print a warning, raise an error, or change the mode of the directory (even if the -m option is given), and will move on to processing any remaining names.

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

`-m mode'
`--mode=mode'
Set the mode of created directories to mode, which is symbolic as in chmod and uses `a=rwx' (read, write and execute allowed for everyone) minus the bits set in the umask for the point of the departure. See section 26. File permissions.

`-p'
`--parents'
Make any missing parent directories for each argument. The mode for parent directories is set to the umask modified by `u+wx'. Ignore arguments corresponding to existing directories.

`-v'
`--verbose'
Print a message for each created directory. This is most useful with `--parents'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.4 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 2. Common options.

`-m mode'
`--mode=mode'
Set the mode of created FIFOs to mode, which is symbolic as in chmod and uses `a=rw' (read and write allowed for everyone) minus the bits set in the umask for the point of departure. See section 26. File permissions.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.5 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.

The arguments after name specify the type of file to make:

`p'
for a FIFO

`b'
for a block special file

`c'
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.

The program accepts the following option. Also see 2. Common options.

`-m mode'
`--mode=mode'
Set the mode of created files to mode, which is symbolic as in chmod and uses `a=rw' minus the bits set in the umask as the point of departure. See section 26. File permissions.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.6 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 option. Also see 2. Common options.

`--ignore-fail-on-non-empty'
Ignore each failure to remove a directory that is solely because the directory is non-empty.

`-p'
`--parents'
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.

`-v'
`--verbose'
Give a diagnostic for each successful removal. directory is removed.

See section 11.5 rm: Remove files or directories, for how to remove non-empty directories (recursively).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.7 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 section `Deleting Files' in The GNU C Library Reference Manual. Synopsis:

 
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.

By default, unlink honors the `--help' and `--version' options. That makes it a little harder to remove files named --help and --version, so when the environment variable POSIXLY_CORRECT is set, unlink treats such a command line arguments not as an option, but as an operand.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Jeff Bailey on December, 28 2002 using texi2html