Skip to content

Instantly share code, notes, and snippets.

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 lorey/e8850bd81008fef9f0c0bcca16b85275 to your computer and use it in GitHub Desktop.
Save lorey/e8850bd81008fef9f0c0bcca16b85275 to your computer and use it in GitHub Desktop.
Delete all files that contain a specific string via command line
# say we want to delete all files that contain the string "trash"
# source: https://stackoverflow.com/a/4529138
# 1) create a file that lists all files to delete
find .cache/ | xargs grep -l "trash" | awk '{print "rm "$1}' > delete.sh
# 2) check for errors and stuff
vim delete.sh
# 3) make the file executable and execute
sudo chmod +x delete.sh
./delete.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment