I have my files sorted by date to easily work with the most recent files. I also have a bunch of logs redirected to /dev/null in my home directory that I would like to be shown at the end. I tried to create a systemd service for this, but it doesn't work somehow:
$ cat /etc/systemd/system/devnull1975.service
[Unit]
Description=Change /dev/null modification time to 1975
After=display-manager.target
[Service]
Type=oneshot
ExecStart=/usr/bin/touch -c -t 197501010000 /dev/null
[Install]
WantedBy=default.targetIt works if I start it manually and it is being run on reboot. "after display manager" looks like a point where /dev/null was already created but after reboot it still has current date is stat output. So, can anyone see what the problem is?
1 Answer
First, /dev/null is a special file, not a directory. It's primary purpose is to handle redirection of stdout and stderr. When logs are redirected to the folder, they no longer exist.
Some reference material, Here
With regards to the files in your home directory, it may better to switch from the direct command: /usr/bin/touch -c -t 197501010000 /dev/null
To
/usr/local/bin/mynewscript.shThough use your own new file name. So with your favorite editor create the new file, add contents such as: (Change the names accordingly)
#!/bin/bash
/usr/bin/touch -m -t 197501010000 /home/username/.bzr.log
/usr/bin/touch -m -t 197501010000 /home/username/.xsessions-errors.old
/usr/bin/touch -m -t 197501010000 /home/username/.php_history
/usr/bin/touch -m -t 197501010000 /home/username/.recently-usedSet execute, on your file:
chmod 455 /usr/local/mynewscript.shNext change your service file: /etc/systemd/system/devnull1975.service
[Unit]
Description=Changes modified times on log file locate /home/username/
After=graphical-session.target
[Service]
ExecStart=/bin/sh /usr/local/bin/mynewscript.sh
Type=oneshot
[Install]
WantedBy=multi-user.target
Alias=file-touch.serviceUse the following to verify no errors are found with the .service file
systemd-analyze verify /etc/systemd/system/devnull1975.serviceRefer to this link for more information on systemd.
6