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:Usage
- Search for all
.DS_Storefiles - Display the list of files found
- Ask for confirmation
- Delete confirmed files
- Show summary
Output
Features
- Recursive Search: Finds
.DS_Storefiles 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
yorY- Proceed with deletionn,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
- Not needed in cloud storage
- Clutter the file listing
- Can expose folder structure information
- Waste storage space (small but unnecessary)
Safety Features
- Preview Before Delete: Shows complete list of files
- User Confirmation: Requires explicit approval
- Cancellable: Can abort at confirmation prompt
- No Wildcards: Only targets exact
.DS_Storefilename
Examples
Standard Usage
Non-Interactive (Auto-Confirm)
For automation, modify the script to skip confirmation:Dry Run (Check Only)
To see what would be deleted without actually deleting:Error Handling
No Files Found
Failed to Fetch Storage Key
az login and verify access
Deletion Failures
Individual failures are tracked:- Blob is locked
- Insufficient permissions
- Blob was already deleted
Prevention
Prevent Future .DS_Store Files
Add to.gitignore:
macOS Settings
Disable.DS_Store on network volumes:
Upload Scripts
Filter out.DS_Store when uploading:
Automation
Scheduled Cleanup
Add to cron for weekly cleanup:CI/CD Integration
Verification
Check for .DS_Store Files
Count .DS_Store Files
Best Practices
- Run Periodically: Schedule regular cleanups
- Check Before Upload: Filter
.DS_Storeduring uploads - Configure macOS: Disable network
.DS_Storecreation - Add to .gitignore: Prevent committing to version control
- Review List: Always check the preview before confirming
Troubleshooting
Script Hangs at Confirmation
- Press
nand Enter to cancel - Or press Ctrl+C to force exit
Permission Denied
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
Related Scripts
- list-media-files.sh - View all files including
.DS_Store
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