Purpose of  the lost+found folder:

  • This  directory  is for recovering files which are not properly closed due to many reason such as power failure.
  • The  lost+found   folder  contains the files with no links and files to be recovered.
  • Any file to be recovered is kept in this folder. fsck command (file system check) is used to recover these files.
  • In generally, the directory is empty; but if there is corruption, the conditions files can be recovered after fsck places them here.
  • The lost+found directory (not Lost+Found) is a construct used by fsck when there is damage to the filesystem (not to the hardware device, but to the fs).
  • Files that would normally be lost because of directory corruption would be linked in that filesystem’s lost+found directory by inode number.
  •  If  you lost directories or lost files or even lost devices. Each filesystem should have its own lost+found directory, but you influence be looking at a system with only one file system.
  • If you run fsck, the filesystem check and repair command, it find the data fragments that are not referenced anywhere in the filesystem. In particular, fsck might find data that looks like a complete file but doesn’t have a name on the system — an inode with no corresponding file name. This data is still using up space, but it isn’t accessible by any normal means.
  • The  fsck to repair the filesystem, it will back the deleted files into files. The device is, the file had a name and location once, but that information is no longer available. So fsck deposits the file in a specific directory, called lost+found (after lost and found property).
  • Files that appear in lost+found are typically files that were already unlinked (i.e. their name had been erased) but still opened by some process (so the data wasn’t erased yet) when the system halted suddenly (kernel panic or power failure). If that’s all that happened, these files were slated for deletion anyway.
  • Files can also appear in lost+found because the filesystem was in an inconsistent state due to a software or hardware bug. If that’s the case, it’s a way for you to find files that were lost but that the system repair managed to salvage. If  they do they may be incomplete or out of date; it all depends how bad the filesystem damage was.
  • On many filesystems, the lost+found directory is a bit special because it preallocates a bit of space for fsck to deposit files there. (The space isn’t for the file data, which fsck leaves in place; it’s for the directory entries which fsck has to make up.) If you accidentally delete lost+found, don’t re-create it with mkdir, use mklost+found .
[ad type=”banner”]

Example:

  • In lost+found folder you find more than 10000 folders with its name as some random number prefixed with # symbol. fsck has moved my files here in this structure while running .And ,you to identify the right directory and files and move them out of lost+found. So you run “file *” in lost+found to know the type of files. It lists some thing like
[pastacode lang=”bash” manual=”%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237479417%3A%20%20directory%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237479418%3A%20%20directory%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237479419%3A%20%20directory%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237602560%3A%20%20directory%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237603310%3A%20%20MPEG%20sequence%2C%20v2%2C%20program%20multiplex%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237603464%3A%20%20JPEG%20image%20data%2C%20JFIF%20standard%201.02%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237603542%3A%20%20Audio%20file%20with%20ID3%20version%202.3.0%2C%20contains%3A%20Audio%20file%20with%20ID3%20version%202.4.0%2C%20contains%3A%20MPEG%20ADTS%2C%20layer%20III%2C%20v1%2C%20320kbps%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2044.1%20%20%20kHz%2CJntStereo%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237604043%3A%20%20ISO%209660%20CD-ROM%20filesystem%20data%20’Linux%20Mint%209%20Isadora%20%20%20%20%20%20%20%20%20%20%20’%20(bootable)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237604089%3A%20%20ISO%209660%20CD-ROM%20filesystem%20data%20’netbook-x86_64-201005242312%20%20%20%20’%20(bootable)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237605425%3A%20%20MPEG%20sequence%2C%20v2%2C%20program%20multiplex%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237605470%3A%20%20MPEG%20sequence%2C%20v2%2C%20program%20multiplex%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237605484%3A%20%20MPEG%20sequence%2C%20v2%2C%20program%20multiplex%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237607478%3A%20%20gzip%20compressed%20data%2C%20from%20Unix%2C%20last%20modified%3A%20Fri%20May%2014%2007%3A55%3A35%202010%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237607788%3A%20%20gzip%20compressed%20data%2C%20from%20Unix%2C%20last%20modified%3A%20Tue%20May%20%204%2014%3A16%3A31%202010%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237610801%3A%20%20PDF%20document%2C%20version%201.4%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237612061%3A%20%20ISO%209660%20CD-ROM%20filesystem%20data%20’Ubuntu%2010.04%20LTS%20amd64%20%20%20%20%20%20%20%20%20’%20(bootable)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237613228%3A%20%20directory%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237613583%3A%20%20directory%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%237613588%3A%20%20directory%0A” message=”bash code” highlight=”” provider=”manual”/]
  • Then you filtered out all files except “directory” using “file * | grep directory > /root/list.dir” command.
  •  Edited /root/list.dir to make it as script to show the list of files in each directory with directory name. Here is a snippet of my script.
[pastacode lang=”bash” manual=”%20%20%20%20%20%20%20%20%20%20%20%20%20%20set%20-v%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ls%20-l%20%5C%2310104455%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ls%20-l%20%5C%2310104531%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ls%20-l%20%5C%2310104536%0A” message=”bash code” highlight=”” provider=”manual”/]
  • The “set -v” will help you to echo the command the shell execute. “chmod +x list.dir” to make it executable.
  • Now run the script in /home/lost+found folder, redirecting the output to /tmp/ (“./list.dir 1> /tmp/dir.out 2>&1“). Now search for your known file in dir.out output file. Now  searched for “Desktop” and found some thing like this..
[pastacode lang=”bash” manual=”ls%20-l%20%5C%237733249%0Atotal%205704%0Adrwxr-xr-x%202%201002%201002%20%20%20%204096%202010-06-05%2013%3A24%20Desktop%0Adrwxr-xr-x%202%201002%201002%20%20%20%204096%202010-04-30%2009%3A15%20Documents%0Adrwxr-xr-x%202%201002%201002%20%20%20%204096%202010-04-30%2009%3A15%20Downloads%0A-rw-r–r–%201%201002%201002%20%20%20%20%20179%202010-04-30%2009%3A14%20examples.desktop%0Adrwxr-xr-x%202%201002%201002%20%20%20%204096%202010-04-30%2009%3A15%20Music%0Adrwxr-xr-x%202%201002%201002%20%20%20%204096%202010-04-30%2009%3A15%20Pictures%0Adrwxr-xr-x%202%201002%201002%20%20%20%204096%202010-04-30%2009%3A15%20Public%0A-rw-r–r–%201%201002%201002%205794003%202010-05-15%2011%3A00%20scrap001_a.ora%0Adrwxr-xr-x%202%201002%201002%20%20%20%204096%202010-04-30%2009%3A15%20Templates%0A-rw-r–r–%201%201002%201002%20%20%20%201265%202010-05-20%2014%3A35%20tinda%20chuteny%0Adrwxrwxr-x%202%201002%201002%20%20%20%204096%202010-05-23%2014%3A57%20Ubuntu%20One%0Adrwxr-xr-x%202%201002%201002%20%20%20%204096%202010-04-30%2009%3A15%20Videos%0A” message=”bash code” highlight=”” provider=”manual”/] [ad type=”banner”]

Categorized in: