xxxxxxxxxx
# Remove last occurrence of any extension from the supplied file path
echo filename.ext | sed 's/\.[^.]*$//'
# Example
$ echo multi.period.filename.ext | sed 's/\.[^.]*$//'
multi.period.filename
# Remove the filename leaving only the extension
echo multi.period.filename.ext | sed -r 's/^.*\.//'
# Example
echo multi.period.filename.ext | sed -r 's/^.*\.//'
ext
xxxxxxxxxx
import os
for file in os.scandir(path):
if file.name.endswith(".bak"):
os.unlink(file.path)