Elena & Fabrice's Web

Stripping extension from files

Blog:Hacks

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

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

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

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

Find:
What links here (Stripping extension from files) | Powered by GNU softwares & MediaWiki |