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`
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.
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 a lot of Ctrl+<letter> sequences that are very useful besides line-editing.
- Ctrl-D: signal that you're done sending input (you can imagine it stands for 'done'). If you use this with an empty command-line it'll exit the shell. Most programs that take text input when you run them use this as their signal to stop.
- Ctrl-C while a command is running: ask the command the stop (you can imagine it stands for 'cancel'). Most commands stop immediately when you Ctrl-C them, but they can be programmed not to. If you need to *force* a program to stop, there are other ways of doing that.
- Ctrl-Z while a command is running: pause the command (I think it's obvious what this one stands for). You'll get back to the shell prompt. Like Ctrl-C, a command can be programmed to not respect this.
- Ctrl-\ while a command is running: ask the command to die. This is similar to Ctrl-C but a lot of programs treat it differently. This also requests the program to make a *core dump*, but that's something I won't get into.
I guess if you want you can imagine that \ as a sword that kills the command.
- Ctrl-T: this actually only exists on BSD systems and not Linux, but it asks the command to print some information about what it's doing. A lot of commands just print a basic status line showing some cryptic information I won't get into here, but some commands print more useful and application-specific stuff.
This one stands for "tell". And yes I just made that up.
subscribe via RSS