CS265 Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which command repeats the last command?

!!

If you want a user to run your bash script without having to specify an interpreter, what should be the first line of your script?

#!/bin/bash

Which of the following AWK programs shows the first and last fields of the following employe file? liam manager account 1000 noah clerk account 2000 oliver manager sales 3000 william manager account 4000

$ awk '{print $1,$NF}' employee.txt

Which awk command outputs all lines where the second field contains onlythe string xyzzy and where the third field exactly matches the first field:

$1 == $3 && "xyzzy" == $2 { print }

Use a single ls command to list all files that either begin with rt or end with rt

(\s*ls \s*rt\* \s*\*rt)|(\s*ls \s*\*rt \s*rt\*)

Which of the following shell's wildcards are used to match any number of characters including none?

*

If i is a variable and p points to i, which of the following expressions are aliases for i?

*&i *p

Assume the following C variable declarations int n; int *p; Choose the statements below that are correct

*p=n; p = (int *) malloc (n);

True if file exists True if file is a directory True if file is a regular file True if the file is writable by you True if file is executable by you

-e file -d file -f file -w file -x file

What will the following commands print?[ 1 = 1 ]; echo $?

0

We define the function fun as void fun(int ptr) { ptr = 20; } If a=10 and we call the function fun(a), what would be the value of a afterwards?

10

Consider the following C declaration struct { short s[5]; union { float y; long z; } u; } t;

18 bytes

How many files are used for representing different standard streams?

3

Predict the output of the following program union test { int x; char arr[8]; int y; }; int main() { printf("%d", sizeof(union test)); return(0); }

8

What is a hidden file or directory?

A filename that begins with a . (dot)

cmd < file - Input of cmd from file cmd1 <(cmd2) - Output of cmd2 as file input to cmd1 cmd > file - Standard output (stdout) of cmd to file cmd > /dev/null - Discard stdout of cmd cmd >> file - Append stdout to file cmd 2> file - Error output (stderr) of cmd to file cmd 1>&2 - stdout to same place as stderr cmd 2>&1 - stderr to same place as stdout cmd &> file - Every output of cmd to file

All Stuff

struct node { int i; float j; }; stuct node *s[10]; The above C declaration defines s to be

An array, each element of which is a pointer to a structure of type node

When you execute the command ls *txt in bash, what program does the file expansion?

Bash

How do we redirect I/O in Unix?

By using > or < or |

In C all variables have a type, but implicit conversions are possible. This is because ...

C supports a typing system that is weakly enforced

A Bash script MUST have execute permissions to be able to run.

False

In a regular expression, .? matches exactly one character

False

In awk, $0 is the first field of the current record

False

In bash, the directory ~user and the directory ~/user are the same directory.

False

Is this is valid C code? True or False? char s1[10], s2[10]; s1="CS265"; s2=s1;

False

The directory that contains a disk utility must be in your $PATH environment variable in order to call the disk utility with its full pathname.

False

The following two sed commands are identical. sed -n '1,10 p' sed -n '10,$ !p'

False

The following two statements are equivalent p=q; *p = *q;

False

The return statement is mandatory in C.

False

There is NO difference between [ ] and [[ ]] in Bash.

False

You can use malloc() to allocate memory in stack memory.

False

You cannot redirect the standard input and the standard output at the same time.

False

a is NOT matched by the regular expression [aa|hh]

False

cat is matched by the regular expression [^hcb]at

False

float is C 's default floating point number data type.

False

sed is an interactive editor

False

Which utility allows you to search for files by name, type, time, etc.?

Find

What does this command do? x=$(ls)

It executes the ls command and puts the output of the command into the shell variable x

Which built-in variable is used by awk to specify the line numbers?

NR

What will the following command print if file exists?[ -e file ]

Nothing - the command will only perform a test

(( )) can be used to evaluate arithmetic expressions.

True

A Unix shell is a program.

True

A shell builtin is faster than executing a disk utility.

True

Bash commands can be combined using a semicolon, e.g., cmd1 ; cmd2

True

By default Awk prints every line of data from the specified file.

True

C is faster than python because C is a compiled language.

True

Executing a disk utility starts a new Unix process.

True

In a regular expression, [xyz] matches exactly one character

True

It is possible to use sed in order to make an in-place update to a file.

True

Sometimes these two commands have identical behavior command > output command >> output

True

The ASCII character set does not contain an EOF character. There is no EOF character.

True

The UNIX file system is hierarchical.

True

The Unix Kernel interfaces with all the hardware resources of the computer.

True

The following code can be used to substitute on a pattern range: changing old to new between a begin/end pattern. #!/bin/bash sed ' /begin/,/end/ s/old/new/ '

True

The following is a valid Bash for loop: for (( i=0; i<3; ++i )) ; do echo $i done

True

The following regular expression in sed matches positive integers? '[1-9][0-9]*'

True

The following two commands are equivalent ls -lF ls -l -F

True

The following two expressions are equivalent. j=*&i; j=i;

True

The following two sed commands are equivalent sed s/day/night old > new sed 's/day/night' old > new

True

The following two sed commands are equivalent: sed 's/day/night/' < old > new sed s/day/night/ old > new

True

The following two sed commands are identical. sed '1,10 !d' sed '11,$ d'

True

The following two statements are equivalent new_node = malloc(sizeof(struct node)); new_node = (struct node *) malloc(sizeof(struct node));

True

The gcc compiler is capable of compiling a number of programming languages.

True

This command test 1 \< 2 is equivalent to this command [ 1 \< 2 ]

True

When using relative path names, the special character ~ indicates the home directory of the current user.

True

You can use the command rm to delete a non-empty directory.

True

awk allows the user to use variables of their own choice

True

hello (at the end of a line) is matched by lo$

True

Which of the following matches any space, tab or newline?

\s

How do you math the word Pepper appearing at the beginning of the line?

^Pepper

What is the output of the following command? echo {a..c}

a b c

When we don't care about the output of a command, we can redirect it to

a special device (/dev/null)

What things does a debugger allow you to do?

a. Set command-line arguments c. Evaluate any expression (involving variables currently in scope) d. Change the value of variables f. Follow along in source code as the program executes g. Let us see where an executable crashed h. Step through your program, one line at a time i. Move the execution pointer around j. Set breakpoints

Suppose we define the following variables in main int a[10]; int *p = (int *) malloc(10); Where are a[0] and *p allocated?

a[0] in stack and *p in heap

Which of the following operators can be applied on structure variables?

assignment (=)

Which of the following will be used to print lines containing 'manager' in emp.lst?

awk '/manager/ { print }' emp.lst

In GDB, breakpoints can be set by the command

both break and b

To exit this loop in a bash script and continue script execution, you could use:

break

Which command is used to assign only read permission to all three categories of the file 'note'?

chmod ugo=r note

To exit the current loop iteration in a bash script and skip to the next iteration, you could use:

continue

The statement cp $file $target will not work if $file contains spaces. Which one of the following commands will fix the statement?

cp "$file" "$target"

Suppose the contents of the file test.txt are czar dAze maZe lAZy HAZY what would the output of this command be? tr '[A-Z]' '[a-z]' < test.txt

czar daze maze lazy hazy

What permission do you need to enter a directory

execute

Which of the following commands deletes all files whose filename ends in .tmp?

find . -name "*.tmp" -print | xargs rm -rf

For debugging with GDB, the file prog can be created with the command

gcc -g -o prog prog.c

Local variables in C functions are allocate in which memory?

in stack

The shell:

is a command interpreter, provides a user interface

What does this command do? echo a > b

it creates a new file

ls -a ls -l ls -F ls -R

list hidden files display a long list of information about files display a / after a directory recursively list subdirectories

Which of the following Unix command can be used to rename a file in the current working directory?

mv

If p is defined as int *p, and we use malloc() to allocate memory for *p, where are p and *p allocated?

p is allocated in stack and *p is allocated in heap

In awk, the default action, if the selection criteria are missing, is

print

To print the value of a variable while debuggin with gdb, which command can be used?

print

What permissions do you need to see the contents of a directory?

read

Which one is faster?

redirecting using pipes

What does this command redirect? myprogram 2> file

redirects the standard error

For debugging with GDB, the compiled program can be run by the command

run

The following are sed commands. Check all that apply.

s (for substitute) p (for print) d (for delete) c (for change)

Choose the command that creates a tar file

tar cvf file

If c is a int, the following is a valid condition in C ((c == 'Y')|| (c = 'Y'))

true

catt is matched by the regular expression (h|c|b)at*

true

If v and value are local variables in a bash script, check the statement that represents a correct assignment

v=$value

Which awk command outputs the sum of the first two fields on every line:

{ print $1+$2 }

awk uses which of the following two as comparison operators?

||, &&


Set pelajaran terkait

Mental Health Exam 4 Practice Questions

View Set

Wireless Networking Chapter 2 -Radio Frequency Fundamentals

View Set

PRS Inservice- Skin/Fat/Cartilage Graft

View Set

Blood Vessels: Tunics, Arteries, Veins, and capillary structure

View Set

Algebra 4.2 Set A Point Slope to Slope Intercept

View Set

Insurance Exam CH 11 Individual Policy Provisions

View Set