💾 Archived View for yujiri.xyz › software › guide › ubuntu-tutorial-appendix.gmi captured on 2023-04-26 at 13:35:38. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

➡️ Next capture (2023-09-08)

-=-=-=-=-=-=-

yujiri.xyz

Software

Learn programming for good instead of profit

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.

stderr

The tutorial introduced stdin and stdout in chapter 6, but didn't mention there's a third stream that processes have: stderr. stderr is like stdout, but meant for error or diagnostic messages rather than normal output. In fact, by default stderr is the same as stdout (it shows up on the terminal), but it behaves differently with redirection; for example when you use | to redirect a command's output, that only redirects stdout. stderr still goes to your terminal. For example, try running `cat` on a file that doesn't exist and piping the output into `wc` (`cat nonexistent | 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, but I won't get into them here.

contact

subscribe via RSS