How to remove trailing whitespace of all files recursively?

前端 未结 15 1989
难免孤独
难免孤独 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:57

    Ack was made for this kind of task.

    It works just like grep, but knows not to descend into places like .svn, .git, .cvs, etc.

    ack --print0 -l '[ \t]+$' | xargs -0 -n1 perl -pi -e 's/[ \t]+$//'
    

    Much easier than jumping through hoops with find/grep.

    Ack is available via most package managers (as either ack or ack-grep).

    It's just a Perl program, so it's also available in a single-file version that you can just download and run. See: Ack Install

提交回复
热议问题