Score:2

Delete All Files in a Directory Except One on every sunday 20 hour

br flag

I use this option

In autodelete.sh

rm -rf /home/user/Public/!("VIP Folder")

In Crontab

0 20 * * 0 /home/autodelete.sh

but it is does not work.

Score:5
cn flag

The !(pattern) syntax is part of the extended globbing capabilities of bash and this isn't on by default. You need to make sure that your script is using bash and not sh, and you need to enable the relevant option. So make your autodelete.sh file look like this:

#!/bin/bash

shopt -s extglob
rm -rf /home/user/Public/!("VIP Folder")

The quotes are optional in this case, but don't hurt either and are a good habit to have.

Also, your crontab line will run this command every day at 20:00 and not every Sunday only. To run it at 20:00 on Sundays, use:

0 20 * * 0 /home/autodelete.sh
terdon avatar
cn flag
Good point, @steeldriver, thanks.
Salai Robin avatar
br flag
Thank u so much it work, @steeldriver
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.