Linux file management system (soft and hard links)

index node inode (index node)

We know that files have file names and data, which are divided into two parts on Linux: user data and metadata. User data, the file data block (data block), the data block is where the real content of the file is recorded; and metadata is the additional attributes of the file, such as file size, creation time, owner and other information. In Linux, the inode number in the metadata ( inode is part of the file metadata but does not contain the file name, the inode number is the inode number, and the inode stores the file creation time (ctime), modification time (mtime), Information such as file size, owner, user group to which it belongs, read and write permissions, and the block number where the data is located ) is the unique identifier of the file rather than the file name. The file name is only for the convenience of people's memory and use, and the system or program searches for the correct file data block through the inode number.

  • In the file system, each file has a specific inode
  • Can be multiple filenames pointing to an inode (hard link)
  • Use the ls -i command to view the inode corresponding to each file or directory
    $ ls - li
    total 12 
    809433 drwxrwxr-x   2 eko eko 4096 May   6  13 : 12 abc
     812347 -rwxrwxr -x   1 eko eko   873 May   6  08:48 admin . sh 812326 -rw-rwxr - + 1 eko eko    21 May   4 20 : 56 facl.txt
     

     

hard link

Add one more inode for the same data, two inodes point to the same data

How to use: Hard link (entity link) ln source target

eg: Create a hard link to admin.sh in the current directory to ./abc/admin.sh

ln ./admin.sh ./abc/admin.sh

At this point we view the file information

$ ls - li
total 4 
812347 -rwxrwxr -x 2 lessons learning 873 May   6  08 : 48 admin. sh

We can see that the number of times the file is referenced is 2, and the two file names point to the same inode

Hard links have the following notes

  • Can only be created on files, not on directories
  • cannot span filesystems
  • Creating hard links will increase the number of times the file is linked

 

symbolic link (soft link)

The role of a symbolic link is similar to a shortcut in Windows, creating a file name that points to the original file

How to use  : ln -s source target

eg: Create a soft link to facl.txt in the current directory to ./abc/facl.sh

$ ln -s ./facl.txt ./abc/facl

 Switch to the abc directory to view the soft connection of the new number

lrwxrwxrwx 1 eko eko   10 May   6 13:30  facl - > ./facl.txt

Through the ls -li command, we can see that the inodes pointed to by the two file names are different

 

Soft connection precautions

  • Can be applied to catalogs
  • can span filesystems
  • Does not increase the number of links to linked files
  • Its size is the size of the string contained in the specified path

 

In addition, two commands to view disk space are introduced.

du view space 

The du command also checks the space used, but unlike the df command, the Linux du command checks the space used by the file and directory disk, and it is somewhat different from the df command.

du [options] [files]

Options

-a or -all Display the size of individual files in the directory.
-b or -bytes Display directory or file size in bytes.
-c or --total In addition to displaying the size of individual directories or files, also display the sum of all directories or files.
-k or --kilobytes Output in KB (1024bytes).
-m or --megabytes Output in MB.
-s or --summarize Display only totals, only the last summed values.
-h or --human- readable Use K, M, G as units to improve the readability of information.
-x or --one - file - xystem is based on the file system at the beginning of processing, if it encounters other different file system directories, it will be skipped.
-L<symlink> or --dereference<symlink> Displays the source file size of the symlink specified in the options.
-S or --separate -dirs Display the size of an individual directory without the size of its subdirectories.
-X <file> or --exclude-from=<file> Specify a directory or file in <file>.
--exclude=<directory or file> Skip the specified directory or file.
-D or --dereference- args Display the source file size of the specified symlink.
-H or --si Same as the -h parameter, but K, M, G are in 1000 units.
-l or --count-links Repeats the count of hardware linked files.

Example:

#View the size of all files and directories in the current directory and its subdirectories
$ du -ah #Specify 
to view the size of the admin.sh file in the current directory
$ du -h ./admin.sh

 

df shows usable disk space on disk partitions. The default display unit is KB

 

df (options) (parameters)

 

-a or --all : include all file systems;
 --block-size=<block size> : display the number of blocks with the specified block size;
 -h or --human- readable: with readability A higher way to display information;
 -H or --si: the same as the -h parameter, but it is calculated in 1000 Bytes instead of 1024 Bytes;
 -i or -- inodes: Display inode information;
 - k or -- kilobytes: specify a block size of 1024 bytes;
 -l or -- local: display only the local file system;
 -m or -- megabytes: specify a block size of 1048576 bytes;
 --no- sync : Do not execute the sync command before getting the disk usage information, this is the default value;
 -P or -- portability: Use the POSIX output format;
 --sync : Execute the sync command before getting the disk usage information;
 -t <file system type> or --type=<file system type> : only display the disk information of the specified file system type;
 -T or --print- type: display the type of the file system;
 -x<file system type> or - -exclude-type=<filesystem type>: Do not display disk information of the specified file system type;
 --help: Display help;
 --version : Display version information

Example:

[root@LinServ-1 ~]# df -h
File system capacity used free used % mount point
 /dev/sda2 140G 27G 106G   21 % /
/dev/sda1             996M   61M  884M   7% /boot
tmpfs                1009M     0 1009M   0% /dev/shm
/dev/sdb1             2.7T  209G  2.4T   8% /data1

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325521014&siteId=291194637