Linux - Replacing spaces in the file names

前端 未结 11 675
臣服心动
臣服心动 2021-01-29 18:21

I have a number of files in a folder, and I want to replace every space character in all file names with underscores. How can I achieve this?

11条回答
  •  滥情空心
    2021-01-29 18:46

    To rename all the files with a .py extension use, find . -iname "*.py" -type f | xargs -I% rename "s/ /_/g" "%"

    Sample output,

    $ find . -iname "*.py" -type f                                                     
    ./Sample File.py
    ./Sample/Sample File.py
    $ find . -iname "*.py" -type f | xargs -I% rename "s/ /_/g" "%"
    $ find . -iname "*.py" -type f                                                     
    ./Sample/Sample_File.py
    ./Sample_File.py
    

提交回复
热议问题