recursively add file extension to all files

前端 未结 6 1890
盖世英雄少女心
盖世英雄少女心 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:21

    Alternative command without an explicit loop (man find):

    find . -type f -exec mv '{}' '{}'.jpg \;
    

    Explanation: this recursively finds all files (-type f) starting from the current directory (.) and applies the move command (mv) to each of them. Note also the quotes around {}, so that filenames with spaces (and even newlines...) are properly handled.

提交回复
热议问题