转换整个文件夹中的缩进

时间:2019-01-21 04:04:25

标签: bash directory indentation subdirectory

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

unexpand -t 4 <file>

但是我不能为每个文件都运行它。

我正在考虑使用tree的某种方式,我知道我可以操纵它以完整的路径打印每个文件名...或者有人知道可以迭代其中所有文件的Shell程序。文件夹和子文件夹,以便可以使用unexpand

1 个答案:

答案 0 :(得分:1)

由于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开头的行仅复制原始行的属性。如果行无效,您可以将其注释掉。
请确保在执行之前备份原始文件。