Linux reading Summary-File

Source: Internet
Author: User

1. The block number of the inode file. During the Linux kernel read and write operations, the corresponding disk block is operated based on the disk block number in the inode to complete file read and write. The MV command is used to move a file. Even if the file to be moved is large, it moves quickly because the MV command does not move the file content but changes the directory items of the file. This command creates a new directory item under the new directory and points it to the original file.

2. Use the link function in Linux to create a hard link. The function prototype is int Link (const char * path1, const char * path2). The first parameter is an existing file name, the second parameter is new.Directory item. Linux File System does not allow common users to create a linkDirectoryHard LinkThis may cause loop in the file system.The root user can create a link to the directory, but the loop should not occur.

3,Hard LinkOnly files in the same file system can be referenced. It references the physical index (inode) of files in the file system ). When you move or delete the original file, the hard link will not be broken because it references the physical data of the file rather than the position of the file in the file structure. A hard-linked file does not require the user to have the permission to access the original file or display the location of the original file. If the deleted file has a hard link, the file will still be retained until all references to it are deleted. (Each time you add a hard link counter + 1, find a hard link, counter-1, when the counter is 0, the file will be deleted)

4,Symbolic LinkIs a pointer pointing to the position of the file in the file system. Symbolic Links can point to files in a remote file system across file systems. The symbolic link only specifies the location of the original file. You must have access to the location of the original file to use the link. If the original file is deleted, all symbolic links pointing to it will be destroyed. They point to a location that does not exist in the file system. (Deleting a symbolic link does not delete the original file)

5. the stat function can obtain the turntable information of the directory file, and its permission limit is also stored in the st_mode member variable. You have the read permission on the directory to list the directory items in this directory; you have the write permission on this directory to create new files in this directory; you have the permission to execute this directory. You can pass through this directory to enlarge the subdirectories of this directory. That is to say, if you provide a path, the user must have the execution permission for each directory in the path to ensure that the path is available. This is often ignored. In fact, every directory should have the execution permission.

6. A directory is a special file.CompositionDirectory. The directory can also be opened, read/write, and located. You can delete or create files in a directory, but cannot perform write operations on the directory. Directory write operations are completely completed by the kernel proxy. Therefore, the write directory function interface is not provided in Linux.

7. Changing the working directory of a child process does not affect the parent process. If the CD command is implemented asProgramThe parent process is not affected. In this case, the CD command does not work. Therefore, in Linux, the CD command is not implemented as an independent program, but is implemented in Shell programs. Therefore, it cannot be called by a system such as system ("CD/usr") in a program.

8. The files in the/proc directory are the images of processes running in the system. Therefore, these files are only stored in memory . The proc file system is designed to provide users with a set of interfaces to access process kernel data. The proc file system is a pseudo file system, which only exists in the memory. You can use the LS-l command to view the file details and find that most of the files are the file size is 0 !. The proc file system is not a file system in the general sense. It is not only an access interface to the address space of the running process, but also an interface to access the kernel data. Users and applications can access files in the proc file system through Linux calls (such as open (), read (), write (), IOCTL () and other functions, to obtain the corresponding information. For example, a common PS program uses/proc to obtain the Process status. The path of the proc file system is/proc. You can run the LS command to view the files in this directory. A file is a subdirectory named after a number. This number is the process ID of the related process. These directories contain information about running processes. There is a "." file in the/proc file, and there is no "." file, because proc has no parent directory .

9. When the fclose function closes a file, the function writes the file content that has not been written back to the disk in the memory to the disk. It is important to understand this. If the fclose function is not called, you must wait for the buffer in the memory to be filled up and the system will write the content back to the disk. Many programmers are troubled by the need to check the return value of the fclose function. Although strictly speaking, all system call return values should be checked and error handling should be performed, the error probability of fclose function is very small, almost 0. however, if you close a remote file in a network environment, the fclose function may fail. Because the fclose function writes the buffer content back to the disk when closing the file, the fclose function actually performs a write operation. In the network environment, the content of a file is transmitted to the target host over the network and written to the disk. During the transmission process, if the network link is faulty or the data transmission fails, the file content writing will fail. In this case, an error occurs in the fclose function. If you close a file locally, you do not need to check the return value. If you close a file in the network environment, it is necessary to check the return value of the fclose function .

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.