6

Weird question, but here's the context. I was playing a video in VLC on Ubuntu 16.04. I accidentally deleted the video while I was still playing it. I can still move to any point on the video stream in VLC and play it, but the physical file is deleted from the disk.

Is there a way to recover this cache? I still have VLC open.

Edit per comments:

lsof | grep vlc | grep dvgrab

returns

vlc       2671           peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2674      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2676      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2677      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2686      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2689      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2692      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2694      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2695      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2696      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2697      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2698      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2699      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
vlc       2671 2700      peter   31r      REG               0,40 1048560000         45 /mnt/server/Vid projects/2017/01 January/22 Home/dvgrab-003.dv (deleted)
  • All I can say is keep the video playing, once it stops, the cache is deleted. I have been in the same position before where I rename a playing file, the playback goes till end then stops. – Parto Jan 26 '17 at 16:13
  • 3
    As long as the file is in use it will not be really deleted, but removed from the directory. The inode of the file is still in use. You may find the inode number by issuing lsof | grep vlc; this will show a file with no name and the message (deleted) instead. The inode number is the number in front of that. You can then relink the file to the directory with ln <inode#> <filename>. – ridgy Jan 26 '17 at 16:32
  • 1
    @rigdy, I've included the output from the grep. Where is the inode number? (Forgive my ignorance!) – anonymous2 Jan 26 '17 at 16:38
  • 3
    The inode is 45(the number in front of the file path). But I just realized that lndoes not work on inodes (could not get it to work..). But as you see that the file is used by vlc, filedescriptor # 31 (see 31r before REG), you could do cat /proc/2671/fd/31 > file_to_save, which will copy the content to a new file. 2671is the process # of vlc (number after vlc). – ridgy Jan 26 '17 at 16:48
  • 1
    @ridgy, it worked. Post as an answer and I'll accept as soon as I have opportunity. – anonymous2 Jan 26 '17 at 17:00
1

As @ridgy so helpfully pointed out in the comments:

As long as the file is in use it will not be really deleted, but removed from the directory. The inode of the file is still in use. You may find the inode number by issuing lsof | grep vlc; this will show a file with no name and the message (deleted) instead. The inode number is the number in front of that. You can then relink the file to the directory with ln <inode#> <filename>.

And later on:

The inode is 45 (the number in front of the file path). But I just realized that ln does not work on inodes (could not get it to work..). But as you see that the file is used by vlc, filedescriptor # 31 (see 31r before REG), you could do cat /proc/2671/fd/31 > file_to_save, which will copy the content to a new file. 2671 is the process # of vlc (number after vlc).

And, indeed, running

 cat /proc/2671/fd/31 > file_to_save

grabbed the file and stored it to my hard drive. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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