How to remove trailing whitespace of all files recursively?

前端 未结 15 1992
难免孤独
难免孤独 2020-12-07 06:58

How can you remove all of the trailing whitespace of an entire project? Starting at a root directory, and removing the trailing whitespace from all files in all folders.

15条回答
  •  误落风尘
    2020-12-07 07:59

    Use:

    find . -type f -print0 | xargs -0 perl -pi.bak -e 's/ +$//'
    

    if you don't want the ".bak" files generated:

    find . -type f -print0 | xargs -0 perl -pi -e 's/ +$//'
    

    as a zsh user, you can omit the call to find, and instead use:

    perl -pi -e 's/ +$//' **/*
    

    Note: To prevent destroying .git directory, try adding: -not -iwholename '*.git*'.

提交回复
热议问题