The Shell Game Part 4: Bash Shortcuts

1,929 views

Published on

Continuing our exploration of the Linux Shell by learning some useful shortcuts in the Bash Shell.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,929
On SlideShare
0
From Embeds
0
Number of Embeds
193
Actions
Shares
0
Downloads
18
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

The Shell Game Part 4: Bash Shortcuts

  1. 1. The Shell Game, Part 4 Kevin O'Brien Washtenaw Linux Users Group http://www.lugwash.org
  2. 2. BASH Shortcuts ● One way to uncover the power of the shell is by mastering the built-in shortcuts ● These let you whip through commands much faster than any GUI ● They can also do things no GUI was ever designed to do ● Remember the GUI is mostly just a front-end for running the very same commands you can run in the shell 2
  3. 3. Autocompletion 1 ● This is very handy ● It will finish a command for you ● You do this by using the Tab key ● If there is only one possible option available, this will fill it in for you ● If there are multiple options, it will stop at the point where it is not sure ● Hit tab two times, and you get a list of the possible options 3
  4. 4. Autocompletion 2 ● Then you just type in however many letters are needed to remove the uncertainty, and hit Tab again to finish the autocompletion ● Example: On a Debian or Ubuntu installation you can type: – sudo apt-get upd – Hit Tab, and you get sudo apt-get update – Now try sudo apt-get up – Hit tab 4
  5. 5. Autocompletion 3 ● This time, the shell does not know how to finish this ● When you hit tab, you may hear a bell that indicates there are multiple options ● Hit tab again, and you should see sudo apt-get up update upgrade kevin@linuxbox:$ sudo apt-get up 5
  6. 6. Autocompletion 4 ● What is happening here: – You first typed sudo apt-get up , and hit Tab but the shell didn't know which command you wanted, so it stopped – You may have heard a bell – You hit Tab a second time, the shell gave you two possible completions – The shell also re-entered your command so you didn't have to type it in a second time 6
  7. 7. Autocompletion 5 ● All you need to do at this point is type a single letter at the end of this re-entered command: “d” if you wanted “update”, and “g” if you wanted “upgrade” ● Then hit Tab again and it will autocomplete 7
  8. 8. Autocomplete 6 ● This also works for directories ● If you type /u and then hit the tab, it should complete to /usr/ ● You can continue through the directory tree this way. At /usr/ you could then type s and hit tab to get /usr/share/, and so on. 8
  9. 9. Autocomplete 7 ● This is particularly helpful when you are installing software. For example, you may have downloaded a file with a name like VirtualBox-3.0.2_49928_sles10.1- 1.i586.rpm ● You could try to type in the entire name, but you are likely going to make a mistake somewhere ● Autocomplete will fill it in after you type in one or two letters, in all likelihood 9
  10. 10. Copy and Paste 1 ● You can use Copy and Paste while in the shell, or to paste in commands found outside the shell ● For example, if you go to a website, it may tell you to enter a command: wget -q http://download.virtualbox.org/virtualb ox/debian/sun_vbox.asc -O- | sudo apt- key add - ● Again, you try to type this in, but it is much 10 easier to paste it in
  11. 11. Copy and Paste 2 ● Copy within the shell is done by Ctrl+Shift+C ● This is different from copy in most programs, which is Ctrl+C ● Paste within the shell is done by either Ctrl+Shift+V, or Shift+Insert ● This is different from paste in most programs, which is Ctrl+V 11
  12. 12. Copy and Paste 3 ● To copy text from a shell, you would first need to select it ● You can do this with a mouse by clicking and dragging ● Once it is selected, press Ctrl+Shift+C, then go to any other program that accepts text, and paste it in according to that program's instructions 12
  13. 13. Copy and Paste 4 ● For example, to copy a command from a Web page into the terminal window, highlight the command on the Web page, click Ctrl+C to copy it, then go to your terminal window, and press Ctrl+Shift+V to paste it in, and hit enter ● This will run the command ● If you need elevated rights, you could type in sudo, followed by a space, before pasting in the command 13
  14. 14. Conclusion ● Autocomplete and Copy and Paste are great ways to be more efficient in the shell ● You should practice using these techniques ● The best efficiency gain is when you have them in your brain so well that you don't need to think much about them, and that only comes with practice 14

×