How To Automatically Remove EXIF & Metadata From Your Files
Whenever you go to take a picture or write a document there's a range of hidden data that isn't seen on first glance. Details such as date the picture was taken, location, type of camera used and encoding format is all included in an image's metadata. You may say that this is inherently harmless but this data is just another way for the sites we use (and the people viewing our content) to gather further insight into our behaviour and activities. Although some social media sites such as Facebook and Instagram remove this data when a file is uploaded, trusting these sites is a bad habit we should quickly get rid of.
In a previous article I discussed how you can host a range of cloud services on your own private server. In this article I'm gonna discuss how you can remove EXIF data in bulk from your files and how to set it up so you can do this automatically when you create/upload a new file.
The Technical Details
I created a basic shell script that searches through all the files in a folder and removes the metadata. This is done in a single line that can be seen below.
mat2 --unknown-members omit --inplace $my_directory
Now if like me you have a rake of old photos that make you question what the fuck you're doing with your life you can run this script on any linux/ MacOS terminal. You'll need to replace the $my_directory variable with whatever your directory location is.
I didn't want to keep running this whenever I had new files. Especially since my NextCloud instance is connected to multiple devices including my phone. So I needed a way to automatically do this on my cloud server whenever I added a new file. You could also easily do this on your local computer by following the same steps.
I created an additional shell script that uses the inotify-tools library to detect when a file is created. It then calls the other script mentioned above. You can see the code below.
while : do sleep 10 while inotifywait -r -e create $my_directory; do # Sleep for 10 seconds in case there are a few files being uploaded sleep 10 /usr/bin/remove_bulk_data.sh -d $my_directory done done
Then I created a SystemD service so that this runs in the background. SystemD is just a service manager (among a load of other things) that is used for running all the low-level services on your linux OS. If you wanna check out the Service file that runs the script or any of the other scripts you can check out my Github repo below.
(Glan is the Irish word for clean if you're curious)
That's basically it. You'll need to edit the files with your directory and you'll need to start the service but following the steps in the Github repo should make it work. Now you'll have to worry less when you upload your photos to an other site that you don't own. If there's any concerns or suggestions for how this could be improved please feel free to let me know.
Stay happy and stay private.