How to clear content of multiple files at once

When I am updating my Linux template, I like to delete all old logs, as a first step, I delete old rotated logs. First check how your logs are rotated and create a find command the one below to delete old rotated logs:

The command above will delete all file that match the rule, you can limit how deep you want to find files using maxdepth. you can also use mtime +n to find files older than n days and delete them.

Now it's the time to empty the content of file, this helpful if your find rules did not catch some files, or you don't want to delete active log file.

Explanation:

This will empty the content of all files in /var/log/, concatenate /dev/null (/dev/null is a special file system object that hides the output) to each item.

References: