Reputation: 56
I am looking for a way to truncate all the files in several folders recursively. I need this because I am working on an installer where I want to keep all the files that will ship in the installer, but I want to truncate all of them so I can build my installer packages faster for testing purposes.
Any batch script or tools to do this? This is for Windows system and i use cygwin.
Upvotes: 0
Views: 1205
Reputation: 902
I propose you a simple script to make a copy of the file structure. Two options: only create empty files, or copy the first n blocks of the original files. See man touch and man dd
dirIn="xxxxx" #your original directory
dirOut="yyyy" #the fake data dir used to test the packaging code
find $dir -name "*" | while read line
do
fname=${line##*/}
dirName=${line%/*}
# create directory in the target test dir
mkdir -p ${dirOut}/$dirName
# first option: create an empty file (you can also set permissions and times, see man)
touch ${dirOut}/$dirName/$fname
# other option: create a file by copying only 1 block from the input
dd if=$line of=${dirOut}/$dirName/$fname count=1
done
Upvotes: 0