When a family member started using Libreoffice Writer on Ubuntu they used a particular document over and over as a starting point for new documents. Subsequently these documents were themselves used as starting points over and over for even more documents. Unfortunately the family member wasn't aware of the "Title" field for these documents.

End result, now they have hundreds of documents with bogus content in the "Title" field, all the same. Except, after they learned about this, they started fixing the Title field, so not every document has this problem. Only most of them.

Is there a command line / batch / terminal way to

  1. select the offending documents
  2. blank out the Title field

Doing it document by document is impractical because there are so many.

Searching ask.libreoffice.org didn't yield an answer.


1 Answer 1


This script (this version) seems to do it.

#   Last updated: "Sun Jul 29 23:43:59 2018"
# Replace "Unwanted content" with "Desired Stuff" in the document's "Title" (File->Properties->Title)
# **WARNING** Leaves original unmodified "<file>" in "<file>~". Overwrites previous "<file>~"
# modified to remember the contents of the zip archive, and zip
# every one back together
if [[ "$1" = "-d" ]] ; then
    set -x
while [[ "$1" ]] ; do
    contents=$(unzip -l "$file" | tail -n +4 | awk '{print $4}' | tr "\n" " ")
    dirs=$(unzip -l "$file" | tail -n +4 | awk '{print $4}' | grep / | cut -d/ -f1 | uniq)
    unzip -qq "$file"
    sed -e 's/dc:title>Unwanted content/dc:title>Desired stuff/' meta.xml >meta.xml.new
    mv -f meta.xml.new meta.xml
    mv -f "$file" "${file}~"
    zip --quiet -o "$file" -r $contents
    rm -r $contents $dirs
    cmp --quiet "$file" "${file}~"
    if [[ $? -eq 0 ]] ; then
        mv -f "${file}~" "$file"

Make the script, called FixMyTitle executable, and store in in a directory in your $PATH. $HOME/bin is good.

Then, use find (read man find) to pass the names of the files to FixMyTitle:

find $HOME -type f -name '*.odt' -print0 | \
    xargs -0 FixMyTitle

Later, clean up the obsolete originals by:

find $HOME -type f -iname '*.odt~' -delete
  • This is very close. The final version of the document does not have the embedded graphics in it. Instead there are boxes with red text saying Read Error. I'll have to see how they went about inserting these graphics. Jul 24, 2018 at 22:10
  • I added Pictures to the line starting with zip and that works now. the rm line doesn't completely work because some of the arguments are directories. Jul 24, 2018 at 22:15
  • Fixed the rm line but the grep in the 2nd script does not seem to work. Researching. Jul 24, 2018 at 22:39
  • @OrganicMarble Fixed file list problem (generated it dynamically). The grep -lZ has a lower-case ell (the letter, l), not the digit 1.
    – waltinator
    Jul 25, 2018 at 22:37
  • @OrganicMarble could you give a pointer to your question on ask.libreoffice.org? My script might help others there.
    – waltinator
    Jul 28, 2018 at 14:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .