{"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<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">bash code<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">                  #7479417:  directory<br\/>                  #7479418:  directory<br\/>                  #7479419:  directory<br\/>                  #7602560:  directory<br\/>                 #7603310:  MPEG sequence, v2, program multiplex<br\/>                 #7603464:  JPEG image data, JFIF standard 1.02<br\/>                 #7603542:  Audio file with ID3 version 2.3.0, contains: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 320kbps, <br\/>                  44.1   kHz,JntStereo<br\/>                #7604043:  ISO 9660 CD-ROM filesystem data &#039;Linux Mint 9 Isadora           &#039; (bootable)<br\/>                #7604089:  ISO 9660 CD-ROM filesystem data &#039;netbook-x86_64-201005242312    &#039; (bootable)<br\/>                #7605425:  MPEG sequence, v2, program multiplex<br\/>                #7605470:  MPEG sequence, v2, program multiplex<br\/>                #7605484:  MPEG sequence, v2, program multiplex<br\/>                 #7607478:  gzip compressed data, from Unix, last modified: Fri May 14 07:55:35 2010<br\/>                #7607788:  gzip compressed data, from Unix, last modified: Tue May  4 14:16:31 2010<br\/>                #7610801:  PDF document, version 1.4<br\/>                #7612061:  ISO 9660 CD-ROM filesystem data &#039;Ubuntu 10.04 LTS amd64         &#039; (bootable)<br\/>                #7613228:  directory<br\/>                #7613583:  directory<br\/>                #7613588:  directory<\/code><\/pre> <\/div>\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<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">bash code<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">              set -v<br\/>               ls -l \\#10104455<br\/>               ls -l \\#10104531<br\/>               ls -l \\#10104536<\/code><\/pre> <\/div>\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<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">bash code<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">ls -l \\#7733249<br\/>total 5704<br\/>drwxr-xr-x 2 1002 1002    4096 2010-06-05 13:24 Desktop<br\/>drwxr-xr-x 2 1002 1002    4096 2010-04-30 09:15 Documents<br\/>drwxr-xr-x 2 1002 1002    4096 2010-04-30 09:15 Downloads<br\/>-rw-r--r-- 1 1002 1002     179 2010-04-30 09:14 examples.desktop<br\/>drwxr-xr-x 2 1002 1002    4096 2010-04-30 09:15 Music<br\/>drwxr-xr-x 2 1002 1002    4096 2010-04-30 09:15 Pictures<br\/>drwxr-xr-x 2 1002 1002    4096 2010-04-30 09:15 Public<br\/>-rw-r--r-- 1 1002 1002 5794003 2010-05-15 11:00 scrap001_a.ora<br\/>drwxr-xr-x 2 1002 1002    4096 2010-04-30 09:15 Templates<br\/>-rw-r--r-- 1 1002 1002    1265 2010-05-20 14:35 tinda chuteny<br\/>drwxrwxr-x 2 1002 1002    4096 2010-05-23 14:57 Ubuntu One<br\/>drwxr-xr-x 2 1002 1002    4096 2010-04-30 09:15 Videos<\/code><\/pre> <\/div>\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}]}}