Learning record 006-file deletion principle and related knowledge points

Source: Internet
Author: User
Tags create directory

The file deletion principle has the following three points:
1. File system reclaims the Inode, or is covered by the gods can not find back
2. Delete all hard links (I_nlink equals 0)
3. The service process does not read the Inode (i_ count equals 0)

Linux is through the number of link to control the deletion of files, only if a file does not exist any link, the file can be deleted, the general file has two link a i_count and a i_nlink
The meaning of I_count is the number of users (or calls) of the current file, and I_nlink is the reference counter for the disk
When a file is referenced by a process, the corresponding I_count number is incremented. When you create a hard link to a file, the corresponding I_nlink increases

For the Delete command RM, the actual reduction is the disk reference count I_nlink. There is a problem here, if a file is being called by a process and the user is performing an RM operation to delete the file, what will happen? When the user performs an RM operation to delete a file and then executes the LS or other file management commands, the file can no longer be found, but the process of invoking the deleted file continues to execute normally and the content can be read and written correctly from the file. Why is that?

This is because the RM operation only reduces the file I_nlink, if there is no other link i_nlink is 0, but because the file is still referenced by the process, so the file corresponding to the I_count is not 0, so even if the RM operation, but the system does not really delete the file, When only I_nlink and I_count are 0, the file is actually deleted. That is, you also need to dismiss the process's call to the file.

Below to simulate the real scene, if the disk is almost full, how do you deal with it? (with the principle of file deletion)
Install httpd Web Service
Yum install httpd-y
/etc/init.d/httpd start
/etc/init.d/iptables stop
CD/ etc/httpd/httpd.conf//Edit config file, enter 5223GG in this page to find Customlog/app/log/accedd_log combined, bold font for modified path, log will be stored in the face, after exiting with grep "/app/log"/httpd.conf to see if the correct
[[[email protected] ~]# dd if=/dev/zero OF=/DEV/SDC bs=8k count=10//Create a new disk
10+0 Records in
10+0 records out
81920 bytes (kB) copied, 8.4851e-05 s, 965 MB/s
ls-l/DEV/SDC
mkfs-t ext 3/DEV/SDC
Mount-o-loop/dev/sdc/app/log
Restart the httpd service to ensure that the log is logged to the/app/log file with the
Access site 100,000 commands: for n in ' seq 10000 ';d o Curl-s 10.0.0.27 >/dev/null;done Write the disk full
write so much, also to simulate the real scene, if the disk is almost full, you delete the rm-rf/app/log/accedd_log after using df-h The command view is still unchanged, what should you do with it?
You just need to restart the service to solve this problem


4. Head of household, user group
Linux is a multi-user, multi-tasking operating system
User role segmentation, roles are identified by UID and GID
GID is GroupID, which is the group ID that identifies the unique identifier for the user group
UID is userid, which is the user ID, which identifies the unique identifier for each user
Extended:
User groups: Set the same class of users to the same group, such as all system administrators can be set to the Admin group, easy to assign permissions, set some important files to all the Admin group users can read and write, so that permissions can be assigned.
Each user has a unique user ID, and each user group has a unique group ID
Superuser root UID and GID are all 0 with the command ID root view

Normal User: Only have the permission to operate the files and directories in their home directory, for the General User License (sudo) UID starting from 500
Virtual User: With the real ordinary users to differentiate, install the system by default, most of the situation can not log in, it is not chicken ribs? No, they can be easily managed by the system. Its UID is mostly in the 1-499
Awk-f ":" ' {print $ ' "$/etc/passwd} ' can view UID and user
The switch between users depends on the. bash_logout. Bash_profile. BASHRC if not, use SU-STT time, will prompt-bash-4.1$
Can be found in Etc/skel using Ls-a to find out the hidden


User groups: Multiple users belong to multiple different groups of users

5. Ls-l--full-time//can display the full time
Ls-l--time-style=long-iso//can display time in full
270260 Drwxr-xr-x. 2 Root2 root2 4096 June 19:06 Videos/. On behalf of SELinux Open


6. Permissions for the file
rwx rwx rw-permissions correspond
Primary (owner) read Read Write writes execute 0
Group (Group)
Other file (other)
-delegate no permissions
to pay special attention to: Execute mkdir/com/123.txt-p, create directory and file
to delete 123.txt, you have to go through his boss permission, that is rwx have or chown user Master/com change User master chmod if you want all files or subdirectories to change at the same time, Need to use the-R parameter (recursive)
chmod u+r,g+r,o+r 1.txt//To user master, user group, other user plus readable permission equals chmod a+r 1.txt all
chmod o=rwx 1.txt//equals sign clear In addition to the original permissions, what is followed, change into what
WIN32 executable: *.exe,*.bat,*.com
Linux executable: *.sh,*.py,*.perl, etc.

[email protected] ~]$ Touch 11[[email protected] ~]$ ls-li 11134891-rw-rw-r--. 1 root2 root2 0 June 05:56 11[[email protected] ~]$ mkdir 111[[email protected] ~]$ ls-ld 111drwxrwxr-x. 2 Root2 root2 4096 June 05:56 111[[email protected] ~]$ Su-password:[[email protected] ~]# touch 11[[email protected] ~ ]# Ls-li 11141211-rw-r--r--. 1 root root 0 June 05:57 11[[email protected] ~]# mkdir 111[[email protected] ~]# ls-ld 111drwxr-xr-x. 2 root root 4096 June 27 05:57 111

The above experiment will tell you that the permission to create a directory under the root user is 755 files 644
Normal User directory Permissions 775 file is 664
Change the system's default permissions Umask value decision (hardly to move it)
UMASK=022 is 666-022=644
umask=021 666-021=643 643+001=644//in odd digits plus one


7. Change the document owner, belong to the group
[Email protected] kak]# chown Root2 1.txt
[Email protected] kak]# Ls-li
Total 4
521237-rwxr-x-w-. 1 Root2 Root 6 June 00:19 1.txt
[Email protected] kak]# chown. Root2 1.txt//. Root2 or: Root split
[Email protected] kak]# Ls-li
Total 4
521237-rwxr-x-w-. 1 Root2 root2 6 June 00:19 1.txt
There is a special case where the owner of the file after the deletion of the user is a number
In this case, increase chmod kk-u//-u is to set the UID if not added starting from 501

8. Simple command Accumulation
Chattr +i 1.txt//Lock +a can only Wang inside add, cannot delete
Lsattr 1.txt//view files

Isof-i: 80 equivalent to Netstat-lnt|grep 80//view port What services are turned on

9. If create file Tmp/1.txt, want to delete 1.txt, how to deal with?

Is the step to read the 1.txt file

First want to remove 1.txt, the most easy to enter the misunderstanding is directly to the 1.txt operation

Can you delete, you have to look at the permissions of the top level 1.txt directory

We start from the reading of the file, to open the 1.txt file, then we need to first read the data from the root directory, like playing the game customs, want to live here, left to buy the road money

After a few levels, leaving the money everywhere, then the 1.txt buy road money by the/tmp directory to control, to see the last Hello World

Therefore, changing the permissions in other in/TMP can achieve the purpose

Related blog: http://blog.sina.com.cn/s/blog_3edf6ca20100qvif.html

Learning record 006-file deletion principle and related knowledge points

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.