Main Content

Linux - useful tips including history and file name completion

Archive - Originally posted on "The Horse's Mouth" - 2010-02-15 21:05:28 - Graham Ellis

Linux is feature rich - it's so feature rich that it's daunting to know where to start when teaching about it - what features to include and what to leave out.

It's twenty to nine at night, and I'm still hear in "The Wilts" training room, just getting down to "the Mouth" which I would have expected to be writing first thing in the morning. I just don't know where the time has gone (no - actually, I do; several inquiries about courses to be answered at highest priority, a group of customers at the hotel who are on their first visit to England and need a little more TLC than average, and an admin / linux course which is much more teaching and much less practicals that the language courses. And then a thread on the First Great Western Coffee Shop which has required sensitive handling.)

So - coming up to 9 p.m. - so quick hints on Linux and the Bourne Again Shell, copied off the board:

1. If you type
  history
you'll see a list of the recent command you've run. You can then make use of those commands (and parts of them) using sequences such as
  !1052 - rerun command no. 1052
  !c - rerun the latest command starting with the letter c
  !! - rerun the last command
  !$ - reuse the last parameter from the previous command
  !* - reuse all parameters from the previous command

2. If you have a long line that's been typed in or recalled and you want to cleat it out, [ctrl-U], Control and U, will do it for you

3. If you've typed in part of a file name, you can hit the [tab] key to use autocomplete. The rest of the file name will spring in, or if there are several possibilities, as much as possible will come in and then the bell will ring. Type one more character and [tab] again to carry on, or hit [tab] a second time for a listing of all possibilities.

4. If you don't want your output to go to the screen, you can redirect:
  > - send the output to a file, replacing any existing content
  >> - send the output to a file, adding to any existing content
  2> - send the error output to a file
  | - send the output to a following command