Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

. Explain this sequence of commands: $ mkdir empty $ cd empty $ cp a b cp: canno

ID: 3891716 • Letter: #

Question

. Explain this sequence of commands:

$ mkdir empty

$ cd empty

$ cp a b

cp: cannot stat 'a': No such file or directory

$ cp a b >a $ # why is there no error message from cp this time? what is in file a ?

Explain this sequence of commands:

$ date >a
$ cat a
Wed Feb 8 03:01:21 EST 2012

$ cp a b
$ cat b
Wed Feb 8 03:01:21 EST 2012

$ cp a b >a
$ cat b
$                                 # why is file b empty? what is in file a ?

How many words are in each of these five output files?

$ echo one two three >out1
$ echo one two >out2 three
$ echo one >out3 two three
$ echo >out4 one two three
$ >out5 echo one two three

What is in each file a, b, c, after this command line?

$ echo hi >a >b >c

$ mkdir empty

$ cd empty

$ cp a b

cp: cannot stat 'a': No such file or directory

$ cp a b >a $ # why is there no error message from cp this time? what is in file a ?

Explanation / Answer

Question 1 : Explain this sequence of commands:

$ mkdir empty

- we made a directory with the name empty

$ cd empty

- here we have changed out current working directory to empty.

$ cp a b

- here we are copying file 'a' to file 'b' but there is no file in

the directory so executing this command displays following error.

"cp: cannot stat 'a': No such file or directory"

$ cp a b >a $

# why is there no error message from cp this time?

- here the output of execution of command is redirected to file new file named 'a'.

so the error message is not displayed, it is sent to file a.

what is in file a ?

File 'a' contains the error message "cp: cannot stat 'a': No such file or directory"

Question 2 : Explain this sequence of commands:

$ date >a

- here the output of date command is redirected to file a

$ cat a -

it displays the content of file a, which is output of date command.

"Wed Feb 8 03:01:21 EST 2012"

$ cp a b

- File 'a' is copied to file 'b'.

$ cat b

- since file b is copy of file a it contains the same contents of file 'a'

"Wed Feb 8 03:01:21 EST 2012"

$ cp a b >a

$ cat b

$ # why is file b empty? what is in file a ?

- The '>' operator has higher precedence, so file 'a' will be created first,

the shell opens the b file for writing, truncating it,

before the cp starts running.

then it gets copied in b, so b is also empty file like file 'a'

Question 3 : How many words are in each of these five output files?

$ echo one two three >out1

$ echo one two >out2 three

$ echo one >out3 two three

$ echo >out4 one two three

$ >out5 echo one two three

All the output files out1, out2, out3, out4 and out5 contains same numbers of words.

All file contains 3 words "one two three"

Here echo is command operator '>' tells output file and remaining are arguments.

Question 4 : What is in each file a, b, c, after this command line?

$ echo hi >a >b >c

- File a and file b is empty, but the file c contains the "hi" word

Since the command contains the operator '>' which has highest precedence

so it will be executed first, from left to right, so first a will created for

writing, then b for writing then the file c, and the the output is redirected to

latest file, which is c.