I'm working in a large project with ~35,500 files and I want o know if I cold convert the indentation of the entire project. I know I can do
unexpand -t 4 <file>
but I can't run it for every single file.
I was thinking about some way of doing it with tree
, which I know I can manipulate to print every file name with complete path... or does someone know a shell program that can iterate over all files in folder and subfolders so I could use unexpand
?
As unexpand
does not have an overwrite option, please try:
#!/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)
The line starts with cp
just copies the attributes of the original one. You can comment-out the line if it does not work.
Please make sure to back up the original files before execution.