Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've noticed that I can actually Shift-Delete (ie. doesn't go to Trash) a video which is currently playing, and it still keeps on playing, even though there is no named reference to it in nautilus or ls (terminal).

Is the disk-space freed normally when the player has finished with the video?

I assume it is normal behaviour, but it is certainly a new experience for me (as this was simply not possible in Windows).

share|improve this question

2 Answers 2

up vote 9 down vote accepted

Although you've deleted it, the file is still in use because you have it open in your player. Once you close the media player, it will release its handle on the file data and will therefore be deleted.

You can verify this with the lsof command, which lists open files. If you run lsof, your movie file should be listed as being open by the player, but it will have "DEL" next to it which means it has been deleted even though it is still open.

This is actually all a useful thing and would mean you could actually recover open files that you've deleted, although that would probably be best left to another question :)

It comes about because (as I understand) files consist of the data itself, and handles (location in the filesystem) to the file. Normally you only have a single handle for a file, but you can create others using the ln command to create a hard link. This creates what appears to be an identical copy of your file but is actually just adding another handle - so you haven't used twice the disk space. You can check this by looking at the inode of the two files - this tells you where the data actually is.

So e.g. in a terminal window:

ln existing_movie.avi movie_hardlink.avi

ls -i

The -i argument to ls shows the inode information for files - they should be identical.

When you delete one of those files, the data will remain because the other one still retains a handle to the inode. Once you delete the second file, the inode has no remaining handles/references and so is deleted/marked as unused space. This is directly analogous to the case when your player has the movie open, except that the second handle here is within the running program rather than a second file in the filesystem.

share|improve this answer
    
Okay! Nicely explained.. and yes I saw the DEL ("deleted" in my case) in lsof | grep video.avi .. Thanks Roger. –  Peter.O Nov 17 '10 at 13:41

read http://linuxgazette.net/105/pitcher.html, you will understand why (and learn the difference between hard and soft links)

share|improve this answer
    
A good article .. thanks –  Peter.O Nov 17 '10 at 13:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.