# Open new file from command line?

It is very common on Linux to do

command filename

from the command line, and programs will try to open the file called filename or, if it does not exist, create it. However, when I do

I get an error saying that the file does no exist. Additionally, if just open libreoffice from the command line without specifying a filename and then open the save-file dialog, the default location is not the directory from where I issued the command, but my home. I find these behaviour inconvenient for my workflow... Is there any way to create a new empty file from command line and open it directly?

Thanks!

edit retag close merge delete

Sort by » oldest newest most voted

What I have always found helpful is to create an empty document from command line and then call LibreOffice on it. For example,
touch new_file.odt
libreoffice --writer new_file.odt

or you can use them together and type in
touch new_file.odt && libreoffice --writer new_file.odt

or you can use lowriter if you want as well.
lowriter new_file.odt

more

If I'm in my terminal in Linux and I want to open an odt file I just type lowriter then the file name. For example, if I want to open the file pizza.odt through the terminal I would type: lowriter pizza.odt and the file will open in Libre Writer.

more

I have an alias in the alias file that is sourced when I open a terminal.

alias writer='/usr/bin/libreoffice --writer --norestore &>writer.log'


So

writer mydoc.odt &


will open the file in writer.

In Ubuntu and Solaris the alias file is ~/.bash_aliases by default. Other distros may be different. In Debian I had to modify the ~/. profile file.

The --norestore bypasses the document recovery process which for me always otherwise runs and has never been necessary. If it turns out that a document does need recovery then you can run writer without this switch.

The redirect of output '> ' spares me from warnings and errors that are rarely important but will be put to the writer.log file if something goes awry.

more

There appears to be no option available, which is something of an oversight.
However, create a blank document of the type that you wish to use and save it i.e. mybase.odt or mybase.ods
Then on the command line
cp mybase.odt mynewfilename.odt
or
cp mybase.ods mynewfilename.ods

and then
libreoffice mynewfilename.odt
or
localc mynewfilename.ods

more