Using Task Manager to delete files start with ~$

Questions and mods regarding system management may go here
Forum rules
1) This is a user forum for Synology users to share experience/help out each other: if you need direct assistance from the Synology technical support team, please use the following form:

https://account.synology.com/support/su ... p?lang=enu



2) To avoid putting users' DiskStation at risk, please don't paste links to any patches provided by our Support team as we will systematically remove them. Our Support team will provide the correct patch for your DiskStation model.
hanbichi
I'm New!
I'm New!
Posts: 4
Joined: Thu May 17, 2018 11:43 am

Using Task Manager to delete files start with ~$

Unread post by hanbichi » Thu May 17, 2018 12:08 pm

Hello, I am Hanbit, and I recently bought DS918+.
I would like to delete every file start with ~$ (for instance, '~$Lorem Ipsum.xlsx') in volume1.

As I am totally new to Linux, I googled and tried plenty of cases but I couldn't solve this matter.

Here's my try and it didn't work :
1) Created an sh file : "delete_temp_files.sh" in "/volume1/PHB/Script/" (/volume1/PHB/Script/delete_temp_files.sh)
- command line is as below :
cd /
find . -type f -name ~$*.* -exec rm {} \;

2) Created user-defined script by Task Scheduler
- Task name : delete_temp_files
- user : root
- schedule : Daily at 03:00
- Run command : /volume1/PHB/Script/delete_temp_files.sh

Don't really know why it doesn't work :(

Is there any fault? Thank you in advance.

User avatar
Twisted World
Enlightened
Enlightened
Posts: 439
Joined: Sun Jun 12, 2016 8:29 am
Location: Netherlands
Contact:

Re: Using Task Manager to delete files start with ~$

Unread post by Twisted World » Thu May 17, 2018 4:09 pm

Did you chmod the .sh to be executable?
[ DS916+ | DS216+II | DS1815+ | EDS14 | DS212+ | DS211+ | DS411slim ]

hanbichi
I'm New!
I'm New!
Posts: 4
Joined: Thu May 17, 2018 11:43 am

Re: Using Task Manager to delete files start with ~$

Unread post by hanbichi » Fri May 18, 2018 1:13 pm

Twisted World wrote:
Thu May 17, 2018 4:09 pm
Did you chmod the .sh to be executable?
As I mentioned I am totally new to Linux, so I don't understand what you say...
I'm sooooo sorry, but could you give me details?

User avatar
Twisted World
Enlightened
Enlightened
Posts: 439
Joined: Sun Jun 12, 2016 8:29 am
Location: Netherlands
Contact:

Re: Using Task Manager to delete files start with ~$

Unread post by Twisted World » Fri May 18, 2018 2:04 pm

Sorry, somehow missed the part of being new at linux.

In linux you cannot just create a .sh file and execute it like a program. Basically you are just creating a textfile with commands that has the extension .sh. And that is what is will remain if you don't change it; just a file containing text.

chmod is a Linux command to set permissions on a file. You can set the permissions to only read it, to read and write it but also to actually execute the program.

(I think) for safety reasons newly created files are not executable by default, you need to specifically set the permissions of the file to be an executable file.

So after creating the file you need to enter the command "chmod +x delete_temp_files.sh" which will add the "x" permission (executable) to your file.

But you don't actually need to create a file and make it executable like this (unless you have a specific reason to want to use a file). You can just directly put the commands that are in your .sh file inside of the Task Scheduler.

You could even just have a scheduled task create the file for you and set the right permissions, just like I did with my script to delete songs from an Audio Station playlist. The script actually creates a .sh file, makes it executable, executes it and deletes it again. (https://forum.synology.com/enu/viewtopi ... 90#p527990)

So, there's many ways to approach this, but in your case you need to at least make sure the file has the executable attribute set.
[ DS916+ | DS216+II | DS1815+ | EDS14 | DS212+ | DS211+ | DS411slim ]

hanbichi
I'm New!
I'm New!
Posts: 4
Joined: Thu May 17, 2018 11:43 am

Re: Using Task Manager to delete files start with ~$

Unread post by hanbichi » Thu May 24, 2018 11:28 am

What I've tried again :

1.Directly put the commands inside of Task Scheduler.

Code: Select all

cd /
find . -type f -name ~$*.* -exec rm {} \; 
→ Not working.

2.Gave "delete_temp_files.sh" a permission(executable).
1) Inside of Task Scheduler

Code: Select all

cd /volume1/PHB/Script
chmod +x delete_temp_files.sh
./delete_temp_files.sh
2) Command inside of delete_temp_files.sh

Code: Select all

cd /
find . -type f -name ~$*.* -exec rm {} \;
→ Not working.

None of them works. :(

But I tried this as a test, and it worked. But I still need to delete files start with "~$".
Inside of Task Scheduler,

Code: Select all

cd /
find / -name temp.xlsx -exec rm -f {} \;
With this code, every "temp.xlsx" file in the NAS are gone, I still don't know what's the difference, though.

Moreover, what is odd is, the code below didn't work.

Code: Select all

cd /
find / -name ~$temp.xlsx -exec rm -f {} \;
The name of the files I want to delete are starts with "~$" and have some spaces and Korean characters. Does this make difference?
Twisted World wrote:
Fri May 18, 2018 2:04 pm
Sorry, somehow missed the part of being new at linux.

In linux you cannot just create a .sh file and execute it like a program. Basically you are just creating a textfile with commands that has the extension .sh. And that is what is will remain if you don't change it; just a file containing text.

chmod is a Linux command to set permissions on a file. You can set the permissions to only read it, to read and write it but also to actually execute the program.

(I think) for safety reasons newly created files are not executable by default, you need to specifically set the permissions of the file to be an executable file.

So after creating the file you need to enter the command "chmod +x delete_temp_files.sh" which will add the "x" permission (executable) to your file.

But you don't actually need to create a file and make it executable like this (unless you have a specific reason to want to use a file). You can just directly put the commands that are in your .sh file inside of the Task Scheduler.

You could even just have a scheduled task create the file for you and set the right permissions, just like I did with my script to delete songs from an Audio Station playlist. The script actually creates a .sh file, makes it executable, executes it and deletes it again. (https://forum.synology.com/enu/viewtopi ... 90#p527990)

So, there's many ways to approach this, but in your case you need to at least make sure the file has the executable attribute set.

hanbichi
I'm New!
I'm New!
Posts: 4
Joined: Thu May 17, 2018 11:43 am

Re: Using Task Manager to delete files start with ~$

Unread post by hanbichi » Thu May 24, 2018 12:53 pm


Post Reply

Return to “System Managment Mods”