55 lines
1.5 KiB
Markdown
55 lines
1.5 KiB
Markdown
# rename-ext
|
||
|
||
> changes file-extension based on mime-type
|
||
|
||
### also
|
||
|
||
- removes `*?|^:"<>` characters from the file-name
|
||
- reducing multiple spaces, dots, and underscores
|
||
- adds rename-date suffix to ensure uniquness of the filename
|
||
- strips exec-flag from non-executive types (usual leftover from FAT/NTFS)
|
||
- optimizes images while at it (shows reduction size in `kb` and `%`)
|
||
|
||
|
||
## install
|
||
|
||
1. look at [install](./install.sh) file for instructions
|
||
2. adjust `PREFIX` at wish
|
||
3. make sure the final directory is on `$PATH`
|
||
|
||
|
||
## use
|
||
|
||
`rename-ext /Data/Pictures/_unsorted/**/*`
|
||
|
||
to only change extension and nothing else:
|
||
|
||
`rename-ext --only-ext /Data/Photos/2020/*`
|
||
|
||
to only print a report:
|
||
|
||
`rename-ext --test-run /Data/Docs/_dump/*`
|
||
|
||
|
||
## requires
|
||
|
||
- [`file`](https://darwinsys.com/file/) - to determine file type
|
||
- [`sd`](https://github.com/chmln/sd) – better sed
|
||
- [`jpegoptim`](https://github.com/tjko/jpegoptim) – to compress JPEGs
|
||
- [`imagemagick`](https://imagemagick.org/)
|
||
or [`graphicsmagic`](http://www.graphicsmagick.org/) – to mogrify PNGs
|
||
- [`pngcrush`](https://github.com/Kjuly/pngcrush) – to compress PNGs
|
||
<!-- - [`pngquant`](https://github.com/kornelski/pngquant) – to compress PNGs -->
|
||
|
||
|
||
## todo
|
||
- [ ] find better determination tool for `application/octet-stream`
|
||
- [ ] leverage `fd` to do recursive paralel execution if some of parameters are folders
|
||
|
||
|
||
## q&a
|
||
|
||
**Q**: why not just rename files to hashes of their contents, and store original filenames in some database?
|
||
|
||
**A**: good point. that database is in my case a filesystem itself.
|