Bash – Delete content of file but keep name and hierarchy

bashfilesfindzsh

I have mirrored a directory structure but I don't care about the content of the files, I just want to keep the name and structure of everything.

How can I replace all files' (not folders) content with "nothing" (null, 1 byte, empty string or something like that)?

Best Answer

Generically,

find /top -type f -exec cp /dev/null {} \;

or (courtesy of jordanm):

find /top -type f -exec sh -c '> $1' -- {} \; 

On a Linux system (or one with the truncate command from the GNU coreutils package):

find /top -type f -exec truncate -s 0 {} +