I use this script to open Microsoft Office documents in Office Online to convert them to PDF (for my work) and preserve the formatting. Script to view office documents in Microsoft Office Online
The script basically copies the docx file to my ~/Dropbox/Public directory. Then it grabs the public URL and appends it to the Office Online link to view documents in the browser.
I often forget to clear out the ~/Dropbox/Public directory after opening in Office Online. The following command works from terminal to clear out this directory, but I have been unable to incorporate it successfully into my script. (I have tried adding it to the end of it and have tried other ideas.) The command below deletes all files in the ~/Dropbox/Public directory but one. Any help or suggestions are much appreciated.
sleep 60
rm /home/brock/Dropbox/Public/!(My-Document.docx)
Another possibility (see script for variable reference). This one I assume would delete only the copied file.
sleep 60
rm /home/brock/Dropbox/Public/$Filename