How can I delete with a script each file with an extension that is present in a list of file extensions? The list must be included in the script itself as I need to remove easily a bunch of files that are generated when I run another program.
I want to delete all the files with certain extensions from the current directory only (no subdirs) without returning errors if they don't exist.
I want to run the script from terminal. The extensions will always be the same. I need to delete e.g. some .log and .txt that are generated from another program but I don't need, so I don't need any command line arguments, just $ myscript
.
I don't know pretty anything about bash scripting. I wrote some tests but I deleted them because they didn't work. In pseudocode it should be something like this:
myexts = .log, .txt, .somethingelse for ext in myexts: if exists *.ext delete *.ext
I tried the code suggested by ilkkachu but I get
$ ./myscript find: ‘’: No such file or directory find: ‘’: No such file or directory find: ‘’: No such file or directory
I tried to change the extensions in the list and to create files with the extensions in the original list but I always get this error.
rm *.foo *.bar *.baz
sufficient?"$dir"
in the script with the actual target directory, or just.
if you want to start at the current directory. I edited the answer a bit.