Log in to pe15
- Run the ssh client
Use the values in the table below to connect to .
ssh configuration parameter value protocol ssh ssh version 2 ssh port 22 host pe15.cs.umb.edu user name your Unix username Authentication method password
- Enter your password
A dialog box will appear on the screen into which you must type the password for your Unix account.
Directory for this Exercise
- Make sure you are in your home directory
cd- Go to your it244 directory
cd it244- Go to your ex directory
cd ex- Create an ex05 directory
mkdir ex05- Go to your ex05 directory
cd ex05Working with Pagers
- Use cat on the exercise #05 page
cat /home/ckelly/public_html/teaching/common/exercises/linux/intro/exercise_05.htmlScroll back up in your terminal session to see the beginning of the file.
- Use more on the same file
more /home/ckelly/public_html/teaching/common/exercises/linux/intro/exercise_05.html- Move down one screen
Space- Look at the more help section
h- Use the Enter key to moves down a few lines
Enter Enter Enter- Move to the end of the file
Hit Space as many times as you need to.
You should reach the end of the file and exit more.
- Use less on the same file
less /home/ckelly/public_html/teaching/common/exercises/linux/intro/exercise_05.html- Move to the end of the file
Hit Space until you reach the end of the file.
You see (END) but you are still in less.
- Examine the help section
h- Quit the help section
qHitting q the first time only gets you out of the help section.
- Quit less
qHitting q the second time only gets you out of less.Create a typescript File
- Make sure you are in your ex05 directory
pwdIf the result of running this command is not~YOUR_UNIX_USERNAME/it244/ex/ex05where YOUR_UNIX_USERNAME is the name you created for your Unix account, see me.- Run the script command
script --flushThis will create a typescript file in your ex05 directory.
You must perform the remaining steps in this exercise while script is still running.
If you make a mistake, simply try again.
Do not exit the script session until you have finished all the steps in this exercise.Filename Completion
- Create the directory test
mkdir test- Move to the test directory
cd test- Create some files
touch foo foobar foobletch bletch- Use filename complete to run ls on bletch
ls ble[Tab][Enter]- Use filename completion to see all files with "foo" in the name
ls foo[Tab][Tab]After the first Tab, you should hear a beep. After the second, all files beginning with "foo" should be displayed.
- Keep typing to run ls on foobletch
bl[Tab][Enter]As you supply more letters in the filename, the completion mechanism narrows down the possibilities.
Experimenting with echo
- Run echo with a string argument
echo foo bar bletch- Run echo using the -n option
echo -n foo bar bletchNotice that "foo bar bletch" appears before the normal prompt.
That is because the -n option turned off sending a newline character to advance to the next line.
- Use echo to display a system variable
echo SHELL: $SHELL- You must use a $ when displaying the value of a variable
echo SHELL: SHELLhostname
- Determine the name of your current host
hostname- Determine the IP address of your current host
hostname -igrep
- Go to the it244_files directory
cd /home/ckelly/course_files/it244_files- Look at the contents of foo.txt
cat foo.txt- Look for lines with the string "foo" in foo.txt
grep foo foo.txt- Experiment with the -i option
First look for "bar" without the -i optiongrep bar foo.txtNow try the same search with -igrep -i bar foo.txt- Use grep with the -r option
grep, when used with the -r option, looks in all subdirectories of the directory given to it as its second argumentgrep -r foo .
The . means the current directory.
Everything up to the colon, : , is the path to the file in which the string was found.
The text after the colon is the line itself.
The entries in the directory .svn are associated with the versioning software, subversion, I use in all my work.
- Use grep -v to remove unwanted lines
Many of the lines returned in the previous invocation of grep come from files with the string "svn" in their file names.
These are files created by subversion.
Let's remove these lines grep twice, using a pipe, |, to feed the output of the first invocation of grep into the input of the secondgrep -r foo . | grep -v svn
Notice that all the entries in the subversion files have been removed.
We'll discuss pipes in a future class.head
- Display the contents of red_sox.txt
cat red_sox.txt- Display the first 10 lines of red_sox.txt
head red_sox.txt- Display the first line of red_sox.txt
head -1 red_sox.txttail
- Display the last 10 lines of red_sox.txt
tail red_sox.txt- Display the last two lines of red_sox.txt
tail -2 red_sox.txtsort
- Look at fruit.txt
cat fruit.txt- Run sort on this file
sort fruit.txt- Sort this file in reverse alphabetical order
sort -r fruit.txt- Look at numbers1.txt
cat numbers1.txt- Run sort on this file without any options
sort numbers1.txtSince the numbers from 10 to 19 begin with a 1 they appear before 2
- Sort numbers1.txt in numerical order
sort -n numbers1.txt- Sort numbers1.txt in reverse numerical order
sort -nr numbers1.txtNote that sort allows you to combine options after the dash.diff
- Examine the contents of numbers1.txt and numbers2.txt
cat numbers1.txt cat numbers2.txt- Use diff to compare numbers1.txt and numbers2.txt
diff numbers1.txt numbers2.txtThe output is hard to read, because it contains instructions for the Unix patch utility to convert the first file given at the command line to the second.
- Use the -y option to diff to create readable output
diff -y numbers1.txt numbers2.txtThis output is much easier to read.End your script Session
- Exit from your script session
exitYou need to do this or the typescript file will never be created- Look at the contents of the typescript file
cat typescriptCreate a Bash script
- Go to your home directory
cd- Go to your it244 directory
cd it244- Go to your ex directory
cd ex- Go to your ex05 directory
cd ex05- Create the script file ex05.sh
nano ex05.sh- Write into this file commands from certain of the sections above
Go back to the section of this Class Exercise called Experimenting with echo.
Enter all the commands from the echo section to the section called diff into this script file.
Do not run the more or less commands inside ex05.sh
Do not use Tab completion inside ex05.sh
You do not have to use echo in scripts for the Class Exercise.
- Save and quit
- Run this script
bash ex05.shWhen finished:
- Remember to check with instructor to make sure you are recorded as having completed the class exercise.
- When you are ready, be prepared to show me:
- Your command line interaction -- in other words, scrolling up in the terminal windows, not just running the history command!
- Any other deliverables specified in the instructions, such as scripts or other files.