Libre offce open latest file date from command line [duplicate]

Solution 1:

If you use zsh in your terminal, you can use its glob qualifiers to select the youngest .odt file (by modification time):

soffice path/to/dir/*.odt(om[1])

To use the zsh features from another shell, you could do

zsh -c 'soffice path/to/dir/*.odt(om[1])'

Solution 2:

As long as the file name does not contain returns or other very strange characters, you can use ls -ct to sort files most recently modified on top. You want to see only Libreoffice documents. You can use grep to filter these. The first, which you can obtain with head -n 1, will be the one you will want to open. You will open a file with the associated application using xdg-open. If the shell variable mypath contains the path to where your files reside, then following command will open the most recently modified .odt document.

xdg-open "$mypath"/"$((cd "$mypath"; ls -ct) | grep -i '.odt$' | head -n 1)"