Truncate many large file with awk xargs

ls -la | grep ‘pattern’ | awk ‘{ print $9 }’ | xargs -I% truncate -s 0 %


  • awk is used to print out the file name
  • xargs with pipe (|) will pick the file name from the previous step then call the truncate function, -I in xargs is substitution (can use: any character, for eg: % or {} or $, …)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.