Objectives
1) Upon completion of this unit, you should be able to:
- Use command-line shortcuts
- Use command-line expansion
- Use history and editing tricks
- Use the gnome-terminal
Command Line Shortcuts file Globbing
1) Globbing is wildcard expansion
- * matches zero or more characters
- ? matches any single character
- [0-9] matches a rang of numbers
- [abc] matches any of the character in the list
- [^abc] matches all except the character in the list
- Perdefined character classes can be used
Command Line Shortcuts The Tab Key
1) Type tab to complete comand lines:
- For the command names, it will complete a command name
- For an argument, it will complete a file name
Command Line Shortcuts History
1) bash stores a history of commands you’ve entered, which can be used to repeate commands
2) use history command to see list of “remembered” commands
- !!: repeats last command
- !char: repeats last command that started with char
- !num: repeats a command by its number in history output
More History Tricks
1) Use the up and down keys to scroll through previous commands
2) Type Ctrl-r to search for a command in command history
3) To recall last argument from previous comand:
- Esc,. (the escape key followed by a period)
- Alt-. (hold down the alt key while press the period)
Command Line Expansion the tilde
1) Tilde (~)
2) May refer to your home directory
$ cat ~/.bash_profile
3) May refer to another user’s home directory
$ ls ~julie/public_html
Command Line Expansion Commands and Braces Sets
1) Command Expansion: $() or ``
- Print output of e command as an argument to another
   $ echo “This systems’s name is $(hostname)”
   This system’s name is server1.exmaple.com
2) Brace Expansion: {}
- Shorthand for printing repetitive strings
   $ echo file{1,3,5}
   file1 file3 file5
   $ rm –f file{1,3,5}
Command Editing Tricks
1) Ctrl-a moves to beginning of line
2) Ctrl-e moves to end of line
3) Ctrl-u deletes to beginning of line
4) Ctrl-k deletes to end of line
5) Ctrl-arrow moves left or right by word
Gnome-terminal
1) Application –> Accessories –> Terminal
2) Graphical terminal emulator that supports multiple “tabbed” shell
- Ctrl-shift-t creates a new tab
- Ctrl-PgUp/PgDn switches to next/prev tab
- Ctrl-Shift-c copies selected text
- Ctrl-Shift-v pastes text to the prompt
Scripting Basics
1) Shell scripts are text files that contain a series of commands or statements to be executed.
2) Shell scripts are useful for:
- Automating commonly used commands
- Performing system administration and troubleshooting
- Creating simple applications
- Manipulation of text of files
Creating Shell Scripts
1) Step 1: Use such as vi to create a text file containing commands
- First line contains the magic shebang sequence: #!
   #!/bin/bash
- Comment your scripts!
   Comments start with a #
2) Step 2: Make the script executable:
   $ chmod u+x myscript.sh
3) To execute the new script:
- Place the script file in a directory in the executable path –OR-
- Specify the absolute or relative path to the script the command line
Sample Shell Script
#!/bin/bash
# This script displays some information about your environment
echo “Greetings. The date and tiem are $(date)”
echo “Your working directory is: $(pwd)”
End of Unit6
1) Quetions and Answers
2) Summary
- Command expansion: $()
- History recall: !string, !num
- Inhibition: ‘’, \