Raspberry Pi_Eng_16.1.4 Special Directory and Special File


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


16.1.4  Special Directory and Special File

 

16.1.4.1    Hidden File

 

On Linux, directory or files that begin with a "." are considered hidden. These files are usually configuration files and temporary files that are created by various applications for various purposes. These are managed by assigning a hidden attribute in order to distinguish it from ordinary data and not to be seen in daily routine work.

 

However, if you use the appropriate option as needed, the hidden file can be viewed and used as a normal file. Please refer to [16.3.7 Checking Contents of Directory] for specific examples.

 

[Used Example]

The screen below shows a list of all the files, including the hidden files in the user account "pi" home directory. You can see that there are many files that start with ".".

 

pi@raspberrypi ~ $ ls a

.              .dbus        .gconf           .minecraft     .swp

..             Desktop      .gstreamer-0.10  .netsurf       testdata

ArchiveTest    .dillo       .gvfs            .profile       .thumbnails

.bash_history  .dmrc        .icons           .pulse         .vnc

.bash_logout   Downloads    .idlerc          .pulse-cookie  .WolframEngine

.bashrc        .fltk        Image            python_games   .Xauthority

.cache         .fontconfig  .local           .scratch       .xsession-errors

.config        .galculator  .Mathematica     .sonic-pi      .xsession-errors.old


 

16.1.4.2    Link File

 

In Linux, you can create another file that refers to a directory or file that already exists, which is called a link file. It only point to certain other directory or file that exists on the disk, and does not itself contain any data inside it

 

If you work with a link file in a command or program in the system, the command will be executed in the same way that you work with the original file, regardless of where the link file is located.

 

These link files may be in the same directory as the original file, but the effects are the same even if they exist in different directory.

 

Linux supports the following two kinds of link:

 

   Soft link creates a pointer file pointing to the actual location of the original file, and uses it to link to the original file. This soft link has all permissions for read, write, and execute, but the permissions on the original file do not apply to the permissions of the link file. It acts like a "shortcut" or "shortcut" used in ms windows.

 

   Hard link, like a soft link, has pointer information that points to the original file, but what is represented externally is indistinguishable from a regular file. So if you create a hard link for a particular file, it will be treated as if there are two names for one file. However, there is a limitation that these hard links can only be used in a single file system.

 

From the overall point of view of system management, hard links can be confused because they are not distinguishable from the original files, and they can only be used in a single system. To avoid administrative confusion and to share link information in multiple file systems, It is better to use soft link.

 


 

16.1.4.3    "ln" Command

 

When creating a link file in the system, use the "ln" command, and the detail usage is as follows.

 

[Command Format]

ln    [OPTION]   <source-directory/file>     <link-directory/file>

 

[Command Overview]

   This creates a link to an existing directory or file.

   User privilege          -- Normal user.

 

[Detail Description]

   None

 

[Main Option]

--help

display this help and exit

-s, --symbolic

make symbolic links instead of hard links

 

 

 

[Used Example]

The following screen shows an example to create a soft link and a hard link to "DebianManual.txt" file included in "testdata" directory, and and inquire contents.

 

pi@raspberrypi ~/testdata $ ls l

-rw-rw---- 2 pi pi   80 Apr 12 15:12 DebianManual.txt

drwxr-xr-x 3 pi pi 4096 Apr 11 02:17 TestFolder01

drwxr-xr-x 2 pi pi 4096 Apr 10 13:32 TestFolder02

-rw-rw---- 1 pi pi   81 Apr 11 09:03 user_guide01.txt

pi@raspberrypi ~/testdata $ link s DebianManual.txt DebianManual-softlink

pi@raspberrypi ~/testdata $ link    DebianManual.txt DebianManual-hardlink

pi@raspberrypi ~/testdata $ ls l

total 20

-rw-rw---- 2 pi pi   80 Apr 12 15:12 DebianManual-hardlink

lrwxrwxrwx 1 pi pi   16 Apr 12 14:59 DebianManual-softlink -> DebianManual.txt

-rw-rw---- 2 pi pi   80 Apr 12 15:12 DebianManual.txt

drwxr-xr-x 3 pi pi 4096 Apr 11 02:17 TestFolder01

drwxr-xr-x 2 pi pi 4096 Apr 10 13:32 TestFolder02

-rw-rw---- 1 pi pi   81 Apr 11 09:03 user_guide01.txt

 

If you look up the contents of each file, you can see that the same contents are retrieved.

 

pi@raspberrypi ~/testdata $ cat DebianManual.txt

This is user guide for RaspberryPi system.

You can read this guide at any time.

pi@raspberrypi ~/testdata $ cat DebianManual-softlink

This is user guide for RaspberryPi system.

You can read this guide at any time.

pi@raspberrypi ~/testdata $ cat DebianManual-hardlink

This is user guide for RaspberryPi system.

You can read this guide at any time.

 

If you check the above result data, you can see that for the soft link, the first leftmost character indicating the file type displays the letter "l", meaning link, and the right file name shows the original file name.

 

However, when I look at the contents of the hard link, the file type is displayed the same as that of a original file, and the the original file is not displayed in file name, so the file does not show any link information at all.