Linux file attributes related supplements and soft and hard connections

Source: Internet
Author: User
Tags disk usage python script

1th. File properties related to 1.1 file property 1.1.1 Extension

Windows distinguishes between different types of files by extension

Linux extensions are for human viewing convenience we distinguish between different types of files

. conf configuration file

. SH Script

. tar.gz Compression Pack

. py Python Script

[[Email protected]/tmp]#ll etc.tar.gz View Compression pack information-rw-r--r--1 root root 9734648 Jul 20 01:41Etc.tar.gz[[email protected]-LNB/TMP]#MV etc.tar.gz etc.txt Renaming a compressed package[[Email protected]-LNB/TMP]#ll etetc/etc-pai.tar.gz etc.txt ethers [[email protected]-LNB/TMP]#ll etc.txt View information-rw-r--r--1 root root 9734648 Jul 20 01:41Etc.txt[[email protected]-LNB/TMP]#tar tf etc.txt can be opened as well##证明Linux系统下 Changing the extension does not affect the use of

Types of 1.1.2 Files

F File files

D dir Directory

L Softlink Soft Connection

B Block Blocks Equipment

C Character character device

P Pipe Piping

s socket socket

[[Email protected]/tmp] # file  /bin/ls/etc/hosts/tmp/etc-pai.tar.gz##file可以查看文件的详细类型/bin/ls:              for Gnu/linux 2.6.18, stripped/etc/hosts:          ASCII textfrom Unix, last Modified:fri Jul 20 02 : 39:55 2018#######         file 1. Binary(command)2. text File3. Data file requires a separate command to view

1.2 File system

1. Disk (House)

2, partitions (partition)

3. Format to create file system (decoration)

4. Mount (Install doors and windows)

5. Store documents (live persons)

1.3 Permissions under Linux

For a file, users in the system are divided into: The owner of a Stranger

Owner User Group Others

R----Read Readable 4

W----Write writable 2

X----Execute executable 1

-0

1.4 User-related files

/ETC/PASSWD Information for users

/etc/shadow User's password information

/etc/group User Group Information

Password for the/etc/gshadow user group ()

The meaning of each column under 1.4.1/ETC/PASSWD
Root     : x             : 0     : 0      : Root             :/root           :/bin/bashnobody   : x             :     : £ ©: Nobody           :/               :/sbin/nologinclsn     : x             :$:                 £/home/clsn      :/ bin/Bash user name   original password location  UID   GID    User's description information     user's home directory     command interpreter

1.4.2 Command interpreter 1.4.2.1 the default command interpreter

/bin/bash default

/sbin/nologin Unable to login system-Virtual user

1.4.2.2 Other command interpreters
[[Email protected] ~] # cat/etc/shells/bin/sh/bin/bash/sbin/nologin/bin/Dash/bin/tcsh /bin/csh
View Code

2nd Soft link and hard links

Links: Soft links (Softlink or symbolic links symlink) Hard link

2.1 Hard Links 2.1.1 Meaning

In the same partition, the inode number of the file is the same as the hard link

A hard link is the entrance to the file (front and rear doors of the supermarket)

2.1.2 Effect

Prevent accidental deletion of documents

2.1.3 How to create a hard link

The ln command, preceded by a link file created after the source file

[[Email protected] ~]#Mkdir/oldboy Creating an environment[[Email protected]-50 ~]#cd/oldboy/[[Email protected]-50 Oldboy]#Echo oldboyedu.com >>/oldboy/oldboy.txt[[Email protected]-50 Oldboy]#Cat Oldboy.txtOldboyedu.com[[email protected]-50 Oldboy]#LN oldboy.txt oldboy.txt.hard Creating a hard link[[Email protected]-50 Oldboy]#Ll-lhi Check created successfully two files inode number same Total8104523268-rw-r--r--. 2 root root 10 20:53Oldboy.txt523268-rw-r--r--. 2 root root 10 20:53Oldboy.txt.hard[[email protected]-50 Oldboy]#Cat Oldboy.txt What you seeOldboyedu.com[[email protected]-50 Oldboy]#Cat Oldboy.txt.hard What you seeoldboyedu.com View two files with the same inode number. [[email protected] CLSN]#Ls-lhi clsn.txt Clsn.txt-hard151273-rw-r--r--2 root root 607 30 09:13Clsn.txt151273-rw-r--r--2 root root 607 09:13 Clsn.txt-hard

2.2 Soft Connection 2.2.1 meaning

Most commonly used

For fast, convenient, easy to use

The location of the source file that corresponds to the shortcut that Windows holds

2.2.2 How to create a soft link

You cannot create a hard-link soft connection to a directory

[[email protected] Oldboy]#ln-s oldboy.txt Oldboy.txt-soft Creating a soft connection[[Email protected]-50 Oldboy]#ls-l Check whether the creation was successful Total8-rw-r--r--. 2 root root 10 20:53Oldboy.txt-rw-r--r--. 2 root root 10 20:53oldboy.txt.hardlrwxrwxrwx.1 root root ten 21:13 Oldboy.txt-softOldboy.txt Create a successful use absolute path to create the displayed information is also the absolute path relative path creation displays is relative path [[email protected]-50 ~]#ln-s/oldboy/oldboy.txt/oldboy/oldboy.txt.1[[Email protected]-50 ~]#ls-l/oldboy/ Total8-rw-r--r--. 2 root root 10 20:53oldboy.txtlrwxrwxrwx.1 root root 21:16 oldboy.txt.1-/oldboy/oldboy.txt source file disappears (move rename delete etc.) view information the source file for the soft connection will turn red (white on red)

2.3 File Deletion principle

The number of hard connections is 0

The number of process calls is 0 whether someone is using

2.4 How to view the files that are occupied

Lsof (list open files) displays all the files that are occupied

Simulation Environment

Xshell Open two windows                |  -f/oldboy/oldboy.txt viewing process [[email protected]-lnb/oldboy]#  lsof |grep oldboy.txt Tail             3755    root    3r      REG         8,3      1046996  /oldboy/oldboy.txt command or service name                                                        file size    inode Number file name

2.5 The difference between a soft connection and a hard link 2.5.1 created

The ln command creates a hard link, ln-s creates a soft link

2.5.2 meaning

A hard-link file in the same partition is the same as the Inode node number of the source file. A soft link file is equivalent to a shortcut to Windows (the Inode number differs from the source file)

2.5.3 Features

You cannot create a hard link to a directory, but you can create a soft link, and a soft link to the directory is often used

Soft connections can cross file systems, hard links can not cross file systems

2.5.4 source file Soft connection hard link and delete

Delete soft connection files, no effect on source files and hard link files

Remove hard-link files from files without any effect on source files and soft-connect files

Delete the source file of the connection file, no impact on the hard-link file, will cause its soft connection failure (red on white)

Delete the source file and the hard link file at the same time, the whole file will be "really" deleted

2.6 File Deletion but space not released case

Impersonation: The file is not completely removed (I_link) to 0 process calls (I_count) not 0

Not completely removed-the number of hard links is 0, the number of process calls is not zero

/var/log/messages

[[email protected] Oldboy]#df-h df-h to view disk usageFilesystem Size used Avail use%mounted on/dev/sda3 19G 6.1G 12G 35%//use up to tmpfs 491M 0 491M 0%/dev/SHM/DEV/SDA1 190M 35M 146M 19%/Boot[[email protected]-50 Oldboy]#du-sh/* |sort-h use DU-SH/* Layer to troubleshoot[[Email protected]-50 Oldboy]#du-sh/var/* |sort-h Troubleshooting Process[[Email protected]-50 Oldboy]#du-sh/var/log/* |sort-h Find the most space-occupying[[Email protected]-50 Oldboy]#\rm-f/var/log/messages Confirm no use and then delete[[Email protected]-50 Oldboy]#df-h after deletion check discovery space is not releasedFilesystem Size used Avail use%mounted on/dev/sda3 19G 6.1G 12G 35%/has not been released Tmpfs 491M 0 491M 0%/dev/SHM/DEV/SDA1 190M 35M 146M 19%/boot [[email protected]-50 Oldboy]#lsof |grep messages use lsof to see if a file is being calledRSYSLOGD1247 Root 1w REG 8,3 4888993470 135456/var/log/messages (deleted) Deleted lsof token indicates that the number of file hard connections is 0 process call not 0 [[email protected]-50 Oldboy]#/etc/init.d/rsyslog Restart Restart process[[Email protected]-50 Oldboy]#df-h to view disk usageFilesystem Size used Avail use%mounted on/dev/sda3 19G 1.5G 17G 9%/disk space released Tmpfs 491M 0 491M 0%/dev/SHM/DEV/SDA1 190M 35M 146M 19%/after the boot restart process/var/log/messages will be created again, but the space has been freed.

2.7 How to find a hard link through the inode number

Use the Find command-inum parameter to find the inode number and find the same inode as a hard link.

[[Email protected] ~] # ls-lhi  test.txt260141-rw-r--r--. 2 root root 265 19:16~] # Find/*-type f-inum 260141/root/test.txt/root/test.txt-hard

Linux file attributes related supplements and soft and hard connections

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.