
Here, the files prefixed with data-file are non-empty files and the ones prefixed with empty are empty files: |- data-file1 Let’s try to understand this with an example.Ĭonsider a directory that contains both empty and non-empty files and sub-directories. Then, we add the -delete option to delete all those files. type f -empty -print, will find all the empty files in the given directory recursively. String are usually disallowed at the user level if they don't make sense: a file name is a string, and most file systems do not allow an empty string as a file name internally, when creating file names from fragments, the program may well have an empty string as one of the fragments.This particular part of the command, find.
Most notably to strings, which are sequences of characters: Zero-length strings are commonplace inside of programs. In general, all of the above reasons except those related to file names apply to sequences. In the case of files, the "there is a file recorded somewhere" aspect (inode and/or file name) comes on top of the above considerations, but file systems would not do that if empty files were useless.
Reading from the file: programs need to deal with hitting the end of the file before they got what they expected, so again the case of a zero-length file does not involve extra thinking for the programmer: he'll just hit end-of-file from the beginning. Searching for a string in a file: this is covered by the standard case of "if the file is shorter than the search term, it cannot contain the search term". Concatenating files: this is just a no-op with an empty file. The git program (and others) tend to ignore empty directories, and if a project/administrator/user wants to have a record that the directory exists even though it has no useful content (yet), you may see an empty file named empty or empty.directory. This prevents overeager administrators from deleting empty directories after installation, and it also prevents bugs where a program or a user accidentally creates a file where the program would like to see a directory later. * Sometimes you see files where all the relevant text is in the file name, e.g. If the log file is empty, the number of errors is zero, which makes perfect sense. * To find out how many errors happened, you count the number of lines in the log files. * Error log files tend to be created empty, to be filled if and only if an error happens. Further complications arise if some other users created a file with that name in the mean time. Delete zero byte files program code#
Text editors that regularly make a backup would need special-case code to deal with the situation that the user might delete the last line, go to lunch, then come back and add another line.More practically, deleting the last line of a text file would need to be special-cased.
The same operation on a file that consisted of just "AAAAAAAAAAAAAAAAAAAA" would have to deal with the special case of a vanishing file.
If a file contains 20 letters "A", and you remove all "A"s, then the file will become 20 bytes shorter. Longer answer: It's defined that way because some operations are conceptually simpler: Simple answer: Because it's defined that way.