Bash aliases are great, so is dired.

Lobsters·34 points·sebboh·over 8 years ago

<p>I don't know why it took me so long to create this, but from here on out, it's going on all my machines and I'll use it a few times per week at work.</p> <pre><code>alias spaces2underscores='for i in *; do mv -iv "$i" "${i// /_}"; done' </code></pre> <p>Usage:</p> <pre><code>hobbes@metalbaby:~/projects/apache/20180119-brianna$ spaces2underscores renamed 'LHD Map Jan 2018.pdf' -&gt; 'LHD_Map_Jan_2018.pdf' renamed 'Contacts List.xls' -&gt; 'Contacts_List.xls' </code></pre> <p>Previously, I would do <code>emacs .</code> followed by <code>C-x C-q M-x replace-string SPC _ RET C-c C-c C-x C-c</code>, which accomplishes the same goal, and felt amazing when I did it to hundreds of files at a time. Of course, I'll still use this method if the replacement is more complex than <code>SPC -&gt; _</code>...</p>

Related stories

Related topics