Q1 60-80 Flashcards

1
Q

When will ‘wc < chap0[1-5]’ work?

A

When there is a file called “chap0[1-5]” in the same directory.

wc (Word Count) will display the lines, words and characters of a file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Is ‘>foo < bar sort’ a legitimate Unix command, and what does it appear to do?

A

No it is not. >foo is an Invalid Null Command.

But it appears to write Null to ‘foo’, then send the contents of ‘bar’ to ‘foo’ and sorting it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens when you execute (i) cat > foo if foo contains data, (ii) who&raquo_space; foo if foo doesn’t exist?

A

Executing cat > foo will overwrite foo, and who&raquo_space; foo will create foo if it does not exist.

If foo does exist&raquo_space; will append the data to the end of foo.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When executing the following two Unix commands: sort filename and sort

A

The different errors come from who is opening the file. sort or the shell (in the case of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do the commands wc foo and wc < foo differ?

A

In ‘wc foo’ foo is opened by wc.

In ‘wc < foo’ foo is opened by the shell and redirected to wc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

You want to concatenate two files, foo1 and foo2, but also insert some text after foo1 (but before foo2) from the terminal. How will you do this?

A

UNKNOWN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you redirect each of the standard output and standard error to two different files in the Bourne-shell and C- shell? Give an example.

A

Bourne-shell: cat foo bar 2> error_file

C-shell: (cat foo bar > output_file) >& error_file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you redirect each of the standard output and standard error to the same file in the Bourne-shell and C-shell? Give an example.

A

Bourne-shell: cat foo bar > output_and_error_file 2>&1

C-shell: cat foo bar >& output_and_error_file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you redirect the standard input from a file in the Bourne-shell and C-shell? Give an example.

A

The redirect input symbol, <, instructs the shell to redirect a command’s input from the specified file instead of from the keyboard.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What will you get if you execute ls 1> out.file in Bourne-shell and in C-shell? Explain.

A

Bourne-shell: You will overwrite out.file with the output of ‘ls’. (as bourne-shell treats 1> as >)

tcsh: 1 not found, create empty out.file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Display lines 30 through 40 of the file poem on your screen. Assume that the file poem has more than 40 lines.

A

head -30 poem

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Print the 5th line in a file called input_file.

A

head -5 input_file | tail -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you select from a file: (i) lines 5 to 10, (ii) second-to-last line?

A

NOT SURE

tail -2 letter.txt | head -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does head display its output when used with multiple filenames?

A

In order of the provided file names, using ==> foo <== as titles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the file /dev/null used for?

A

A virtual file that is always empty and used to dispose of unwanted data. Basically a black hole.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you find out the number of (i) users logged in (ii) directories in your home directory tree?

A

who | wc -l

ls -d -l */ | wc -l

17
Q

Consider the Unix command ls -lrt | tee > newfile; Why does this command not produce any output on the screen? Give the command that uses tee correctly (save the output to newfile).

A

It doesn’t produce any output because you don’t use the redirect > with tee. To have it write both to stdout and a new file you need to do.

ls -lrt | tee newfile

18
Q

In a Bourne-shell, what do the following commands mean? Are they equivalent? Explain.
cat 1> letter 2> save < memo
letter 2> save cat

A

The first command opens (or creates) the file letter then outputs the error message with save and inputs ‘memo’ before the error message.

The second command differs slightly by printing out the error, and saving ‘cat’ instead of ‘memo’ within the file save.

19
Q

Print the names of all files in the current working directory to the screen in upper case (i.e., translate all lower case characters to upper case). Hidden files should be included.

A

ls -a | tr a-z A-Z

20
Q

How do you convert a content of a file to uppercase letters?

A

tr a-z A-Z < filename > newfilename

21
Q

How do you convert a content of a file to lowercase letters?

A

tr A-Z a-z < filename > newfilename