Starting from:

$29.99

HW 1 Unix Commands

CS507 Computing Foundation for Computational Science −HW 1
Unix Commands

Instruction to electronic submission: http://cs.boisestate.edu/∼cs221/SubmissionProcedure.html
• The written assignment can be done in a pure text format (*.txt, for example, problem1.txt) on
Onyx.
• The programming assignment should be presented with source codes.
• Each problem should have its own working directory, such as HW2/prob1, HW2/prob2 ... For
example, the following table shows the structure of HW1 from the user “student1” and how to
submit HW to us through Onyx
1 [ student1@onyx :HW1] $ l s −l
2 drwxr−x−−−. 2 s t u d e n t 1 S tuden t s 13 Sep 19 2021 prob1
3 drwxr−xr−x . 3 s t u d e n t 1 S tuden t s 14 Sep 19 2021 prob2
4 [ student1@onyx :HW1] $ cd prob1 /
5 [ minlong@onyx : prob1 ] $ l s
6 −rw−r−−−−−. 1 s t u d e n t 1 S tuden t s 943 Sep 19 2021 problem1 . t x t
7 $ cd . .
8 [ student1@onyx :HW1] $ pwd
9 /home/ s t u d e n t 1 /CS507/HW1
10 [ student1@onyx :HW1] $ submit minlong CS507 HW1
Listing 1: A sample structure of homework and submission procedure.
• Your source codes (if any) must compile and run on Onyx.
• Documentation is important and proper comments are expected in your source code.
– comments giving description of: purpose, parameters, and return value if applicable
– other comments where clarification of source code is needed
– proper and consistent indentation
– proper structure and modularity
Don’t ask us or your classmates directly for solutions (it happened); just try as much as possible.
Be patient and enjoy coding!
1
Written Problems
Hint: If needed, you can type those commands on Onyx as tests to help you figure out the solutions.
P1. (10 pts) Explain the results of the following command sequences.
1 l s | wc −l
2 rm ???
3 who | wc −l
4 mv p r o g s /∗ / u s e r s / s t e v e / backup
5 l s ∗ . c | wc −l
6 who | s o r t
7 cd ; pwd
8 cp memo1 . .
9 d a te +%T
10 pl o t d a t a 2>e r r o r s &
Listing 2: Unix/Linux Commands. Assume “plotdata” is an executable file.
P2. (10 pts) Suppose that your HOME directory is /users/steve, which contains a directory of
“documents”. In this directory, there are “letters”, “proposals” and “memos” directories.
1 [ steve@onyx : documents ] $ l s
2 l e t t e r s memos p r o p o s al s
Listing 3: Example of Steve’s directories.
Assuming that you just logged in to the system and executed the following commands:
1 $ d oc s=/u s e r s / s t e v e / documents
2 $ p r o g s=/u s e r s / s t e v e / programs
3 $ l e t=$d oc s / l e t t e r s
4 $ prop=$d oc s / p r o p o s al s
Listing 4: Setting Steve’s customized environment variables.
Write the commands in terms of these variables to:
(a) List the contents of the documents directory.
(b) Copy all files from the letters directory to the proposals directory.
(c) Move all files from letters directory to the current directory.
(d) Count the number of files in the memos directory.
What would be the effect of the following commands?
1 l s $ l e t / . .
2 c a t $prop / s y s .A >> $ l e t /no . JSK
3 echo $ l e t /∗
4 cp $ l e t /no . JSK $p r o g s
P3. (5 pts) What do you think would happen if you invoked the following command on the shell?
Why?
1 c a t i n f i l e | s o r t | wc −l > i n f i l e
P4. (5 pts) Which of the following are valid variable names? Why?
2
1 XxXxXx
2 HOMEDIR
3 f i l e n a m e
4 x09
5 f i l e 1
6 S l i m i t
P5. (10 pts) “echo” is a very useful Unix/Linux command that outputs the strings that are passed
to it as arguments. Given the following assignments:
1 $ x=∗
2 $ y=?
3 $ z=’ one two t h r e e ’
4 $ now=$ ( d a te )
5 $ symbol=’> ’
and these files in your current directory:
1 $ echo ∗
2 programs documents games homeworks
What will the output be from the following commands?
1 echo ∗∗∗ e r r o r ∗∗∗
2 echo ’ I s 5 ∗ 4 > 18 ? ’
3 echo $x
4 echo What i s your name?
5 echo $y
6 echo ”$y”
7 echo \∗\∗\∗
8 echo $z | wc −l
9 echo \ $$symbol
10 echo h e l l o $symbol out
3

More products