the shell game part 4: bash shortcuts
DESCRIPTION
Continuing our exploration of the Linux Shell by learning some useful shortcuts in the Bash Shell.TRANSCRIPT
![Page 1: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/1.jpg)
The Shell Game, Part 4
Kevin O'BrienWashtenaw Linux Users Group
http://www.lugwash.org
![Page 2: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/2.jpg)
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
![Page 3: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/3.jpg)
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
![Page 4: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/4.jpg)
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
![Page 5: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/5.jpg)
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 seesudo apt-get upupdate upgradekevin@linuxbox:$ sudo apt-get up
![Page 6: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/6.jpg)
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
![Page 7: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/7.jpg)
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
![Page 8: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/8.jpg)
8
Autocomplete 6
● This also works for directories● If you type /uand 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.
![Page 9: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/9.jpg)
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
![Page 10: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/10.jpg)
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/virtualbox/debian/sun_vbox.asc -O- | sudo apt-key add -
● Again, you try to type this in, but it is much easier to paste it in
![Page 11: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/11.jpg)
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
![Page 12: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/12.jpg)
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
![Page 13: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/13.jpg)
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
![Page 14: The Shell Game Part 4: Bash Shortcuts](https://reader038.vdocument.in/reader038/viewer/2022100602/55895627d8b42a6d3e8b464d/html5/thumbnails/14.jpg)
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