Linux commands to empty all files of a directory

Posted by Damodar Bashyal on August 25, 2015

 

Below are few commands to empty content of a file that already exists in a directory.

1. Empty one file

$: > filename.ext

2. one or more files within a folder / directory

1st$: find . -type f -exec sh -c '>{}' \;

2nd$: find . -type f -exec sh -c '>"{}"' \;

3rd$: for f in *; do >$f; done

My favorite one from above to truncate content of files is the 3rd one from above.

If you know / have your favorite command let me know below on comment section.

 
not published on website


QR Code: Linux commands to empty all files of a directory