4 ms·
Because sometimes I want to remove old and irrelevant lines in a logfile but want to retain the recent lines. > A file should be seen as a low-level data struc
by posix_me_less 7y ago
Because sometimes I want to remove old and irrelevant lines in a logfile but want to retain the recent lines.
> A file should be seen as a low-level data structure with a limited set of operations.
Why should? For many people, a file is a basic way to permanently store data. Changing the data at any point of the file should be easy.
- fjfaase 7y agoActually, most file systems let you randomly read and write to files. Usually, they implement this by reading and writing blocks (of 256 bytes or a multiple). One could create file systems with more advanced operations, but most likely, these will be based on the more primitive operations. For example, to add the function to remove 10 bytes from the start of the file, one could read the whole file, block-by-block, and move the data 10 bytes. For a large log file, this will take a long time. Another solution is to have a begin of file offset for all files, this means that some additional information need to be stored with every the file and that this information needs to be accessed with all file operations, resulting in some performance loss for all file operations. Existing programs that access files as blocks of a certain size, might see significant performance penalties when the offset is not a multiple of the block size, because reading the data from one block, needs to read two actual blocks from the underlying medium. If you often want to strip a logfile from old data, a solution might be to create new logfiles at a regular intervals and delete old logfiles. Or maybe even better, use a database to store the log messages. Gives you query functionality and allows you to perform more advanced operations, as removing certain types of log messages.