Log in to users
- Run the ssh client
Use the values in the table below to connect to users.
ssh configuration parameter value protocol ssh ssh version 2 ssh port 22 host users.cs.umb.edu user name your Ynix 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
(If you did not complete Exercise #06 during the previous class, please consult with me before continuing!)
- 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 ex07 directory
mkdir ex07- Go to your ex07 directory
cd ex07Experiment with Special Characters
- Try using & in a directory name
mkdir abc&def
You should get an error message- Look at the results
lsmkdir created an abc directory and then tried to execute the non-existent command def- Remove the abc directory
rmdir abc- Check that the abc directory is gone
ls- Use the backslash, \ , to continue a command onto the next line
echo foo \[Enter] bar [Enter]There should be no space between the \ and the newline created by the Enter key.
The shell did not process what you entered on the first line after you pressed the Enter key for the first time, it just gave you a new line.
The backslash, \ , turned off the special meaning of the newline character.Create a typescript File
- Make sure you are in your ex07 directory
pwdIf the result of running this command is not~YOUR_UNIX_USERNAME/it244/ex/ex07where 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 ex07 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 directed to do so...Working with ls
- Move to your home directory
cd- Make sure you are in your home directory
pwd- Run ls without options or arguments
lsYou see only the visible files in your home directory- Look at the contents of your it244 directory
ls it244- Look at all the files in your home directory
ls -a- Get a long listing of all the files in your home directory
ls -alNotice that you can use more than one option at a time.cat
- Run cat on your .bash_history file
cat .bash_history- Now run cat showing line numbers
cat -n .bash_historymkdir
- Go to your ex07 directory
cd it244/ex/ex07 pwd- Create a test directory
mkdir test- Make sure the directory was created
ls- Create a test2 directory
mkdir test2- Look at the contents of your current directory
lsYou should see the a new test2 directoryExperiment with rm
- Move to your test2 directory
cd test2- Create some files in this directory
touch foo bar bletch gobbletouch will create a file if it doesn't already exist.
That is not its primary purpose, but we'll only be using it in this way for this class.- Perform a long listing of the contents of the test2 directory
ls -lThe first entry after -rw-r--r-- for each file is a 1. This means the files are one byte long, essentially empty.
touch creates empty files.- Remove the file foo
rm foo- Look at the directory contents
ls- Remove bar and bletch
rm bar bletch- List the contents of your current directory
lsAll the three files you removed should be gone.- Remove a file using the -i option
rm -i gobbleEnter y when prompted- Create some more empty files
touch baloney ham cheese turkey- Look at the directory contents
lsYou should see the files you just created.- Remove all files from your current directory
rm *- Look at the directory contents
lsThe directory should be emptyrmdir
- Make sure you are in your test2 directory
pwdIf not, go there.- Create some files
touch red blue green orange- Move back up to the ex07 directory
cd ..- Examine the contents of the test2 directory
ls test2- Try to remove the test2 directory using rmdir
rmdir test2You should get an error message because the directory is not empty- Look at the contents of your ex07 directory
lsThe test2 directory is still there.- Remove the files in test2
rm test2/*- Remove the test2 directory
rmdir test2- Examine the contents of your ex07 directory
lsThe test2 directory should be goneRun cp to Copy Files and Directories
- Create a file
touch foo- Copy a file
cp foo footoyou- Look at the contents of the directory
ls- Go to the test directory
cd test- Create some files in this directory
touch foo bar bletch- Go back to the ex07 directory
cd ..- Copy a directory
cp -r test test3- Look at the contents of the ex07 directory
lsYou should see a new test3 directory- Look at the contents of test3
ls test3It should be the same as testmv
- Go into the test3 directory
cd test3- Change the name of footoyou
mv foo foo_to_you- Examine the changes
ls- Move a file to another directory
mv foo_to_you ../test- Look at the contents of the current directory
lsfoo_to_you is no longer in your current directory- Look at the contents of your test directory
ls ../testfoo_to_you has been moved to the test directoryEnd your script Session
- Exit from your script session
If you hadn't used the "flush" option, you would need to do this or the typescript file would never be created
exit- Look at the contents of the typescript file
cat typescriptWorking 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.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.
Reopen typescript File
- Make sure you are in your ex07 directory
pwdIf the result of running this command is not~YOUR_UNIX_USERNAME/it244/ex/ex07where YOUR_UNIX_USERNAME is the name you created for your Unix account, see me.- Run the script command
script --flush --append
This will reopen the typescript file in your ex07 directory, with appending.
Do not exit the script session until instructed to do so.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
If you hadn't used the "flush" option, you would need to do this or the typescript file would never be created
exit- 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 ex07 directory
cd ex07- Create the script file ex07.sh
nano ex07.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 ex07.sh
Do not use Tab completion inside ex07.sh
You do not have to use echo in scripts for the Class Exercise.
- Save and quit
- Run this script
bash ex07.sh