LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   zero length file entry (https://www.linuxquestions.org/questions/linux-newbie-8/zero-length-file-entry-4175495131/)

sryzdn 02-16-2014 11:29 AM

zero length file entry
 
Hi,

I am reading a text, it says:

Quote:

In the following command:
Quote:

ls -laU>file
the entry for file in the output gives zero length.
Could anyone explain what this "zero length" mean?

jailbait 02-16-2014 12:33 PM

Zero length means that ls found nothing to list.

------------------
Steve Stites

business_kid 02-16-2014 12:34 PM

It's a name with a zero length file (not) attached. It's ok, linux is cool with that. If you don't want the name, you can usually delete it.

An example of where it is used is downloads. A zero length file is written
my_download.mp4
the file is actually downloaded to my_download.mp4.part and moved to the proper filename when it's complete.

sryzdn 02-22-2014 11:37 AM

Quote:

Originally Posted by sryzdn (Post 5118746)
Hi,

I am reading a text, it says:

Quote:

In the following command:
ls -laU>file
the entry for file in the output gives zero length.


Could anyone explain what this "zero length" mean?

I have not yet got the answer. If there are files in the directory, ls -laU will list the names of the files and >file will print the list in "file". Why should there be any notion of "zero length" file here?

rknichols 02-22-2014 11:59 AM

The file will have zero length initially. Until ls has generated enough buffered output to cause a write (the buffer will typically be 4KB), the file will still have zero length. I suspect that ls generates all the output and sorts it before writing anything, so the file will show as zero length.

jpollard 02-22-2014 12:03 PM

Quote:

Originally Posted by sryzdn (Post 5122857)
I have not yet got the answer. If there are files in the directory, ls -laU will list the names of the files and >file will print the list in "file". Why should there be any notion of "zero length" file here?

First, the "file" is created by the shell before the "ls" command is executed. As a newly created file, it gets a zero length because no data is in the file...

Second, the data that will be put in the file is still in memory - it is all buffered in the application.

Now, if the directory has a LOT of files, (and this file is near the end of the list) you will see a non-zero length - but it still will not be complete until the last buffer is written.


All times are GMT -5. The time now is 11:00 PM.