Why can't I delete a file with a Bash script?
17,849
First, make sure that you can delete myjunk.out without running your script; if not, check file attribute with lsattr
.
Second, You don't need to providing exit 0;
Later, point a path to myjunk.out, such as:
rm -rf /path/to/myjunk.out
Related videos on Youtube
Author by
Dony Joe
Updated on September 17, 2022Comments
-
Dony Joe over 1 year
I can't seem to run
rm
from a Bash script and remove a file.#!/bin/bash rm -rf myjunk.out exit 0;
doesn't remove
myjunk.out
.-
Pylsa about 13 yearsAnd it DOES work when you just execute
rm -rf myjunk.out
from the command line? What is triggering execution of this script? -
Torian about 13 yearsJust for the record, -r is meant to descend on directories (Recursive), so if you intend to remove a file, -r is futile. What error do you get ? How do you run this script ? What are the permissions on this script ?
-
Dony Joe about 13 years@BloodPhilla it's triggered because myjunk.out is generated earlier in the script.... @Torian -r was in there because I was just trying stuff out
-
-
Keith about 13 yearsAlso remove the
-r
flag. it is unnecessary and dangerous. -
Dony Joe about 13 yearsActually, taking out the exit 0; allowed rm installed.out to execute properly. Thanks!
-
Emmanuel Devaux about 10 yearsWhat is the explanation of : Why the "exit 0" will make the rm not working
-
Chenmunka about 8 yearsThis is more of a comment than an answer.