{"id":837,"date":"2017-03-18T18:20:04","date_gmt":"2017-03-18T12:50:04","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=837"},"modified":"2017-03-29T13:21:57","modified_gmt":"2017-03-29T07:51:57","slug":"purpose-lostfound-folder-linux-unix","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/purpose-lostfound-folder-linux-unix\/","title":{"rendered":"What is the purpose of the lost+found folder in Linux and Unix"},"content":{"rendered":"<h4 id=\"purpose-of-the-lostfound-folder\"><span style=\"color: #ff6600;\"><b>Purpose of\u00a0 the <\/b><b>lost+found<\/b><b> folder:<\/b><\/span><\/h4>\n<ul>\n<li>This \u00a0directory \u00a0is for recovering files which are not properly closed due to many reason such as power failure.<\/li>\n<\/ul>\n<ul>\n<li>The\u00a0 <b>lost+found<\/b> \u00a0\u00a0folder\u00a0 contains the files with no links and files to be recovered.<\/li>\n<\/ul>\n<ul>\n<li>Any file to be recovered is kept in this folder.<b>\u00a0<\/b>fsck command (file system check)\u00a0is used to recover these files.<\/li>\n<\/ul>\n<ul>\n<li>In generally, the directory is empty; but if there is corruption, the conditions files can be recovered after\u00a0fsck\u00a0places them here.<\/li>\n<\/ul>\n<ul>\n<li>The\u00a0lost+found\u00a0directory (not Lost+Found) is a construct used by\u00a0fsck\u00a0when there is damage to the filesystem (not to the hardware device, but to the fs).<\/li>\n<\/ul>\n<ul>\n<li>Files that would normally be lost because of directory corruption would be linked in that filesystem&#8217;s\u00a0lost+found\u00a0directory by inode number.<\/li>\n<\/ul>\n<ul>\n<li>\u00a0If\u00a0 you lost directories or lost files or even lost devices. Each filesystem should have its own\u00a0lost+found\u00a0directory, but you influence be looking at a system with only one file system.<\/li>\n<\/ul>\n<ul>\n<li>If you run<b>\u00a0<\/b><b>fsck<\/b>, the <b>filesystem<\/b> check and repair command, it find the data fragments that are not referenced anywhere in the filesystem. In particular,\u00a0fsck\u00a0might find data that looks like a complete file but doesn&#8217;t have a name on the system \u2014 an\u00a0<b>inode<\/b>\u00a0with no corresponding file name. This data is still using up space, but it isn&#8217;t accessible by any normal means.<\/li>\n<\/ul>\n<ul>\n<li>The \u00a0<b>fsck<\/b>\u00a0to 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<b>\u00a0<\/b><b>fsck<\/b>\u00a0deposits the file in a specific directory, called\u00a0<b>lost+found<\/b>\u00a0(after\u00a0lost and found\u00a0property).<\/li>\n<\/ul>\n<ul>\n<li>Files that appear in\u00a0lost+found\u00a0are typically files that were already unlinked (i.e. their name had been erased) but still opened by some process (so the data wasn&#8217;t erased yet) when the system halted suddenly (kernel panic or power failure). If that&#8217;s all that happened, these files were slated for deletion anyway.<\/li>\n<\/ul>\n<ul>\n<li>Files can also appear in<b>\u00a0<\/b><b>lost+found<\/b>\u00a0because the <b>filesystem<\/b> was in an inconsistent state due to a software or hardware bug. If that&#8217;s the case, it&#8217;s a way for you to find files that were lost but that the system repair managed to salvage. If\u00a0 they do they may be incomplete or out of date; it all depends how bad the filesystem damage was.<\/li>\n<\/ul>\n<ul>\n<li>On many <b>filesystems<\/b>, the<b>\u00a0<\/b><b>lost+found<\/b>\u00a0directory is a bit special because it <b>preallocates<\/b> a bit of space for\u00a0<b>fsck<\/b>\u00a0to deposit files there. (The space isn&#8217;t for the file data, which\u00a0fsck\u00a0leaves in place; it&#8217;s for the directory entries which\u00a0fsck\u00a0has to make up.) If you accidentally delete\u00a0<b>lost+found,<\/b> don&#8217;t re-create it with\u00a0<b>mkdir<\/b><b>, <\/b>use\u00a0<b>mklost+found<\/b>\u00a0.<\/li>\n<\/ul>\n[ad type=&#8221;banner&#8221;]\n<h4 id=\"example\"><span style=\"color: #808000;\"><strong>Example<\/strong>:<\/span><\/h4>\n<ul>\n<li>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 \u201cfile *\u201d in lost+found to know the type of files. It lists some thing like<\/li>\n<\/ul>\n[pastacode lang=&#8221;bash&#8221; manual=&#8221;%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&#8217;Linux%20Mint%209%20Isadora%20%20%20%20%20%20%20%20%20%20%20&#8217;%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&#8217;netbook-x86_64-201005242312%20%20%20%20&#8217;%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&#8217;Ubuntu%2010.04%20LTS%20amd64%20%20%20%20%20%20%20%20%20&#8217;%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&#8221; message=&#8221;bash code&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]\n<ul>\n<li>Then you filtered out all files except \u201cdirectory\u201d using \u201cfile * | grep directory &gt; \/root\/list.dir\u201d command.<\/li>\n<\/ul>\n<ul>\n<li>\u00a0Edited \/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.<\/li>\n<\/ul>\n[pastacode lang=&#8221;bash&#8221; manual=&#8221;%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&#8221; message=&#8221;bash code&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]\n<ul>\n<li>The \u201cset -v\u201d will help you to echo the command the shell execute. \u201cchmod +x list.dir\u201d to make it executable.<\/li>\n<\/ul>\n<ul>\n<li>Now run the script in \/home\/lost+found folder, redirecting the output to \/tmp\/ (\u201c.\/list.dir 1&gt; \/tmp\/dir.out 2&gt;&amp;1\u201c). Now search for your known file in dir.out output file. Now\u00a0 searched for \u201cDesktop\u201d and found some thing like this..<\/li>\n<\/ul>\n[pastacode lang=&#8221;bash&#8221; manual=&#8221;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&#8211;r&#8211;%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&#8211;r&#8211;%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&#8211;r&#8211;%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&#8221; message=&#8221;bash code&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]\n[ad type=&#8221;banner&#8221;]\n","protected":false},"excerpt":{"rendered":"<p>Purpose of\u00a0 the lost+found folder: This \u00a0directory \u00a0is for recovering files which are not properly closed due to many reason such as power failure. The\u00a0 lost+found \u00a0\u00a0folder\u00a0 contains the files with no links and files to be recovered. Any file to be recovered is kept in this folder.\u00a0fsck command (file system check)\u00a0is used to recover [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1699,1331],"tags":[1570,1571,1568,1562,1566,1578,1567,1565,1564,1563,1561,1569,1573,1575,1572,1576,1574,1577],"class_list":["post-837","post","type-post","status-publish","format-standard","hentry","category-linux","category-unix","tag-can-you-have-multiple-lost-and-found-directories","tag-file-missing-after-fsck","tag-knowledge-basewhat-is-the-lostfound-directory","tag-linux-lostfound-delete","tag-lost-found-netflix","tag-lost-folder-from-mnt-and-recovering","tag-lost-found-meaning","tag-lostfound-ext4","tag-lostfound-folder-mac","tag-mklostfound","tag-newly-created-disk","tag-purpose-of-the-lostfound-folder-in-linux-and-unix","tag-restore-from-lostfound","tag-unix-equivalent-of-smart-folders","tag-what-are-the-advantages-disadvantages-linux-file-hierarchy-has-compared-to-other-oss","tag-what-is-the-reasoningdesign-choice-behind-the-unixlinux-file-system-structure","tag-why-do-people-choose-different-file-systems-for-different-directories","tag-why-is-the-directory-lostfound-16k-instead-of-4k-bytes"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=837"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/837\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}