I want to delete a bunch of files using the exec node.
When I try to start the job with the payload
the exec node tells me:
rm: cannot remove '/mnt/dietpi_userdata/File-to-delete*': No such file or directory
What am I doing wrong? A single file in this directory is possible to delete, Node-RED has sufficient rights in this directory...
I think the issue is the
* - it doesn't get expanded the way it would when you run the command in a local shell normally. So it is looking for a file called literally
I think it has something to do with the file spec being put in quotes?
I don't see any problem using exec to rm /home/pi/junk/delete*, suggesting that there is no mistake in interpretation of the asterisk.
And if there are in fact no files to delete the error message in debug is
rm: cannot remove '/home/pi/junk/delete*': No such file or directory
ie the single quotes are an artifact of the error message (of course single quotes around the command would break it).
So what do your actual filenames look like?
Does it make a difference if you try to delete multiple files in a local directory rather than on a mounted filesystem?
Does it work if you change the command to this?
for f in /mnt/dietpi_userdata/File-to-delete*; do rm $f; done
How did you install node-red? Is this a Docker install for example?
How is that folder mounted?
In the exec node try running
ls -l /mnt/dietpi_userdata to check whether you can see the directory.
The filenames are like
Using your command ends up with
@Colin: it's a local install, no docker installation.
I can use the directory, and also delete ONE file if I write in the command the whole filename without an asterisk. So, like @knolleary said, it seems to not getting expanded like in the local shell...
Yes, I can see all of the files in the directory.
If I try to list via
ls -l /mnt/dietpi_userdata/Back* I get the same error as before.
Can you try
ls -l "/mnt/dietpi_userdata/Back*"
I don't expect it to be any different.
You're right - no difference:
ls: cannot access '/mnt/dietpi_userdata/bb_config/Back*': No such file or directory
I presume the bb_config directory does exist, you just left it out of previous replies here!
I'm not sure how to find out... it's the default user directory in DietPi. Since I am far away from a linux expert (normally using a mac for every-day-use), I have no idea, where to look. If it's important to know - please give me a hint...
Yes, you're right!
The directory does exist, and also the files!
And: Node-RED Exec can have access to the files and also delete one by one - but not, if I try to delete all of my "Backup_"-Files.
Yes I understand your exec can delete them one by one but not en masse.
It is puzzling because I find that the exec node does successfully pass the asterisk to bash on the target machine. ie exec can delete using asterisk.
My setup is not identical to yours: my Linux machine runs RpiOS and I don't have any mounted filesystems. Nevertheless, it ought to work for you.
A massive overkill exec command to try:
This should find all "normal" files (ie not directories) which are below /mnt/dietpi_userdata and whose names start with "delete" (change as appropriate)
Since the filename pattern is enclosed in single quotes, it should be protected until find interprets it.
Each file it finds will be deleted.
The files removed will be listed in the exec node output.
find /mnt/dietpi_userdata -name 'delete*' -type f -print0 | xargs -0 rm -v
Use with caution - a typo in the path could remove files you don't want removed.
You can also try writing a shell script on the dietpi mahine, containing the same as your exec command, then exec that script. By moving the asterisk expansion onto the target machine it removes exec as a possible source of error
Command in the
exec node to 'rm'
.* at the end
works fine for me. If no files exist the exec node returns
rm: cannot remove '/home/pi/atestdelete/file0*.*': No such file or directory
Note that is from my test
This works also for me - and it also does the job without the
.* at the end. Seems to be something special with the
Now I can carry on!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.