<span class="mw-page-title-namespace">Blog</span><span class="mw-page-title-separator">:</span><span class="mw-page-title-main">Hacks/Stripping extension from files</span>
Elena & Fabrice's Web

Stripping extension from files

From laussy.org's Blog about Hacks.
Published: 20:13, 21 March 2012.

The following command allows a variety of useful operations on files based on stripping their extension:

find . -name '*.dat' | while read f; do echo "$f" "${f%.dat}"; done

The above command listed *dat* file without the said extension. Below we put tar archives in directories named after them (prevention of tarbombs).

find . -name '*.tar' | while read f; do mkdir "${f%.tar}"; done find . -name '*.tar' | while read f; do mv "$f" "${f%.tar}"; done