~/ajkule


Special directories and files on a Linux system including special permissions

The /tmp directory must be made available for programs that require temporary files. It is recommended that files and directories located in /tmp be deleted whenever the system is booted. FHS (Filesystem Hierarchy Standard) added this recommendation on the basis of historical precedent and common practice, but did not make it a requirement because system administration is not within the scope of this standard. The /var/tmp directory is made available for programs that require temporary files or directories that are preserved between system reboots. Files and directories located in /var/tmp must not be deleted when the system is booted. The sticky bit permission is used to prevent other users from deleting files that they do not own in a shared directory. The sticky bit permission allows for files to be shared with other users, by changing write permission on the directory so that users can still add and delete files in the directory, but files can only be deleted by the owner of the file or the root user. To set the sticky bit permission symbolically:

# chmod o+t directory

To set the sticky bit permission numerically, add 1000 to the directory's existing permissions (assume the directory had 775 for its permission):

# chmod 1775

To remove the sticky permission symbolically:

# chmod o-t directory

To remove the sticky bit permission numerically, subtract 1000 from the directory's existing permissions:

# chmod 0775

List the details of the /tmp and /var/tmp directories. The t for the others permissions indicates that this directory has the sticky bit permission set.

$ ls -ld /tmp
drwxrwxrwt 8 root root 4096 Mar 4 01:41 /tmp
$ ls -ld /var/tmp
drwxrwxrwt 3 root root 4096 Mar 4 01:41 /tmp

ln makes links between files. By default, it makes hard links; with the -s option, it makes symbolic (or soft) links. A hard link is another name for an existing file. 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. Use the ln command to make a hard link and view the details and inode information of the target and hard link file. When creating hard links, each target must exist.

$ ls -li
138876 -rw-r--r-- 1 mihael mihael 0 Mar 4 02:24 file
$ ln file hardlinkname
$ ls -li
138876 -rw-r--r-- 2 mihael mihael 0 Mar 4 02:24 file
138876 -rw-r--r-- 2 mihael mihael 0 Mar 4 02:24 hardlinkname


Symbolic links are a special file type in which the link file actually refers to a different file, by name. Unlike hard links, soft links can be linked to directories. Create a symbolic link and view the details of both files.

$ ls -li
138876 -rw-r--r-- 1 mihael mihael 0 Mar 4 02:44 file2
$ ln -s file2 symlinkname
$ ls -li
138876 -rw-r--r-- 1 mihael mihael 0 Mar 4 02:44 file2
138877 lrwxrwxrwx 1 mihael mihael 5 Mar 4 02:45 symlinkname -> file2


One of the benefits of using hard links is that every file name for the file content is equivalent. If you have five files hard linked together, deleting four of these files would not result in deleting the actual file contents. Symbolic links, however, have a single point of failure: the original file. The data will fail if the original file is deleted. Symbolic links can link to any file and directory.