Stripping extension from files

⇠ Back to Blog:Hacks

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