Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

File manipulation in 1.linux

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

File operations in 1.linux 1.File operations in Windows in windows, when we manipulate a file, there are the following situations

1.1 first we will specify the directory or path where the file we want to operate is located.

1.2 enter the appropriate path and check whether the file exists when you manipulate a specific file

1.3 create a file when it does not exist

1.4 when a file exists, you can open the file and take appropriate actions.

1.5 when the file operation is complete, close the file

2. What about the file operation in linux? What are the similarities and differences between file manipulation in linux and windows system?

1.1 operates in the same way as the windows above

1.2 points to pay attention to when operating files in linux:

How do basic operation functions (open, close, read, write, lseek) files be opened (read-only, write-only, read-write) when a file needs to be opened for write operations, if there is content in the file, is the written content appended or overwritten? This involves O_APPEND and O_TRUNC. How do you create a file when the file you want to manipulate doesn't exist? Or is it possible to determine the existence of the file when the operating file exists? This involves O_CREAT (creating a file regardless of whether the file exists or not) and O_EXECL (reporting an error if the file exists when you need to create a file) how to exit the current process if something goes wrong during the operation? Use exit, _ exit, _ Exit to exit the current process. There are also two flags, O_NONBLOCK and O_SYNC

6.1 O_NONBLOCK is used for non-blocking access to device files (when there is a program that needs to access the device, if the current device is called by one program, other programs enter non-blocking access)

6.2O_SYNC, because the API of file operation provided by the linux operating system calls the application to read and write the file, but it is not written directly to the hardware of the block device (iNand, SD card) every byte or a small number of characters are written by the application, but only when the close file descriptor is written to the hardware storage device. If you add O_SYNC to the flag of write, you can write it directly to the hardware.

3. When a file is read in linux, it will not only read all the contents, but also read one more'\ n'.

4. When writing to a file in linux, if you use O_TRUNC when opening the file, the contents of the file will be emptied before writing. If O_APPEND is used when opening the file, the written content will be appended to the end of the original content (note: the new content will be appended first) 5. In linux, after opening the file writing content and before the file is closed, call the read function to read the file after writing content, and find that the read content does not match the written content. Refer to the following link content.

Solve the problem of reading garbled code or blank space immediately after writing a file under linux

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report