BAYLOR CSI 3336 Exam 1

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/113

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

114 Terms

1
New cards

Where was Unix designed and when?

1970 at Bell Labs

2
New cards

Who created Linux?

Linus Torvalds

3
New cards

Who developed C and when?

Dennis Ritchie and Brian Kernighan in 1972

4
New cards

Unix is built on

-Simplicity => KISS Principle

- Focus => Pick one thing to work on

- Filters => Filter info you don't want

- Open File Format => Linux, unlike windows, has open file format

- Flexibility => Users can do anything

5
New cards

Linux Programs broken into 2 different types

Binary- Compiled into machine code

- Ends in .bin, .run

Scripts

- Are interpreted

- Python, bash, perl

Both are executable

6
New cards

~

Absolute path to directory

echo ~ returns the current user's home directory

echo ~dinh returns dinh's current home directory

7
New cards

PATH

Environment variable that specifies a set of directories where executable (binaries) are found.

- export PATH=/new/directory:$PATH

- Sets PATH variable to new/directory, followed by existing path variable

- $PATH is the current PATH

8
New cards

cat

used to display content of file or join multiple files

cat file1.txt file2.txt > new.txt

- joins file1.txt and file2.txt combined into new.txt

9
New cards

rename

renames file

rename .out.txt .csv *

- Changes all .out.txt with .csv

10
New cards

ln

make links between files

ln -s foo sFoo

- cat sFoo will print what foo has

- if foo Removed, sFoo removed

- if ln foo nFoo, still printsHardlinks point file name to data on deviceSoftlinks point filename to another filename

11
New cards

wc

The wc (word count) command in Linux is a simple utility that displays the number of lines, word count, and bytes (or characters) in a file or files specified as input.

wc [options] [files]

Count lines: To count the number of lines in a file:

- wc -l filename

Count words: To count the number of words in a file:

- wc -w filename

Count bytes: To count the number of bytes in a file:

- wc -c filename

Count characters: To count the number of characters in a file:

- wc -m filename

Multiple files: You can also use wc with multiple files. It will display the counts for each file individually and then a total count for all files:

- wc filename1 filename2

If you run wc without any options, it will display the line count, word count, and byte count in that order.

- wc filename

12
New cards

The Shell

Program that lets us interact w/ kernal

- windows explorer and mac finder

sh - Bourne Shell -> original

ksh - korn shell

csh - cshell (written in c)

bash - Bourne again shell

13
New cards

Which

returns location of file

which cd

- returns /usr/bin/cd

14
New cards

Filename expansion (globbing)

Specify patterns that can match multiple file names or paths.

15
New cards

? globbing

Matches any single character

EX: file?.txt matches "file1.txt", "file2.txt", but not "file10.txt".

16
New cards

[ ]

matches any single character within specified range or set

EX: [abc]*.txt matches files starting with "a", "b", or "c" and ending with .txt

EX: [0-9]*.txt matches all files starting with a digit and ending with ".txt"

EX: [0-9].txt matches all files that has a number in it, and ending with ".txt"

EX: [a-zA-Z]*.txt matches all files starting with a letter (either uppercase or lowercase) and ending with ".txt".

17
New cards

{ }

Specifies alternatives for patterns

EX: {file1,file2}.txt matches "file1.txt" and "file2.txt"

18
New cards

Suppress

echo "" prints

but echo * prints everything

echo "*" is suppressed

19
New cards

Command Substitution

Shell feature that allows you to execute a command and use its output as part of another command

result=`command`

result=$(command) -> PREFERRED

EX: current_date=$(date +%Y-%m-%d)

echo "Today's date is: $current_date"

EX: echo "The # of files in the current directory is:

$(ls | wc -l)"

EX: current_user=$(whoami)

echo "Current user is: $current_user"

EX: for file in $(ls *.txt); do

echo "Processing $file"

done

Iterate all '.txt' files and prints a message

20
New cards

Arithmetic Expansion

Perform arithmetic calculations directly on command line

EX: result=$((5 + 3))

echo "5 + 3 = $result"

$(())

21
New cards

Concatenation of Strings

str1="Hello"

str2="World"

result="$str1$str2"

echo $result => HelloWorld

result2="$str1 $str2"

echo $result2 => Hello World

22
New cards

>>

Appends

"this is some text" >> file.txt

^ above appends the text to file.txt

- if file doesn't exist, it will be created

23
New cards

Standard Streams

C++ C Linux

cin stdin 0

cout stdout 1

cerr stderr 2

infile infile 3

24
New cards

cut

remove sections from each line of files

EX: cut -d ' ' -f 1 data.txt

- `-d ' '` specifies the delimiter is the space

- -f 1 specifies the field you want to extract, so 1st field

- data.txt is the input file

Alice 25 Alice

Bob 30 -> Bob

Charlie 28 Charlie

25
New cards

awk

Used to process column text

awk 'pattern { action }' file

EX: awk '{ print $1, $3 }' file.txt

- prints first and third column of file.txt

Ex: awk '$3 > 50 { print }' file.txt

- prints out everything in 3rd column that is greater than 50

26
New cards

sort

sort lines of text files

EX: sort file.txt

- words line in file.txt in ascending order

27
New cards

less

navigate through the pages of a file

EX: less file.txt

- opens file.txt for viewing

28
New cards

lpr

print files on a printer

EX: lpr document.pdf

29
New cards

lpstat

display status of print queue on system

EX: lpstat -p- displays list of all printers and their status

30
New cards

lprm

remove print jobs from print queue

EX: lprm 123- removes print job with ID '123'

31
New cards

$HOME

Home variable

Equivalent to ~

32
New cards

$SHELL

Tells you where your shell is

33
New cards

$USER

Gets username

34
New cards

Suppression of Expansion

Prevents shell from interpreting stuff

echo "This is a \$ character"

- prints out "This is a $ character"

35
New cards

paps

"PostScript to ASCII", convert PostScript files to plain text

EX: paps input.ps > output.txt

- takes postscript file (input.ps) as input and redirects ASCII

text output to text file output.txt

36
New cards

Tarball

A compressed archive of files containing scripts that install Linux software to the correct locations on a computer system.

Create a tarball: tar -czvf archive.tar.gz /path/to/directory

37
New cards

Regular Expression (regex)

Sequence of characters that define a search pattern. Examples to follow below

38
New cards

grep

Search files for text patterns line by line. Always use -E after

- grep [options] pattern [file ...]

-i: Ignore case distinctions in both the pattern and input files.

-v: Invert the match, displaying lines that do not match the pattern.

-n: Prefix each line of output with the 1-based line number within its input file.

-l: Display only the names of files containing matches, instead of the matching lines themselves.

-c: Display only a count of the lines that contain matches, rather than the lines themselves.

-r or -R: Recursively search subdirectories listed in the command line, treating them as directories rather than simple files.

-w: Match whole words only. The expression is searched for as a word (as if surrounded by [[:<:]] and [[:>:]]).

-E: Interpret the pattern as an extended regular expression (ERE), which supports additional features such as +, ?, (), etc.

-F: Interpret the pattern as a list of fixed strings, separated by newlines, any of which is to be matched.

39
New cards

grep examples

grep "pattern" file.txt

- searches for lines containing "pattern" in file.txt

- prints out all lines that contain "pattern"

grep -i "pattern" file.txt

- case insensitive search for pattern

- prints out all lines that contain case insensitive "pattern"

40
New cards

sed

Used to edit and display edited text files

- doesn't actually edit them unless you use -i or redirect

output to another file

sed [options] 'command' [filename]

-e 'command': Specify a command directly on the command line. Multiple -e options can be used to specify multiple commands.

-f script-file: Read commands from the specified script file. Multiple -f options can be used to specify multiple script files.

-n: Suppress automatic printing of pattern space. Only explicitly printed output will be displayed.

-i[SUFFIX]: Edit files in-place. Modifies the input files directly. Optionally, you can provide a backup file suffix to -i option.

-r: Use extended regular expressions in the script.

-E: Same as -r, but provided for compatibility with some other versions of sed.

-s: Treat the input files as separate streams. Normally, sed processes input files one by one, but with this option, each file is treated as a separate stream.

--follow-symlinks: Follow symbolic links when processing input files.

-u: Use unbuffered I/O, which is useful when processing large files.

41
New cards

sed examples

sed 's/old/new/g' file.txt

- substitutes all occurrences of 'old' with 'new' in file.txt

sed '/pattern/d' file.txt

- deletes all lines that contain 'pattern'

sed -i 's/old/new/g' file.txt

- actually edits the file to replace 'old' with 'new'

- 's' stands for substitute, and 'g' stands for global, meaning it will substitute for all findings. without g, it will only replace first one

sed -n '/pattern/p' file.txt

- prints lines containing 'pattern' in file.txt

42
New cards

[] regex

Matches any single character inside:

- [dDb] matches either lowercase 'd' or uppercase 'D'.

- grep "[dDb]og" file.txt matches lines containing "dog" or "Dog" or "bog" in the file file.txt.

43
New cards

^ regex

Matches the beginning

- ^start matches lines starting with "start".

- grep "^start" file.txt matches lines starting with "start" in the file file.txt.

44
New cards

$ regex

Matches the end

- end$ matches lines ending with "end".

- grep "end$" file.txt matches lines ending with "end" in the file file.txt.

45
New cards

{n,m} regex

Range from n to m:

- a{2,4} matches "aa", "aaa", or "aaaa".

- grep "a{2,4}" file.txt matches lines containing 2 to 4 consecutive 'a's in the file file.txt.

46
New cards

{n} regex

Exactly n:

- x{3} matches exactly three consecutive 'x's.

- grep "x{3}" file.txt matches lines containing exactly three consecutive 'x's in the file file.txt.

47
New cards

{n,} regex

At least n

48
New cards

{,m} regex

At most m

49
New cards

+ regex

1 or more preceding expression:

- go+gle matches "gogle", "google", "gooogle", etc.

- grep "go+gle" file.txt matches lines containing "gogle", "google", "gooogle", etc., in the file file.txt.

- Matches that has 1 or more 0's

50
New cards

* regex

0 or more preceding expression:

- go*gle matches "ggle", "gogle", "google", "gooogle", etc.

- grep "go*gle" file.txt matches lines containing "ggle", "gogle", "google", "gooogle", etc., in the file file.txt.

- Matches 0 or more 0's

51
New cards

? regex

0 or 1 preceding expression:

- colou?r matches "color" or "colour".

- grep "colou?r" file.txt matches lines containing "color" or "colour" in the file file.txt.

52
New cards

| regex

Or

preceding or succeeding expression:

- (cat|dog) matches "cat" or "dog".

- grep "\\(cat\\|dog\\)" file.txt matches lines containing "cat" or "dog" in the file file.txt.

53
New cards

() regex

Capture group:

- (good){2} matches "goodgood".

- grep "\\(good\\)\\{2\\}" file.txt matches lines containing "goodgood" in the file file.txt.

54
New cards

. regex

Matches any single character except for newline

- a.c would match "abc", "axc", "a1c", etc., but not "ac"

- grep "b.t" file.txt matches lines containing "bat", "but", "bit", etc., in the file file.txt.

55
New cards

-rw-r—r—

The file owner has read and write permissions (rw-).

The group that owns the file has only read permission (r--).

Other users have only read permission (r--).

56
New cards

Shebang line

#! /bin/bash

The path to the interpreter for the script

57
New cards

chmod

"change mode"

- allows you to specify who can read, write, and execute file or directory

- chmod [options] mode file

- chmod 755 file

- recursively sets permissions of all files to read and write for owner only

- chmod u=rwx,g=rx,o=r file

- This command explicitly sets permissions for the owner (u), group (g), and others (o) to read, write, and execute, read and execute, and read only, respectively.

58
New cards

For loop

for var in $@; do

echo $var

done

59
New cards

Scripting comparisons for arithmetic

-gt, -ne, etc.

60
New cards

Scripting comparisons for strings

==, =, !=, etc.

-n -not NULL

-z -not empty

61
New cards

CASE Statement

case $val in

red) echo "Its red";&

bl*) echo "Its bl + anything";;

blue) echo "Its blue";;&

esac

62
New cards

________ changes the working directory to the root directory.

cd /

63
New cards

________ changes the working directory to the user's home without using tilde expansion.

cd $HOME

64
New cards

______ changes the working directory to the user's home directory using tilde expansion.

cd ~

65
New cards

______ changes the working directory to the user bob's home directory using tilde expansion.

cd ~bob

66
New cards

Explain the differences between a static C library and a C shared library.

Shared libraries exist outside of the file they are referenced in, while static libraries are compiled as part of the app.

67
New cards

Write a command that concatenates the values found in classNumber and className into a new environment variable named class.

class="${classNumber}${className}"

68
New cards

Write a command that changes the permissions of a file named output rwxr-xr— using characters (not octal numbers) in combination with chmod (without octal numbers).

chmod u=rwx,g=rx,o=r output

69
New cards

Write a command that displays all exported environment variables.

env

70
New cards

Explain what less does

Less allows you to open a file in a navigatable environment.

71
New cards

Write a command that displays the first 5 lines of a file named classList.txt.

Write a command that displays the last 10 lines of a file named classList.txt.

head -n 5 classList.txt

tail -n 10 classList.txt

72
New cards

What command can be used to copy files from one system to another (e.g. your local computer to the department Linux boxes)?

scp

73
New cards

Explain how bash manages execution of commands with regards to processes.

bash will create a new bash process using a fork

74
New cards

Provide the proper filename expansion for the following (assume local directory) for all files ending in .sh.

*.sh

75
New cards

Provide the proper filename expansion for the following (assume local directory) for all files beginning with assign.

assign*

76
New cards

Provide the proper filename expansion for the following (assume local directory) for all files beginning with assign, containing any number of characters, and ending with .tar.gz.

assign*.tar.gz

77
New cards

Provide the proper filename expansion for the following (assume local directory) for all files in bob's home directory ending with .csv.

~bob/*.csv

78
New cards

Provide the proper regular expression (regex) for the following (assume single match per line) for all items that contain the string "file".

.(asterisk)file.(asterisk)

.* any char up to file

.* any char after

79
New cards

Provide the proper regular expression (regex) for the following (assume single match per line) for all items that begin with the string "file".

^file.*

80
New cards

Provide the proper regular expression (regex) for the following (assume single match per line) for all items that end with the string "ing".

.*ing$

81
New cards

Provide the proper regular expression (regex) for the following (assume single match per line) for all items that contain the same 4 or 5 letter sequence twice.

(.....?).*\1

82
New cards

Difference between soft and hard link for files

soft link is a reference to the file (like a pointer, if the pointer is deleted, the data is fine)

hard link is another name for the file (if the alternative name is deleted, the data is deleted)

83
New cards

Formatted vs unformatted input

Formatted - uses strings to represent data and works with bytes meant to be strings (scanf, printf)

Unformatted - uses raw data (put, write)

84
New cards

Errno

Global variable that holds the numeric code of the last system-call error

85
New cards

System calls

Uses file descriptor

open

read

write

86
New cards

Formatted input functions

fopen

fread

fwrite

87
New cards

What shells can custom environment variables be used in?

The current shell and any children

88
New cards

What does time() get?

The amount of time since the last epoch 1/1/1970

89
New cards

What's the difference between strftime and strptime?

strftime - formats the date and timestrptime - parses a string into a struct tm

90
New cards

execl

executes a file and doesn't return if successful

91
New cards

fork()

Creates a child process

The return differentiates whether it's a child or parent

92
New cards

Zombie process

A process that has terminated, but whose parent has not yet called wait()

93
New cards

Wait()

Function that performs blocking

Stops the program until something is done

94
New cards

What are pipes and what are they used for

Communication channel between a parent and child process

They are shared resources so they can create a race condition

95
New cards

How do you do polymorphism in C?

Function pointers

96
New cards

When is synchronization necessary?

When there is a shared resource

97
New cards

What is mutex?

A mutually exclusive access to a resource. It's a special case of a semaphore with a maximum concurrency of 1.

98
New cards

What are semaphores?

Semaphores are a generalization of mutexes that allow access of a resource up to a limit, not just 1

99
New cards

What is sigaction?

A function to examine and change a signal action

100
New cards

Signal communication is what?

Asynchronous meaning processes stop and deal with the signal before doing anything else