Created
March 26, 2020 19:46
-
-
Save 100ideas/9f0c975c25de483ef14e7c1565be3ffe to your computer and use it in GitHub Desktop.
recursively finds "hidden" .DS_store files then prompts to delete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# delete-all-ds_store.command | |
##################################################################### | |
# @100ideas - 26 mar 2020 - MIT LICENSE | |
# | |
# recursively finds "hidden" .DS_store files under the directory | |
# from which this command is run, then offers delete prompt | |
# | |
# if you have just downloaded this file, open iterm.app, drag | |
# this file into the terminal window and drop it to insert the file's | |
# path into the command line. Then add 'chmod +x ' to the left side of | |
# the command line and hit enter. Should look something like: | |
# | |
# $ chmod +x ~/Users/USERNAME/Downloads/delete-all-ds_store.command | |
# | |
# this updates the permissions on this script so it can be executed. | |
# | |
# to use: | |
# | |
# 1. open iTerm.app, | |
# | |
# 2. navigate to the folder containing the .DS_Store files to be removed | |
# - note: use the 'cd' command to change directories | |
# - note: use the 'ls' command to list directory contents | |
# - 'ls .' -> list current dir contents | |
# - 'ls ../PARENT_FOLDER/SIBLING_FOLDER' -> list contents of | |
# sibling folder ('..' means relative to parent folder) | |
# - note: use the '~' tilde symbol as a unix shortcut for your HOME | |
# directory | |
# - note: use the 'pwd' command to print the full path of the | |
# (current) "working" directory your terminal is "in" | |
# - example: to get to the folder 'TPS_Reports/' stored on your | |
# Desktop, type `cd ~/Desktop/TPS_Reports` | |
# | |
# 3. drag-and-drop this 'delete-all-ds_store.command' file into the | |
# terminal and hit enter | |
# - alternatively, execute the script providing the path to it on disk, | |
# then hit enter. Example: if the script is in the parent | |
# directory, execute "../delete-all-ds_store.command" | |
# | |
##################################################################### | |
filename='.DS_Store' | |
# filename='.DS_MOCK_*' | |
echo "" | |
echo "" | |
echo "============.DS_Store-SEARCH-N-DESTROY=====================" | |
echo "searching for '$filename' files in current directory and children:" | |
echo "" | |
echo "search command:" | |
echo " find . -name \"$filename\" -type f -print" | |
found=$(find . -name "$filename" -type f -print) | |
found_count="$(echo "$found" | wc -l | tr -d '[:space:]')" | |
echo "" | |
if [[ -z "$found" ]]; then | |
echo 'found 0 results, exiting...' | |
exit | |
fi | |
echo "found $found_count files under" | |
echo " $(PWD) " | |
echo "" | |
echo "$found" | |
echo "" | |
echo "to DELETE type 'Y', any other key quits..." | |
echo "" | |
# read a single character | |
while read -r -n1 key; do | |
# if input == ESC key | |
if [[ $key == 'Y' ]]; then | |
echo "" | |
echo "deleting..." | |
echo "" | |
find . -name "$filename" -type f -delete -print | |
echo "" | |
echo "... files deleted. exiting..." | |
break; | |
else | |
echo "... delete operation cancelled; exiting..." | |
break; | |
fi | |
done | |
echo "" | |
echo "========================FINISHED===========================" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment