How can I empty log files with a cron job on WSL?

Where is the log directory in WSL?

There seems to be no such directory as /var/log/.

My aim is to run this *nix cron daily command:

0 0 * * * cat /dev/null > /var/mail/* /var/log/*
3

1 Answer

/var/log is at /var/log (at least in the version 16.04.3 LTS that I just installed in my Windows system).

$ ls -l /var/log
total 304
drwxr-xr-x 0 root root 512 Sep 22 18:15 apt
-rw-rw---- 1 root utmp 0 Sep 22 18:15 btmp
drwxr-xr-x 0 root root 512 Jul 19 01:29 dist-upgrade
-rw-r--r-- 1 root root 12794 Sep 22 18:15 dpkg.log
drwxr-xr-x 0 root root 512 Sep 22 18:13 fsck
-rw-rw-r-- 1 root utmp 292292 Jan 14 19:58 lastlog
drwxr-xr-x 0 root root 512 Aug 23 04:06 lxd
drwxr-x--- 0 root adm 512 Aug 1 04:46 unattended-upgrades
-rw-rw-r-- 1 root utmp 0 Sep 22 18:15 wtmp

But you won't be able to redirect your output to a list of files and subdirectories (as I told you in the comments).

You can empty all log files by the following cronjob (for root):

find /var/log -type f -exec truncate -s 0 {} \;

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like