Short appendix to Ubuntu command-line tutorial

The Ubuntu command-line tutorial

It's a great tutorial, but here I'm going to add a few things I don't think it covered.

Files that start with -

Something a lot of Linux beginners struggle with is figuring out how to work with a file whose name starts with a dash. The Ubuntu tutorial explained why you shouldn't name files like this, but if for some reason you have one, you might find it's hard to rename or remove it because commands usually interpret anything that starts with a dash as a flag rather than a filename.

One solution is to use a path. For example, write `./-file` instead of `-file`.

Another solution is the special flag `--`, which means "don't interpret anything after this as a flag". `mv -- -file file`

Tab autocompletion

This is a ridiculously useful feature, so pay attention!

If you press tab while typing a command, the shell will try to automatically complete the word you're typing. If you need to type a long filename, usually you can just type the first few letters of it and then press tab; the shell will type out the rest for you as long as there's only one file that starts with the characters you've typed.

Tab autocompletion also works for command names if you're on the first word on your command line (since the first word is always the command name), but that's not as important since most commands have short names anyway.

Most shells also have a feature where if you press tab and it can't guess what file you want because there's more than one possibility, pressing tab again will show you all the possibilities.

Line editing

Shells provide special key sequences that help you edit the command-line you're typing more easily. For example, Ctrl-C in most shells clears the current line so you don't have to backspace it all. Ctrl-A usually takes your cursor to the beginning of the line (and Ctrl-E takes you to the end). (The Home and End keys also do that, but they're too far out of the way on most keyboards so I find them less convenient.) Ctrl+left/right arrows are usually interpreted as "move by word"; pressing Ctrl-left will move your cursor one word to the left.

Most shells support quite a few line-editing functions and they're extremely useful, but they vary between shells and can be configured, so I'll not talk about them too much.

Other control sequences

There are some Ctrl+<letter> sequences that are very useful besides line-editing.


The tutorial introduced stdin and stdout in chapter 6, but didn't mention there's a third stream that processes havae: stderr. stderr is like stdout, but meant for error or diagnostic messages rather than normal output. It looks the same because stderr by default shows up on the terminal just like stdout, but it behaves differently with redirection; for example when you use | to redirect a command's output, that only redirects stdout. stderr is still going to your terminal. For example, try running `cat` on a file that doesn't exist and piping the output into `wc`. You'll notice that the error message about the file not existing doesn't get piped into `wc` (and `wc` prints zeroes because it got no actual input). There are ways to redirect stderr too, if you're interested.


subscribe via RSS

Proxied content from gemini://yujiri.xyz/software/ubuntu-tutorial-appendix.gmi

Gemini request details:

Original URL
Status code
text/gemini; lang=en
Proxied by

Be advised that no attempt was made to verify the remote SSL certificate.

What is Gemini?