We often need to use flash drives for our work or for file sharing, but a seemingly routine operation can sometimes become more complicated. Imagine a scenario where you need to work on an USB flash drive and leave no meta-information behind about your computer.
In the case of macOS, this situation is complicated by the fact that, in addition to necessary files, there are a lot of additional files recorded. For instance, directories such as “.Spotlight-V100“, “.Trash“, “.TemporaryItems“, and “.fseventsd” are necessary to store attributes in file systems that do not support them. However, in addition to attributes, information about when the drive was last connected or disconnected, as well as some GUIDs and more, is also stored.
Unfortunately, you can not completely turn off the writing of meta-information on removable media. However, you can permanently delete this information. To do so, you need to install the “srm” utility. This utility enables you to permanently remove files from disks. This is accomplished by repeatedly overwriting the memory blocks of a file with randomly generated data.
Installing the “srm” utility
Using MacPorts
sudo port install srm
Using Homebrew
This utility no longer exists in default Homebrew repository. We will use it’s fork https://github.com/khell/homebrew-srm
brew install khell/homebrew-srm/srm
Remove metadata instruction
We need to prepare the environment. This is necessary because, by default, we cannot access meta-information folders such as “Spotlight-V100“.
- Open “Settings” -> “Privacy & Security” -> “Full Disk Access”
- Give the “Full Disk Access” permission to your terminal application. I prefer to use “iTerm” as terminal application, you can just use default “Terminal”.
After you gave needed permissions, you can go next.
- Open your terminal application. In my case I opened “iTerm”
- Connect your removable media to Mac
- Find your removable media device mount point in the “
/Volume
” directory - Move to directory where your removable media is mounted
- Run
mdutil -i off -d "/Volumes/<MOUNT_POINT>"
- In successful case you will see “
Indexing and searching disabled.
” in result message. - Execute script
find . -name "._*" -or -name ".Spotlight-V100" -or -name ".DocumentRevisions-V100" -or -name ".Trashes" -or -name ".TemporaryItems" -or -name ".fseventsd" -or -name ".DS_Store" -or -name "__MACOSX" -not -path "." | tr \\n \\0 | xargs -0 srm -Rf
- This script recursively search all directories begin from current directory. If we found file that corresponds filter described by our script, we delete this file permanently by
srm
utility. - Remove flash drive
You will need to repeat steps 1-9 every time you use a flash drive. In this case, complete removal of the metadata from your device will be guaranteed.