How to remove trailing whitespace of all files recursively?

前端 未结 15 1994
难免孤独
难免孤独 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 08:00

    Here is an OS X >= 10.6 Snow Leopard solution.

    It Ignores .git and .svn folders and their contents. Also it won't leave a backup file.

    export LC_CTYPE=C
    export LANG=C
    find . -not \( -name .svn -prune -o -name .git -prune \) -type f -print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//"
    

提交回复
热议问题