{"id":232,"date":"2015-05-20T10:24:58","date_gmt":"2015-05-20T09:24:58","guid":{"rendered":"http:\/\/www.troliver.com\/?p=232"},"modified":"2015-05-22T14:19:16","modified_gmt":"2015-05-22T13:19:16","slug":"trouble-in-sambadise-ds_store-and-other-system-created-files","status":"publish","type":"post","link":"https:\/\/www.troliver.com\/?p=232","title":{"rendered":"Trouble in Sambadise; How to remove .DS_Store and other system-created files in Samba"},"content":{"rendered":"<p>Our file share seems to be running well now, except for one bothersome thing; The generation of hidden system files. I noticed this after one of our team members accessed our Samba share from a system running Mac OS, where I could see where he&#8217;d looked around by the trail of hidden\u00a0<em>._.DS_Store\u00a0<\/em>files he had left behind.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-271 aligncenter\" src=\"http:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/sambaveto1.png\" alt=\"sambaveto1\" width=\"587\" height=\"240\" srcset=\"https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/sambaveto1.png 587w, https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/sambaveto1-300x123.png 300w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/p>\n<p>Users who access the Samba shares from a Mac will inadvertently generate <em>._.DS_Store<\/em> and <em>.DS_Store<\/em> files that are just plain annoying. Although you can view them if you have the option to view hidden files turned on, by default they&#8217;re hidden and make an apparently empty directory NOT empty, amongst other annoyances. This is even true from within Linux, where listing a directory with one of these rogue files shows nothing:<\/p>\n<p><a href=\"http:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-234\" src=\"http:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto1.png\" alt=\"veto1\" width=\"558\" height=\"33\" srcset=\"https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto1.png 558w, https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto1-300x18.png 300w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>But you&#8217;ll be able to\u00a0see hidden files, with the -a switch.<a href=\"http:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-235\" src=\"http:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto2.png\" alt=\"veto2\" width=\"588\" height=\"63\" srcset=\"https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto2.png 588w, https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto2-300x32.png 300w\" sizes=\"(max-width: 588px) 100vw, 588px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>And finally you can see more about the files with both -l and -a.<a href=\"http:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-236\" src=\"http:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto3.png\" alt=\"veto3\" width=\"602\" height=\"145\" srcset=\"https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto3.png 602w, https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto3-300x72.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/a><\/p>\n<h2><\/h2>\n<h2>So how do you stop this from happening?<\/h2>\n<p>Samba allows you to &#8220;veto files&#8221; by specifying which files in the current folder you want to remove &#8211; but this doesn&#8217;t actually get rid of them on its own. Since Samba builds on top underlying permissions in the Unix system, all that this does is to hide these files from the view of Windows share users.<\/p>\n<p>This is quite annoying &#8211; because if you try and delete a folder, it just won&#8217;t let you (and, at least on my Windows 8 system, no error shows up). You have to also specify &#8220;delete veto files = yes&#8221; to allow users to delete these files too (even if you can&#8217;t see them). Open up the Samba configuration <em>(etc\/samba\/smb.conf)<\/em> and, under your share name, add the following two lines:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-233 aligncenter\" src=\"http:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto-file-command.png\" alt=\"veto file command\" width=\"547\" height=\"221\" srcset=\"https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto-file-command.png 547w, https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto-file-command-300x121.png 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/p>\n<p>However, this doesn&#8217;t get rid of files that already exist; it just hides them. I think many people think that this is enough &#8211; but I&#8217;d really like to avoid the creation of residual files and hidden behaviours like this in the first place, so I wanted to find a more robust solution.<\/p>\n<p>The most popular articles exist suggest that the above two lines should be enough. Actually, it has been suggested to add all <em>._*<\/em> files to this list on some of these articles &#8211; but this can affect some unix files too, which isn&#8217;t necessarily what we want to have happen.<\/p>\n<p>But it turns out that these two lines<i>\u00a0<\/i><em>are\u00a0<\/em>probably the best approach &#8211; and\u00a0what wasn&#8217;t initially clear, too, is that this <strong>does actually<\/strong>\u00a0<strong>stop files from being created in the first place. <\/strong>You can\u00a0test this out by doing something like copying over just a plain text file called &#8220;hello.txt&#8221;, which should be blacklisted in the <em>veto files <\/em>list:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-237 aligncenter\" src=\"http:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto4.png\" alt=\"veto4\" width=\"463\" height=\"260\" srcset=\"https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto4.png 463w, https:\/\/www.troliver.com\/wp-content\/uploads\/2015\/05\/veto4-300x168.png 300w\" sizes=\"(max-width: 463px) 100vw, 463px\" \/><\/p>\n<p>Now, the message you get is that it can&#8217;t find it in the source folder, but all that is happening is that it just isn&#8217;t copying it over. Don&#8217;t worry, it isn&#8217;t deleting the original file!<\/p>\n<p>This should be all you need to do &#8211; but one other thing that should be pointed out is the format that Samba expects you to have files listed in, if you&#8217;re trying to veto multiple files. Each file should be separated by a forward slash with no spaces, like so:<\/p>\n<pre class=\"lang:vim decode:true \">\/test1.txt\/test.txt\/test3.txt<\/pre>\n<p>&nbsp;<\/p>\n<p>Well, actually.. you can have spaces.. but in that case, it has to look like this:<\/p>\n<pre class=\"lang:vim decode:true \">\/test1.txt\/ \/test2.txt\/ \/test3.txt\/<\/pre>\n<p>&nbsp;<\/p>\n<p>If you do the following, then only test3.txt is removed, since the space is included in the name of the file:<\/p>\n<pre class=\"lang:vim decode:true \">\/test1.txt \/test.txt \/test3.txt<\/pre>\n<p>&nbsp;<\/p>\n<p>This is important &#8211; since if a file has a space in the name, you would NOT use quotes as you might expect you&#8217;d have to; you simply <em>write the name as it appears:<\/em><\/p>\n<pre class=\"lang:vim decode:true \">\/test 1.txt\/test 2.txt\/test 3.txt<\/pre>\n<p>&nbsp;<\/p>\n<p>The last thing to do now is to cleanup the files that already exist. Since there could be any number of folders and subfolders that have been accessed by a Mac user, you need to do a recursive search for the files and then delete them.<\/p>\n<pre class=\"lang:sh decode:true \">find . -name \"*DS_Store\" -delete<\/pre>\n<p>(You can replace the <em>*DS_Store\u00a0<\/em>part with anything you want to find and delete, for example\u00a0.<em>DS_Store<\/em>, ._.<em>DS_Store<\/em>, <em>desktop<\/em>.<em>ini<\/em> or <em>thumbs<\/em>.<em>db<\/em>)<\/p>\n<p>&nbsp;<\/p>\n<p>As a final thought is that, there is a possibility that this has an effect the server&#8217;s performance when writing files since it has to check the list of veto&#8217;d files every time a file is written. This is not a critical issue for shared drives where read time is often more important than write time, but its a consideration for the future if performance was ever to be of critical importance.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our file share seems to be running well now, except for one bothersome thing; The generation of hidden system files. I noticed this after one of our team members accessed our Samba share from a system running Mac OS, where I could see where he&#8217;d looked around by the trail of hidden\u00a0._.DS_Store\u00a0files he had left [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[21],"tags":[10,20,47,41,42,18],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6PQZ3-3K","_links":{"self":[{"href":"https:\/\/www.troliver.com\/index.php?rest_route=\/wp\/v2\/posts\/232"}],"collection":[{"href":"https:\/\/www.troliver.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.troliver.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.troliver.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.troliver.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=232"}],"version-history":[{"count":4,"href":"https:\/\/www.troliver.com\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":274,"href":"https:\/\/www.troliver.com\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions\/274"}],"wp:attachment":[{"href":"https:\/\/www.troliver.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.troliver.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.troliver.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}