recursively add file extension to all files

前端 未结 6 1897
盖世英雄少女心
盖世英雄少女心 2020-12-07 07:52

I have a few directories and sub-directories containing files with no file extension. I want to add .jpg to all the files contained within these directories. I\

6条回答
  •  余生分开走
    2020-12-07 08:15

    This is a little late, but I thought I would add that a better solution (although maybe less readable) than the ones so far might be:

    find /path -type f -not -name "*.*" -print0 | xargs -0 rename 's/(.)$/$1.jpg/'
    

    Using the find | xargs pattern generally results in more efficient execution, as you don't have to fork a new process for each file.

    Note that this requires the version of rename found in Debian-flavored distros (aka prename), rather than the traditional rename. It's just a tiny perl script, though, so it would be easy enough to use the command above on any system.

提交回复
热议问题