在整个文件夹中转换缩进

Convert indentation in entire folder

我正在处理一个包含约 35,500 个文件的大型项目,我想知道是否冷转换整个项目的缩进。我知道我能做到

unexpand -t 4 <file>

但我不能 运行 它用于每个文件。

我正在考虑用 tree 来实现它,我知道我可以操纵它来打印每个文件名和完整路径...或者有人知道一个 shell 程序可以遍历文件夹和子文件夹中的所有文件,这样我就可以使用 unexpand?

由于unexpand没有覆盖选项,请尝试:

#!/bin/bash

dir="."
while read -r -d "" file; do
    tmpfile=$(mktemp /tmp/tempfile.XXXXXX)
    unexpand -t 4 "$file" > "$tmpfile"
    cp --preserve=all --attributes-only -- "$file" "$tmpfile"  # will work with GNU cp only
    mv -f -- "$tmpfile" "$file"
done < <(find "$dir" -type f -print0)

cp开头的行只是复制了原来的属性。如果它不起作用,您可以注释掉该行。
执行前请务必备份原文件