Type in commands that do the following.
Part 1
Send the output to a textfile using the "script" command.
Attach the "script" file with your output. Don't worry about any mistakes while you are typing - you don't need to do it over and you don't need to clean up your script file.
1) create a directory
2) change the directory permissions to rwxr-wr-w (if your system won't allow you to, don't worry about it)
3) go into the directory
4) touch a file
5) create a file called testfile and enter in a bunch of text, save and exit the file
6) grep a directory for some text - it doesn't matter what text it is
7) find the /etc/passwd file
8) create another directory, add files in the directory, and remove the directory
9) go to another directory somewhere and type in the command that displays your current directory
10) type in the command to display all of your filesystems
Part 2
Use the bash shell for the following:
#1 Create a file called testfile.
#2 Make the file executable (what command did you use)?
#3 Add the following lines to the testfile
echo Hello $LOGNAME!
echo The hour that this script is running is `date +%H`
echo "This system name is `uname -n`"
echo Display the calendar for this month:
cal 11 2009
echo The processes that I am running are:
ps -ef | grep "^$LOGNAME"
echo "This is the end of the shell script!"
What is the output of this script?
Run in debug mode:
sh -x ./testfile
What is this output?
#4 We will now test reading in standard input into a variable that can be used.
ex:
echo -n "What is your name? "
read name
echo Greetings to you, $name.
Write a small program that asks the user for their favorite color and outputs the
color back. What does the program say?
#5 Type in the following to set your terminal type to vt100.
$ export TERM=vt100
$ echo $TERM
What is the output?
#6 Type in the following to add /local/bin to your current search path.
$ export PATH=/local/bin:$PATH
$ echo $PATH
What is the output?
#7 Type in this command to re-execute the .profile script? (.profile for ksh .bash_profile for bash)
$ ./.profile or .bash_profile
$ echo $SHELL
What is the output?
Type in the “set” command and the “ env”, capture the ouput and paste as your answer.
#8
What are the following set to?
HZ
PATH
LOGNAME
SHELL
HOME
TERM
PWD
TZ
#9 What command did you use to find out?
#10
Type in the following command:
echo less than b r divided by greater than less than b r divided by greater than N o w r u n p s minus e f vertical line g r e p w h a t e v e r t h e o u t p u t w a s minus w h a t i s t h e s i g n i f i c a n c e o f less than b r divided by greater than t h e e c h o command?
Part 3
Regular Expressions
Write a regular expression that reads the following:
a.summer
2. Write a regular expression that reads the following:
home/asummer/files
3. Find the word MaryBeth if it is at the beginning of a line: What is the expression?
Find the word MaryBeth if it at the end of a line: What is the expression?
5. Match the vowels (both upper case and lower case): What is the expression?
Match all numeric characters: What is the expression?
7. Match all characters that are not alphabetic: What is the expression?
Match zero or more consecutive C's: What is the expression?
Match one or more consecutive E's: What is the expression?
Redirect output
Create a file called output.file from the output of the calendar command: What is the command?
Add the output of the date command to the file that you created from question #10: What is the command?
email this file to
Sandra@neu.edu - what is the command?
translate all upper-case characters in output.file to lower-case and write the results to standard output: What is the command?
What does the following command do?
who | tee outfile.file | grep yourusername
replace yourusername with your username then
cat outfile.file
and copy the output to your homework
*********************************************************************
Assume the following files exist in the current directory:
ls -a
.
..
.dalog
.molog
a
ab
abc
dabkup1
dabkup2
dabkup3
dabkup4
dabkup5
mobkup1
mobkup2
Under this directory is a subdirectory called bin that has the following files:
smail.Z
calc.Z
testsh.Z
Under the subdirectory bin is a subdirectory called foodir that has the following file:
foo.Z
What is the output for the following commands:
ls d*
ls *1 (as in the number 1)
ls *ab
Without changing to the bin subdirectory, what is the output of the following command?
ls */* .Z
What is the output of the following command?
ls */*/*.Z
What is the output of the following command?
echo .*
What is the output of the following command?
echo ??
What is the output of the following command?
echo ???*
What is that command doing?
What is the output of the following command?
ls [am]*
What is the output of the following command?
echo [dm]*[1-5]
What is this command doing?
What is the output of the following command?
ls [!d]
What is the “!” doing?
What does the following command do?
rm *.[!em]
27. What does the following command do?
find / -name file -print 2> errors.txt
1) Given the following assignments:
$ x=*
$ y=?
$ now=`date`
$ greater='>'
$ echo $SHELL
/bin/bash
$ export x=*
$ export y=?
$ export now=`date`
$ export greater='>'
and these files in your current directory:
$ mkdir one
$ mkdir two
$ mkdir a
$ mkdir bb
$ mkdir giraffe
What will the output be for the following commands?
echo *
echo **** error *****
echo $x
echo $y
echo "$y"
echo '$y'
echo _$now_
echo hello $now out
echo "\""
echo 'Is 6 * 4 > 20 ?'
echo 6*4
echo 6 * 4
echo What is your name?
echo \*\*\*
echo \$now
echo $\$now
echo "\\"
echo '\\'
echo \\
echo "What's the word?"
When you create a script, make certain that you set the permissions to executable. rwx or r-x
2)
Write a short program that prompts for your favorite color. Using the case statement give 4 acceptable answers, display different responses depending on the answer that is given. Also, give an option to exit from the script.
Include a printout of the script.
3)
Write a short program that
a: prompts for a filename to search for
b: searches the current directory for the filename
c: if it finds the filename the output reports that it found the filename with
the complete path and filename
d: if it does not find the filename the output reports that to the display