5.4 Special Directories and Files
5.4 Special Directories and Files
Weight: 1
Description: Special directories and files on a Linux system including special permissions.
Key Knowledge Areas:
Using temporary files and directories
Symbolic links
The following is a partial list of the used files, terms and utilities:
/tmp/, /var/tmp/ and Sticky Bit
ls -d
ln -s
Introducing links
On a storage device, a file or directory is stored in a collection of blocks. Information about a file is held in an inode, which records information such as the owner, when the file was last accessed, how large it is, whether it is a directory or not, and who can read from or write to it.
A directory entry contains a name for a file or directory and a pointer to the inode where the information about the file or directory is stored.

The inode number is unique within a particular filesystem.
-iswitch print the index number of each file
Whats is link ?
A link is simply an additional directory entry for a file or directory, allowing two or more names for the same thing.
There are two types of links : Hard Link (LPIC1) and Soft Link.
Soft link
a soft link or symbolic link is a directory entry that points to an inode that provides the name of another directory entry. Symbolic links are also called symlinks.

Creating links
ln
ln command with the -s option creates soft links. Soft links use file or directory names, which may be relative or absolute. If you are using relative names, you will usually want the current working directory to be the directory where you are creating the link. Otherwise, the link you create will be relative to another point in the file system.
If both the
FILEandLINKare given,lnwill create a link from the file specified as the first argument (FILE) to the file specified as the second argument (LINK).If only one file is given as an argument or the second argument is a dot (
.),lnwill create a link to that file in the current working directory . The symlink will have the same name as the file it points to.
By default, on success, ln doesn’t produce any output and returns zero.
Creating Symlink To a File
To create a symbolic link to a given file, open your terminal and type:
example:
To verify that the symlink was successfully created, use the ls -l command:
The l character is a file type flag that represents a symbolic link. The -> symbol shows the file the symlink points to.
Creating Symlinks To a Directory
The command for creating a symbolic link to a directory is the same as when creating a symbolic link to a file. Specify the directory name as the first parameter and the symlink as the second parameter.
For example, if you want to create a symbolic link from the /mnt/my_drive/movies directory to the ~/my_movies directory you would run:
Overwriting Symlinks
If you attempt to create a symbolic link that already exists , the ln command will output an error message.
To overwrite the destination path of the symlink, use the -f (--force) option.
Removing Symlinks
To delete/remove symbolic links , use either the unlink or rm command.
The syntax of the unlink is very simple:
Removing a symbolic link using the rm command is the same as when removing a file:
No matter which command you use, when removing a symbolic link do not append the / trailing slash at the end of its name.
Removing soft link doesn't affect anything but removing original file, the link becomes "dangling" link which points to nonexistent file.
If you delete or move the source file to a different location, the symbolic file will be left dangling (broken) and should be removed.
sticky bit
The Linux sticky bit is a special directory permission preventing users from deleting or renaming files they don't own, even if they have write access to the directory, making it an "append-only" folder. It's commonly used on /tmp to let many users write files, but stop them from deleting others' files, represented as a 't' in ls -l output (e.g., rwxrwxrwt).
We can see if a directory contains the sticky bit permission by running the ls command to check the directory’s permissions:
As we can see from the output, the /tmp directory contains permissions rwxrwxrwt. You should be used to seeing the read, write, and execute permissions – represented by r, w, and x, respectively – but the t at the end of those permissions indicates that this directory has sticky bit permissions.
Why Do We Need the Sticky Bit Permission?
There are certain directories on Linux which many users need access to. In order to grant users full access to a directory, they will need read, write, and execute permissions. This is true for the case of directories like /tmp, where many users (including non human system user accounts) write temporary data to. However, at the same time, we do not want other users interfering with the files of other users in that directory. This is the kind of niche scenario where the sticky bit becomes useful.
For this reason, there is a need for some mechanism to prevent users who do not own the directory or the actual files within the directory from renaming or removing another user’s files. This mechanism is called “Sticky Bit”. Sticky bit only allows root, directory owner and file owner to rename and delete files.
How to Set Sticky Bit Permissions
Setting the sticky bit permission on a Linux directory is very simple and can be done using the chmod command.
that's all.
You can start studying my LPIC-1 book: https://borosan.gitbook.io/lpic1-exam-guide/
.
.
.
sources:
https://app.gitbook.com/o/s9nDBEc3KAeK4VdvtgS3/s/ohrzk4YVVEIEOw3rrQKr/~/edit/~/changes/87/5.4-special-directories-and-files https://linuxize.com/post/how-to-create-symbolic-links-in-linux-using-the-ln-command/ https://linuxconfig.org/explaining-the-sticky-bit-what-the-t-in-linux-directory-permissions-means
Last updated
