I would like to optimize a SVG using software on Ubuntu (and by optimize I mean to reduce the file size without loosing any visible parts of the graphic) and I do mean software I know there are some websites that can do this but I don't trust my internet connection always being good enough for this to work for me. I would also like to keep the file format SVG, I know that SVGZ is usually substantially smaller than its uncompressed counterpart but I am uploading these SVGs to a local MediaWiki installation and it cannot thumbnail SVGZ files to my knowledge (if I'm wrong please do correct me).
I can't think of something better than inkscape.
You can install it usind command:
Take a look for this link for tips to optimize SVG using inkscape.
for comamnd line I think you should take a look for scour
Also take a look for this SE question , it may help.
Use svgo https://spin.atomicobject.com/2016/11/10/svgo-compressing-svg-images/
Works quickly and provides a summary of results
You can use it using the same file for input & output, or not.
Don't be fooled by that small reduction. It is the second pass over already compressed files. On the first round the average saving was 65% (images created with gnuplot).
I just discovered it today and I'm very satisfied.
svgcleaner is very robust and quite fast.
The svgcleaner repo has a comparison vs scour and svgo. In my experience svgcleaner is safer than svgo and scour; I've had the latter two produce broken SVG files.
See https://lists.w3.org/Archives/Public/www-svg/2007Apr/0025.html