-1

I'm on Ubuntu 18.04. If I go into my home directory and right-click and select "new document" and then "empty document", a new file appears called "Untitled Document". Now I want to edit what's in this file, and so in the terminal I type:

gedit ~/Untitled Document

And what happens is that gedit opens two temporary documents, both non-existent yet, one called "Untitled", and the other called "Document". How am I supposed edit the file called "Untitled Document"? Also, to edit the contents of a document like this I must use the terminal? I didn't see any option for editing when I right-clicked.

marked as duplicate by pa4080, WinEunuuchs2Unix, Kulfy, pLumo, mook765 Jul 15 at 15:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Use tab for auto complete and the \ is added automatically – Rinzwind Jul 15 at 14:43
  • Change ~/Templates/New Document to ~/Templates/NewDoc or anything with no space. I just used new_doc. – oldfred Jul 15 at 14:54
2

You're supposed to type :

gedit ~/Untitled\ Document

Why? "space" is a character in linux, it's "interpreted" rather than "read".

In a succession of arguments in a terminal command, a space will be interpreted as or will mean: "now I will pass the next argument".

With this in mind, your gedit did exactly what you told it to do, first edit a document called "Untitled", if it doesn't exist, create it, as soon as you save and exit out of that one move on to editing a document called "Document", if it doesn't exist create it.

So, if you want a space to be read rather then interpreted, you need to "escape" it. Basically the main use of \ (backslash) under linux.

This is what the backslash character interprets as: "whatever follows me, ignore it, just read it as a string (text) not as an interpretable character".

If you click and drag the file to your terminal after typing gedit you'll find that it fills it with the \ (backslash).

This applies for long file paths as well, if one of the folders has a space in it, it must be escaped.

An easy workaround for this is to use double quotes arround the path or filename in order to have the entire thing be read as a string (text), like this :

gedit ~/"Untitled Document"

One last trick to get it right is to use the terminal's autocomplete feature : Tab

If you have entered a case sensitive part of the name or path that is at least 2 characters long, tab will autotocomplete with the only possible match.

Say you have no other files starting with Un

gedit ~/Un

Tab

will fill out your missing file incuding the \.

You can also use double Tab as a quick list of the remaining options if there are more than one.

If there is only one option Tab will autocomplete selecting it without you needing to prefill ancharacters at all.

By the way, if you open a terminal, at the moment it opens you are aleady in "home" AKA : ~/

typing that extra bit works but is unecessary: gedit Untitled\ Document

works fine. If you cd to another directory (for example cd Downloads) it would maybe make sense, but you could always just type cd alone and it would bring you right back to home and you could type your paths without ~/ again, which is less keystrokes and faster.

  • 1
    Or use double quotes – Rinzwind Jul 15 at 14:42
  • 2
    The tilde symbol ~ will not be expanded within any kind of quotes. You need to exclude it from the quotation, or you can use the envvar $HOME. – pa4080 Jul 15 at 15:00
  • 1
    @pa4080 I said that at first and had a part explaining why but then I tested it and nano opened the right file. Can you explain why? – tatsu Jul 15 at 15:04
  • wow, nano parses ~ by itself ?? strange thing. – pLumo Jul 15 at 15:09
  • Hi, tatsu, I can't explain what exactly have had happen in your particular case, but in the common case, within the quotes the tilde must be treat as other special symbols like spaces, etc. Which is the version of your Ubuntu? – pa4080 Jul 15 at 15:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.