Skip to content

Instantly share code, notes, and snippets.

@benatkin
Last active August 29, 2015 14:01
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 benatkin/47cc4e5e24da9cc4cadb to your computer and use it in GitHub Desktop.
Save benatkin/47cc4e5e24da9cc4cadb to your computer and use it in GitHub Desktop.
script for removing some files
#!/usr/bin/env node
var fs = require('fs')
var dirs = fs.readdirSync('.')
dirs.forEach(function(dir) {
console.log('#rm -r ' + '"' + dir.replace('"', '"\'"\'"') + '"')
})

This is just a script for generating a script of commented out rm -r commands that I can uncomment. I can quickly uncomment lines (one or a few at a time) in vim of things I want to remove. I use this to clean out my Downloads folder. I can keep the script as a record of what's been deleted.

If you use this script, just make sure you're in the right directory when you run the generated rm commands, and only uncomment commands that you're sure you want to run.

I keep this script in ~/bin which is not on my path. I go to the directory that contains the files, some of which I want to remove, and run this:

$ ~/bin/gen-rm-script > rm-some.sh

Then I open it up in vim, edit it, and run:

$ sh rm-some.sh
@benatkin
Copy link
Author

Improvement idea: move them all to another directory that I can inspect and remove. Could also be used for sorting.

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