25

Every time I delete it from the desktop, I get the same file ".DS_store" created after some time. Is there a reason why this happens ? And can I permanently stop it from being created ?

bmike
  • 235,889
Render
  • 7,157
  • 2
    See the Wikipedia entry on .DS_Store which explains what the file does. In short, Finder writes one in each folder to track icon locations, sized and the last window position / sort / size so you see a folder the way it was next time you open it. Desktop is always visible, hence the constant recreation of this file by the Finder. – Alex Oct 06 '12 at 14:02
  • Have you ruled out disk corruption by booting to the recovery HD and running a disk repair operation? I would also get a good backup before poking at it in any way in case it's a sign of pending disk subsystem failure. Not likely, but why risk it if you don't have regular backups. – bmike Oct 06 '12 at 14:04
  • @Alex so theres no way to hide that particular file type ?? – Render Oct 06 '12 at 15:37
  • @bmike my laptop is about 2 months old, I really hope its not a pending disk subsystem failure already !!! – Render Oct 06 '12 at 15:37
  • @Fendi, see this Superuser question as well. – Alex Oct 06 '12 at 15:40
  • @Alex thank you .. Sadly I will have to either live with it or just hide everything... – Render Oct 06 '12 at 15:42
  • @Fendi On Windows I always wanted to see the hidden files, but I left this habit behind after switching to Mac. – Alex Oct 06 '12 at 15:44
  • @Alex aren't there disadvantages of not viewing hidden files ? – Render Oct 06 '12 at 15:45
  • @fendi - the vast majority of failures happen in the first week to month of use. It's more likely corruption which is just a random occurrence - bad luck but a reinstall fixes it and you're not likely to have problems going forward. – bmike Oct 06 '12 at 15:50
  • 2
    @bmike can you please explain or point me to an article that mentions how the appearance of .DS_Store in the desktop might be related to a possible disk failure ? – Render Oct 06 '12 at 15:53
  • 1
    @Fendi I haven’t found one. However, if you need to see them, you can either use this widget or just fire Terminal and use ls -la in the respective folder. – Alex Oct 06 '12 at 16:17
  • Over 3 years later and still no further to being able to exclude .htaccess files from being hidden without showing all hidden (dot) files. – William Isted May 25 '16 at 11:24

10 Answers10

26

Type this in Terminal (/Applications/Utilities/Terminal.app):

defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder

The first command sets the hidden files visibility to hidden; the second one forces Finder to restart. This is needed for the first command to take effect.

You can also log out/reboot instead of killing the Finder, but the first command is needed to change a hidden preference (one that the Finder can’t change using the normal Finder view options or preferences).

duci9y
  • 5,457
  • 3
    Would like an explanation please – Render Oct 06 '12 at 13:37
  • 2
    The answerer is guessing that your finder somehow was set to show hidden files. It is the most logical explanation for why a file that normally is hidden by Finder would show, but you would also expect to see .DS_Store files everywhere if this were the case. – bmike Oct 06 '12 at 14:02
  • 1
    @Fendi The first command sets the hidden files visibility to hidden; the second one forces Finder to restart, action that is needed in order to make it take in consideration the previous command. – Alex Oct 06 '12 at 14:07
  • Guess the only way to do it is to hide the hidden files or live with it .. – Render Oct 06 '12 at 15:42
  • Just to keep this thread up to date, it's no longer necessary to kill the Finder to show/hide dot files. I'll post a new answer with a simple Applescript. – Tetsujin Jan 11 '15 at 10:39
  • 4
    This hides dotfiles everywhere, not just on the desktop. There's a legitimate use case for being able to view and work with dotfiles, but not having a useless icon permanently displayed on the desktop. – Bobby Jack Apr 01 '15 at 10:48
  • -1 Not only does this hide dot files everywhere, as mentioned, it also hides all dot files - which might not be advisable if the user has hidden files visible enabled in the first place. – kontur Aug 18 '15 at 09:31
  • @kontur I'd imagine the OP to know what .DS_Stores are if they were to know how to enable/disable hidden files. – duci9y Aug 18 '15 at 09:32
  • @duci9y sure, but that doesn't change the assumption that she might actually want dot files showing, just not that particular one. Following that logic, the answer will have the undesirable effect of hiding dot files everywhere. – kontur Aug 18 '15 at 09:41
15

There's a way to hide all "dot" files from Desktop with 3rd party app called XtraFinder.

Go to Settings → Features tab → Hide dot files on Desktop

Screenshot of XtraFinder

Though I still didn't manage to hide all .DS_Store files and keep all other dot files visible, this is a pleasant improvement.

grg
  • 201,078
Micer
  • 626
  • 5
    Most developers want dot files to show, so the first answer (which has also been marked accepted) isn't helpful. The initial question is about hiding the dot files on the desktop and this answer solves this problem - thank you @micer +1 – alexkb Jun 23 '15 at 09:35
  • 2
    @alexkb I use tinkerTool for showing system files, but also tried adding XtraFinder to hide the .DS_Store file from desktop (and other hidden files which, on desktop, I don't want) - this way you can still have dot files displayed, just not on desktop. – kontur Aug 18 '15 at 09:37
5

.DS_Store is used by OS X to store directory information used by Finder such as icon position, etc.

In OS X any file name that starts with a "." is hidden, so to hide the .DS_Store file you can use the terminal command:

sudo defaults write com.apple.finder AppleShowAllFiles NO

Basically, you can ignore it. If you are copying a directory to a flash drive and looking at it in Windows, feel free to just delete it. It is Mac OS X Finder that creates this file whenever it opens a new directory.

An alternative solution would be to prevent Finder from automatically creating these files. The following terminal command changes the default setting from automatically creating them to not:

defaults write com.apple.desktopservices DSDontWriteNetworkStores TRUE

And to revert back to the default behavior:

defaults delete com.apple.desktopservices DSDontWriteNetworkStores
JackyJohnson
  • 1,840
  • The second option to prevent .DS_Store works for network drives only. It has no effect for the local drive unfortunately. Finder still loves its .DS_Store files. – Darkstar Nov 07 '20 at 17:29
5

For those who would like to still view other hidden files but hide the desktop .DS_Store file, the solution is to give the desktop version a transparent icon. The best instructions I have found are here:

https://www.scottofford.com/2013/03/hide-ds-store-on-mac/

When finished with the transparent icon, drag the icon's text to off the screen and you will never see the desktop file again.

izk9
  • 51
  • 2
    Just drag the icon's text off the screen and you will not see the text. Regardless if it is a cheat or not @atilkan, I have found it to accomplish my needs better than any other suggestion on here at this point. I actually forgot that the file was still on my desktop until I saw your comment, LOL. – izk9 Jun 03 '16 at 14:52
  • 1
    I didn't realize this game had rules. :) Totally useful to me. – Clay Bridges Jul 17 '16 at 21:48
  • 1
    Been using this hack for 3 yrs, its at the bottom corner with text hidden, very useful imho – Keno Apr 08 '17 at 16:36
0

Just to keep this thread up to date, it's no longer necessary to kill the Finder to show/hide dot files.

This Applescript will do it by refreshing all window contents instead; it's also faster than relaunching the Finder.

set newHiddenVisiblesState to "YES"
try
    set oldHiddenVisiblesState to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if oldHiddenVisiblesState is in {"1", "YES"} then
        set newHiddenVisiblesState to "NO"
    end if
end try
do shell script "defaults write com.apple.finder AppleShowAllFiles " & newHiddenVisiblesState


tell application "Finder"
    set theWindows to every Finder window
    repeat with i from 1 to number of items in theWindows
        set this_item to item i of theWindows
        set theView to current view of this_item
        if theView is list view then
            set current view of this_item to icon view
        else
            set current view of this_item to list view

        end if
        set current view of this_item to theView
    end repeat
end tell

Save as an app & launch to toggle visibility.

Tetsujin
  • 115,663
0

You can Remove all DS_Store files

  1. Select Applications > Utilities to launch Terminal.

  2. Enter the following UNIX command:

  3. sudo find / -name ".DS_Store" -depth -exec rm {} \;

When prompted for a password enter your Mac OS X Administrator password.

You can also schedule a crontab to remove them periodically More details: https://helpx.adobe.com/dreamweaver/kb/remove-ds-store-files-mac.html

paarsa
  • 101
0

And can I permanently stop it from being created ?

Over 3 years later and still no further to being able to exclude .htaccess files from being hidden without showing all hidden (dot) files.

This answer comes a little late, but I've stumbled across this question, and I believe I have a useful solution: you could just disable the .DS_store creation in the first place. Death to .DS_Store explains one way how. I have tested this on 10.5, 10.6, and 10.15.

brew install deathtodsstore

This installs a handy GUI application, check "Launch Agent Installed" and "Patch Finder". (I think you have problems with re-opening windows on log-in in 10.15.) However, as documented, still, this will not work with SIP on; specifically (from experimentation,) csrutil disable; csrutil enable --without fs --without debug (this is undocumented and probably not manufacturer approved.) However, with this, hiding files behave much more as expected.

Neil
  • 111
  • 4
-2

There is an application you can download called Show Hidden Files.app It allows you to easily toggle hidden files on and off. The .ds store file is always generated in finder. You can only hide the file through the methods mentioned, or with this handy script.

chuck
  • 1
-3

You can just download and use an app to remove ds_store files from the Apple App Store.

klanomath
  • 66,391
  • 9
  • 130
  • 201
Tom
  • 1
-4

Apparently, it was due to an old Safari update that accidentally showed the .DS_Store file.