I want to empty my Download folder at shutdown, so I created a simple bash script /etc/init.d/empty_download_folder.sh:

rm -rf /home/USER/Downloads/*

then changed the permissions:

sudo chmod +x empty_download_folder.sh

Now created symbolic links so the script runs on shutdown and reboot:

sudo ln -s /etc/init.d/empty_download_folder.sh /etc/rc0.d/empty_download_folder
sudo ln -s /etc/init.d/empty_download_folder.sh /etc/rc6.d/empty_download_folder

The bash script works, but does not run at shutdown/reboot

  • 3
    Which version of Ubuntu? – muru Jul 19 '17 at 7:44
  • Ubuntu 17.04 zesty – API Jul 19 '17 at 7:47
  • 17.04 uses systemd place your script at /lib/systemd/system-shutdown/ – Ravexina Jul 19 '17 at 7:54

Reread man bash - it says, in part,

When  a  login  shell  exits, bash reads and executes commands from the
file ~/.bash_logout, if it exists.  

~/.bash_logout is a better place to put your cleanup.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.