Deleting desktop.ini Files using Bash 1

The desktop.ini files are hidden system files commonly found in Windows directories. These files store folder customization settings, such as icon placement or view preferences. While useful in Windows environments, they can clutter directories when viewed on other operating systems, such as Linux or macOS.

Testing it out

find /directory -iname desktop.ini -print | less

Used to preview all instances of desktop.ini in a directory and its subdirectories.

  • find: A command to search for files in a directory hierarchy.
  • /directory: Replace this with the path of the directory where the search will be performed. For example, /media/drive or ~/documents.
  • -iname desktop.ini: Searches for files with the name desktop.ini, ignoring case (-iname is case-insensitive).
  • -print: Prints the full path of each matching file to standard output.
  • | less: Pipes the output to the less pager, allowing you to scroll through the results interactively.

Deleting the files in the directory

find /directory -iname desktop.ini -delete

Delete once you've identified the files.

  • -delete: Removes each matched file immediately.

⚠️ Important: The -delete action is irreversible. Ensure that you target the correct directory to avoid unintentional file deletions. It's recommended to preview the results using the -print option before running the delete command.

Footnotes

  1. Using Bash, how can I delete all the desktop.ini in my external drive folder tree?