.Ds_Store(桌面服务商店(Desktop Services Store))文件是隐藏在 Mac 操作系统上的信息文件,每当您通过Finder 应用程序(Finder app)浏览文件夹时,macOS 都会自动创建该信息文件。
该文件是为每个文件夹创建的,其中包含控制操作系统如何打开具有相关系统配置元数据的文件夹的信息。数据包括背景图像、图标的大小或方向、打开文件夹时如何显示文件夹等。

DS_Store 文件有害吗?(Are DS_Store Files Harmful?)
您可以在从其他Mac用户收到的存档中找到(Mac)DS_store文件,但它们位于文件夹中时不会造成任何伤害。

DS_Store 文件通常是隐藏的,但您可以启用隐藏文件设置并查看文件。
- 要启用隐藏文件,请选择前往(Go)>计算机(Computer),然后选择Macintosh HD以展开该部分。

- 选择Command + Shift + 。(句号键)。您看到的灰显文件通常是Mac中的隐藏文件。

但是,如果您将DS_Store文件与其他文件一起上传到您的Mac,则它们有可能被滥用来获取有关您Mac上文件的文件属性或元数据等信息。它可能允许黑客进行恶意行为并查看您的私人文件。
如何删除 DS_Store 文件(How to Delete a DS_Store File)
以下是您想要删除DS_Store文件的几个原因,即使它不会占用文件夹中的太多空间或造成任何损害:
- 每次您尝试打开文件夹 时Finder都会启动。(Finder)
- 损坏的DS_Store文件会使您难以更改查看选项以及查看或排序文件夹中的文件图标。当文件夹立即关闭时,表明DS_Store文件已损坏。
- 通过删除DS_Store文件来重置显示首选项。您将丢失特定文件夹的自定义Finder视图设置,但您始终可以更改文件夹的视图选项或设置。
- 如果您在计算机之间传输文件(transferring files between computers),例如从Mac到另一个系统,您可能会遇到一些由DS_Store文件引起的意外问题。

解决DS_Store文件遇到的任何问题的一些快速方法包括:
删除DS_Store(DS_Store)文件时不会丢失任何数据。但是,一旦更改了文件夹首选项,Finder将创建一个新的DS_Store来存储自定义视图设置。
我们将向您展示如何删除DS_Store文件:
- 对于特定文件夹
- 通过终端(Terminal)应用程序获取Mac中的多个文件夹
如何删除特定文件夹的 DS_Store 文件(How to Delete a DS_Store File for a Specific Folder)
使用(Use)这些步骤从特定文件夹中删除DS_Store文件。(DS_Store)
- 选择前往(Go)>实用程序(Utilities)>终端(Terminal)。
注意(Note):如果您没有以管理员身份登录,系统可能会要求您输入您的姓名和密码以访问终端(Terminal)应用程序并使用删除DS_Store文件所需的命令。

- 找到文件夹并将目录更改为包含要删除的DS_Store文件的文件夹。(DS_Store)例如,如果文件夹在桌面上,请使用cd desktop命令并按Enter。

- 键入查找。(find . –name ‘.DS_Store’ –type f –delete )–name ' .DS_Store (DS_Store)' –type f –delete删除当前目录下的所有 DS_Store 文件并回车(Enter)。
注意(Note):确保您完全按照预期输入命令,否则您可能会删除Mac上的其他重要文件。

- 选择确定(OK)。您选择的文件夹中的 .DS_Store 文件将被删除。

注意(Note):仅当您输入的命令不起作用时,终端才会发送消息。
如何删除多个文件夹的 DS_Store 文件(How to Delete a DS_Store File for Multiple Folders)
如果您想从Mac中删除所有(Mac)DS_Store文件,请按照以下步骤操作。
- 选择前往(Go)>实用程序(Utilities)>终端(Terminal)。

- 在终端(Terminal)窗口中输入此命令: sudo find / -name “.DS_Store” -depth -exec rm {} \; 并按Enter。

- 如果出现提示,请输入您的密码(password,)。DS_Store文件将从所有文件夹中删除。

注意(Note):仅当您输入的命令不起作用时,应用程序才会返回消息。
如何防止自动创建 DS_Store 文件(How to Prevent Automatic Creation of DS_Store Files)
如果您的服务器上有随机文件夹,黑客可能会访问(hackers may get access)DS_Store 文件,查看文件的属性(DS_Store)或元数据,并进行恶意行为。
解决此问题并通过DS_Store文件(DS_Store)防止安全漏洞的最佳方法是禁用(prevent security breaches)DS_Store文件的自动创建。就是这样。
- 选择前往(Go)>实用程序(Utilities)>终端(Terminal)。
- 键入defaults write com.apple.desktopservices DSDontWriteNetworkStores true并按Enter。如果您想反转此命令,请使用相同的命令,但将true更改为false。

- 重新启动您的 Mac。
如何定期自动删除 .DS_Store 文件 (How to Automatically Delete .DS_Store Files Periodically )
如果您不想继续以手动方式删除DS_Store文件,可以使用UNIX命令定期自动删除文件。就是这样。
- 选择前往(Go)>实用程序(Utilities)>终端(Terminal)。
- 在终端(Terminal)中键入或粘贴此命令:sudo crontab -e并按Return键。

- 如果出现提示,请输入您的管理员密码(administrator password)。

- 在 vim 编辑器中,按一次键盘上的i。然后键入或粘贴此命令:30 10 * * * root find / -name “.DS_Store” -depth -exec rm {} \;

注意(Note):crontab 条目采用以下格式:<Minute> <Hour> <DayOfMonth> <Month> <DayOfWeek> <User Command>。在我们的示例中,系统设置为每天上午 10.30 自动运行命令。您可以使用不同的值将命令配置为不同的时间,无论您的Mac是打开还是处于睡眠模式(Sleep mode),该命令都会运行。
- 按一次键盘上的Esc键,然后同时按Shift + Z + Z以保存 crontab 条目。

从 Mac 中删除 DS_Store 文件(Remove DS_Store Files from Your Mac)
大多数Mac用户不知道DS_Store文件存在。这些不可见的文件位于(invisible files)Mac的系统文件夹中,您可以使用本指南中概述的步骤删除它们或禁用文件的创建。
请在下方发表评论,让我们知道本指南是否帮助您删除Mac上的(Mac)DS_Store文件。
What Is a DS_Store File and How to Remove It
A .Ds_Store (Desktop Services Stоre) file is an information file hidden on your Mac’s operating system that the macOS creates automatically whenever you browse a folder through the Finder app.
The file is created for each folder and contains information that controls how the OS will open the folder with the associated system configuration metadata. The data includes background images, size or orientation of the icons, how to display folders when you open them, etc.

Are DS_Store Files Harmful?
You can find DS_store files in archives received from other Mac users but don’t cause any harm while they’re in a folder.

DS_Store files are usually hidden from view, but you can enable the hidden files setting and view the files.
- To enable hidden files, select Go > Computer and then select Macintosh HD to expand the section.

- Select Command + Shift + . (the period key). The grayed out files you see are typically the hidden files in your Mac.

However, if you upload a DS_Store file along with other files to your Mac, there’s a chance they can be misused to get information like file attributes or metadata about the files on your Mac. It could potentially allow hackers to act maliciously and view your private files.
How to Delete a DS_Store File
Here are a few reasons why you’d want to delete a DS_Store file, even if it doesn’t take up much space in a folder or cause any harm:
- When Finder acts up each time you try to open a folder.
- Corrupted DS_Store files can make it hard for you to change view options and see or sort file icons within the folder. When a folder closes immediately, it’s a sign of a corrupted DS_Store file.
- To reset your display preferences by deleting a DS_Store file. You will lose custom Finder view settings for the particular folder, but you can always change the folder’s view options or settings.
- If you’re transferring files between computers, like from your Mac to another system, you may encounter some unexpected problems caused by DS_Store files.

Some quick ways to resolve any problems you face with DS_Store files include:
- Open DS_Store files with suitable applications on non-macOS systems like Windows. Some tools you can use to open DS_Store files in Windows include WinRAR, Adobe Acrobat, and Free File Viewer.
- Ensuring your DS_Store file isn’t corrupted or infected with a virus or malware. You can run a malware scan using the best antivirus options for Mac and check for any potential threats.
You don’t lose any data when deleting a DS_Store file. But, once the folder preferences are changed, Finder will create a new DS_Store to store custom view settings.
We’ll show you how to delete a DS_Store file:
- For a specific folder
- For multiple folders in your Mac through the Terminal application
How to Delete a DS_Store File for a Specific Folder
Use these steps to delete a DS_Store file from a specific folder.
- Select Go > Utilities > Terminal.
Note: If you’re not signed in as an administrator, you may be asked to enter your name and password to access the Terminal app and use the commands needed to delete DS_Store files.

- Locate the folder and change the directory to the folder containing the DS_Store file you want to delete. For example, if the folder is on the desktop, use the cd desktop command and press Enter.

- Type find . –name ‘.DS_Store’ –type f –delete to delete all DS_Store files in the current directory and press Enter.
Note: Make sure you type out the command exactly as intended otherwise you may delete other important files on your Mac.

- Select OK. The .DS_Store files in the folder you selected will be deleted.

Note: Terminal will send a message only if the command you entered didn’t work.
How to Delete a DS_Store File for Multiple Folders
If you want to delete all DS_Store files from your Mac, follow these steps.
- Select Go > Utilities > Terminal.

- Enter this command in the Terminal window: sudo find / -name “.DS_Store” -depth -exec rm {} \; and press Enter.

- Enter your password, if prompted. The DS_Store files will be deleted from all the folders.

Note: The app will return a message only if the command you entered didn’t work.
How to Prevent Automatic Creation of DS_Store Files
If there are random folders on your server, hackers may get access to the DS_Store files, view attributes or metadata about the file, and act maliciously.
The best way to resolve this problem and prevent security breaches through DS_Store files is to disable the automatic creation of DS_Store files. Here’s how.
- Select Go > Utilities > Terminal.
- Type defaults write com.apple.desktopservices DSDontWriteNetworkStores true and press Enter. If you ever want to reverse this command, use the same command but change true to false.

- Restart your Mac.
How to Automatically Delete .DS_Store Files Periodically
If you don’t want to keep deleting DS_Store files the manual way, you can use a UNIX command to automatically remove the files at regular intervals. Here’s how.
- Select Go > Utilities > Terminal.
- Type or paste this command in Terminal: sudo crontab -e and press the Return key.

- If prompted, enter your administrator password.

- In the vim editor, press i on your keyboard once. Then type or paste this command: 30 10 * * * root find / -name “.DS_Store” -depth -exec rm {} \;

Note: The crontab entry is in the following format: <Minute> <Hour> <DayOfMonth> <Month> <DayOfWeek> <User Command>. In our example, the system is set to automatically run the command at 10.30 AM every day. You can use different values to configure the command for a different time and the command will run whether your Mac is on or in Sleep mode.
- Press the Esc key on your keyboard once and then press Shift + Z + Z simultaneously to save the crontab entry.

Remove DS_Store Files from Your Mac
Most Mac users aren’t aware that DS_Store files exist. These invisible files live in the system folders of your Mac, and you can remove them or disable the creation of the files using the steps outlined in this guide.
Leave a comment below and let us know if this guide helped you remove DS_Store files on your Mac.