1/154
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
gdb - steps through program one step at a time
n (next)
A product that can be used to determine and find memory leaks
Valgrind
Create and maintain static libraries
ar (archive)
A single copy of a library loaded into memory
Shared libraries
First call to open returns
3
Get to root directory
/
File descriptor
fd
Function that returns a different value every second
time()
Output exit status of most recently run code
echo $?
Relative path to home directory
~
When matching file names in shell, what matches any single character? (example of file name expansion)
?
Developer of Linux
Linus Torvalds, University of Helsinki
GNU
GNU's Not Unix
Where was C developed?
Bell Laboratories
Libraries in Linux are known as archives. What is the typical file extension?
.a
Create directory named 'cs3336' (located back one directory in myClass)
mkdir ../myClasses/cs3336
Print all files named fooxx (f case insensitive, xx - two base 10 digits) to printer ecs312
lpr -P ecs312 [Ff]oo[0-9][0-9]
Swap order of 1st and last name in a file named classList.txt
sed -E 's/(.)(.)/\2\1/'
Find the max value using a bash shell script
#!/bin/bash
maxValue()
{
big = $1
for val
do
if [[ $big -lt $val ]]
then
big = $val
done
echo $big
}
ret = $(maxValue 15 18)
Write a makefile for project (myprog)
- Must have ability to clean, use at least 1 macro, force gnu89 standard on all compiles
cc = gcc -std=gnu89
OBJ = main.o a.o b.o
myprog: $(OBJ)
$(cc) -o myproj $(OBJ)
clean:
rm myprog $(OBJ)
main.o: main.c a.h b.h
$(cc) -c main.c
a.o: a.c a.h b.h
$(cc) -c a.c
b.o: b.c b.h
$(cc) - c b.c
What is a system call?
Fundamental interface between an application and the Linux kernel.
How are they similar/different from other functions?
Other functions (wrapper functions) invoke system calls. System calls perform the same functions as library functions, but at a different layer of abstraction.
When would you choose to use a system call versus another function?
When working with file descriptors and pipes, system calls must be used to read and write.
Using only system calls for I/O, write readADigit()
- reads individual digit, give int back to calling function if it exists
readADigit(int fd)
{
int answer = -1;
char ch;
if ((read(fd, &ch, 1) != -1) || ch < '0' || ch > '9')
{
answer = -1;
}
else
{
answer = ch - '0';
}
return answer;
}
Code fragment that uses getopt() to count number of v options given on command land and prints count
-v option: get increasingly verbose diagnostic output
int main( int argc, char *argv[] )
{
int vcount = 0;
int opt;
while((opt = getopt( argc, argv, "v" )) != -1)
{
if(opt == 'v')
{
vcount++;
}
}
printf( "%d\n", vcount );
}
Calls the command pwd and redirect its stderr to a file named errLog
pwd 2> errLog
Permissions on the (1) directory are set so that any user can create files in it.
temp
Variable expansion but not file name expansion
" "
The (1) symbol will be expanded as the path to your current directory.
.
Old internet standard protocol for a remote terminal connection
Telnet (23)
Secure alternate protocol
ssh (22), encrypts communication between server and client
Print current time on system
date
Print the number of lines that the string "Bear" is found in the file pressRelease
grep -c "Bear" pressRelease
Print the contents of only the current directory in reverse lexicographical order
ls -r
Replace all occurrences of "Dwayne Johnson" in a file named pressRelease with "The Rock"
sed 's/Dwayne Johnson/The Rock/g' pressRelease
Vim: moves cursor to beginning of file
gg
Vim: get editor to save copy of current file
:w
Vim: get editor to move cursor to end of current line
$
Vim: undo last change to file
u
Regex that matches: catinthehat.txt
grep -E "catinthehat.txt" file_name
Regex that matches bears (first letter case insensitive)
grep -E "[Bb]ears" file_name
Regex that matches any number followed by a colon
grep -E "[0-9]+:" file_name
Regex that matches any 5 letter sequence that repeats at least once
grep -E "([a-zA-Z]{5}).*\1" file_name
Shell Expansions: files ending in .thm
*.thm
Shell Expansions: "file" followed by any single char followed by ".txt"
file?.txt
Shell Expansions: all files located in user SMITHB's home directory ending in ".sh"
~SMITHB/*.sh
Shell Expansions: files named "foo" with the first character case insensitive
[Ff]oo
Developers of UNIX
Denis Ritchie, Ken Thompson, Brian Kernighan
Current directory
.
Previous directory
..
Write to a stream (overwrite)
>
Write to a stream (append)
>>
Developers of C
Denis Ritchie, Brian Kernighan
Shell
Good for quick and simple development
KISS Principle
Keep it Small and Simple
Bash
Bourne Again Shell
sh
Bourne Shell
ksh
Korn Shell
csh
C Shell
Bash spawns new shell, executes given command, then returns result. (T/F)
True
Bash built-ins run on the original bash, and as a result, is faster and more efficient. (T/F)
True
Concatenate strings in bash
foo = "Hi"
bar = "there"
total = $foo$bar
""
Do not suppress variable expansion. Suppress shell expansion.
''
Suppress everything
``
Command substitution
- Identical to $(_)
0
Standard in
1
Standard out
2
Standard error
/dev/null
Universal trash can in Linux
kill
kills precess specified by pid
ps -ef | grep user_name
grabs all processes related to a specified user
head
returns first 10 lines
head -num
returns first num lines
tail
returns last 10 lines
tail -num
returns last num lines
Pipe
takes stdout for the first process and uses it as stdin for another process
export
allows every instance of the shell to have access to the variable
In Bash, 0 is considered true (T/F)
True
grep
global regular expression print
sed
special command (substitution in ed)
- manipulates strings, but by default, does not modify files
Remove all instances of 'TX', replace with Texas
sed 's/TX/Texas/g' file_name
sed: i
change in place
*
0 or more of the preceding pattern
? (file name expansion)
matches exactly one character
[...] (file name expansion)
character class
^
first of line
( )
capture group
$
last of line
{n, m}
range of a number of occurrences (at least n, at most m)
{n}
exactly n occurrences
{n, }
at least n occurrences
{ ,m}
at most m occurrences
+
1 or more
|
or
\
escape
* (file name expansion)
0 or more characters
?
0 or 1
Shebang line
#!/usr/bin/bash
- indicates what interprets the file
-rwxrwxrwx
Read, write, executable permissions
- 3 sets of octal numbers
- chmod
You must give file executable permissions OR (1)
1. explicitly give it bash when executing
ex. $bash ./hw.sh