Skip to content

Instantly share code, notes, and snippets.

@Skn0tt
Last active August 22, 2019 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skn0tt/ffa32b35a0e725d4e6f6488e06ea8e09 to your computer and use it in GitHub Desktop.
Save Skn0tt/ffa32b35a0e725d4e6f6488e06ea8e09 to your computer and use it in GitHub Desktop.
Anonymise a folder

Anonymise.sh

This script makes the metadata of all files in the execution directory unknown. It changes the owner to "nobody" and sets the creation date as well as the modification date to 01.01.2001 12:00.

#!/bin/bash
echo "Are you sure you want to anonymise this directory?"
select yn in "Yes" "No"; do
case $yn in
Yes )
shopt -s dotglob
for f in * **/* ; do
sudo chown nobody "$f"
sudo touch -t 200001011200 "$f"
done;
shopt -u dotglob
exit;;
No ) exit;;
esac
done
@jstimpfle
Copy link

Hi, I found your website and came to say, keep up the great work! And a little note, always quote variables in sh/bash, as in "$f". Otherwise they will be split at whitespace (before i.e. chown can see them) and even undergo glob expansion and possibly other things happen.

@Skn0tt
Copy link
Author

Skn0tt commented Aug 22, 2019

Thanks a lot for the compliment, I appreciate it! ☺️
Didn't know about quoting variables, but that makes perfect sense. Thanks a lot for bringing it up. I updated the Gist accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment