Skip to main content

remove-ds-store.sh

Removes all .DS_Store files from Azure Blob Storage container recursively.

Description

This script searches for and removes all .DS_Store files (macOS system files) from the specified Azure Storage container. It provides a list of files before deletion and requires user confirmation for safety.

Prerequisites

  • Azure CLI installed and configured
  • Authenticated Azure session (az login)
  • Delete permissions on Azure Storage Account

Configuration

Edit these variables in the script:
ACCOUNT_NAME="testdinostr"
CONTAINER_NAME="docs"

Usage

./scripts/remove-ds-store.sh
The script will:
  1. Search for all .DS_Store files
  2. Display the list of files found
  3. Ask for confirmation
  4. Delete confirmed files
  5. Show summary

Output

Removing .DS_Store files from Azure Blob Storage
Account: testdinostr
Container: docs

Fetching storage account key...
Storage key retrieved successfully

Searching for .DS_Store files...
Found 3 .DS_Store file(s)

Files to be deleted:
  - docs/organization/.DS_Store
  - docs/test-runs/configuration/.DS_Store
  - docs/test-runs/history/.DS_Store

Do you want to delete these files? (y/N): y

Deleting files...

✓ Deleted: docs/organization/.DS_Store
✓ Deleted: docs/test-runs/configuration/.DS_Store
✓ Deleted: docs/test-runs/history/.DS_Store

✓ Complete!
  Deleted: 3
  Failed: 0

Features

  • Recursive Search: Finds .DS_Store files in all subdirectories
  • Safety Confirmation: Requires user approval before deletion
  • Preview List: Shows all files before deleting
  • Progress Tracking: Real-time status with ✓ and ✗ markers
  • Summary Report: Shows deletion statistics

Interactive Prompts

Confirmation Prompt

Do you want to delete these files? (y/N):
Responses:
  • y or Y - Proceed with deletion
  • n, N, or Enter - Cancel operation
  • Any other input - Cancel operation

What are .DS_Store Files?

.DS_Store (Desktop Services Store) files are created by macOS Finder to store:
  • Custom folder view settings
  • Icon positions
  • Background images
  • Other folder metadata
Why Remove Them:
  • Not needed in cloud storage
  • Clutter the file listing
  • Can expose folder structure information
  • Waste storage space (small but unnecessary)

Safety Features

  1. Preview Before Delete: Shows complete list of files
  2. User Confirmation: Requires explicit approval
  3. Cancellable: Can abort at confirmation prompt
  4. No Wildcards: Only targets exact .DS_Store filename

Examples

Standard Usage

./scripts/remove-ds-store.sh

Non-Interactive (Auto-Confirm)

For automation, modify the script to skip confirmation:
# Remove the confirmation prompt section
# Or use expect/yes command (not recommended)

Dry Run (Check Only)

To see what would be deleted without actually deleting:
# Modify script to comment out the deletion loop
# Or just cancel at the confirmation prompt

Error Handling

No Files Found

No .DS_Store files found
The script exits gracefully - no action needed.

Failed to Fetch Storage Key

Failed to fetch storage account key
Solution: Run az login and verify access

Deletion Failures

Individual failures are tracked:
✗ Failed: docs/some-folder/.DS_Store
Common Causes:
  • Blob is locked
  • Insufficient permissions
  • Blob was already deleted

Prevention

Prevent Future .DS_Store Files

Add to .gitignore:
.DS_Store
**/.DS_Store

macOS Settings

Disable .DS_Store on network volumes:
defaults write com.apple.desktopservices DSDontWriteNetworkStores true

Upload Scripts

Filter out .DS_Store when uploading:
az storage blob upload-batch \
  --source ./local-folder \
  --destination docs \
  --pattern "*" \
  --exclude-pattern "*.DS_Store"

Automation

Scheduled Cleanup

Add to cron for weekly cleanup:
# Run every Sunday at 2 AM
0 2 * * 0 /path/to/scripts/remove-ds-store.sh <<< "y"

CI/CD Integration

# GitHub Actions example
- name: Clean .DS_Store files
  run: |
    echo "y" | ./scripts/remove-ds-store.sh

Verification

Check for .DS_Store Files

az storage blob list \
  --account-name testdinostr \
  --container-name docs \
  --query "[?ends_with(name, '.DS_Store')].name" \
  --output table

Count .DS_Store Files

az storage blob list \
  --account-name testdinostr \
  --container-name docs \
  --query "[?ends_with(name, '.DS_Store')]" \
  --output json | jq length

Best Practices

  1. Run Periodically: Schedule regular cleanups
  2. Check Before Upload: Filter .DS_Store during uploads
  3. Configure macOS: Disable network .DS_Store creation
  4. Add to .gitignore: Prevent committing to version control
  5. Review List: Always check the preview before confirming

Troubleshooting

Script Hangs at Confirmation

  • Press n and Enter to cancel
  • Or press Ctrl+C to force exit

Permission Denied

chmod +x scripts/remove-ds-store.sh

All Deletions Failing

  • Verify delete permissions on storage account
  • Check if container has delete lock
  • Ensure blobs aren’t in immutable storage

Files Reappear

  • Check upload processes that might be adding them
  • Configure macOS to stop creating them
  • Add filters to upload scripts

Additional Notes

Storage Savings

Each .DS_Store file is typically 6-12 KB. While small individually, they add up:
  • 100 files = ~1 MB
  • 1000 files = ~10 MB

Security Consideration

.DS_Store files can reveal:
  • Folder structure
  • File names (including deleted files)
  • Custom metadata
Removing them improves security by not exposing this information.