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

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.

-i switch print the index number of each file

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.

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.

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 FILE and LINK are given, ln will 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 (.), ln will 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.

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.

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:

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.

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:

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?

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.

if Sticky Bit set on a file does nothing but if is set on a direcotry only owner can delete files

that's all.

Congratulation we have done lpi Linux Essentials course !!! do not forget to give a star and donate :-)

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