2505 Test 1 Review Flashcards
difference between ls and ls -l
ls -l lists more info, size in byte, modification date, file owner, group
navigate to home directory
cd ~
navigate to previous directory
cd -
navigate to root directory
cd /
pwd command
prints full system path of current working directory
command to list all files in current dir
ls
what happens when you use “cd” without a destination
goes back to the home directory
command to copy a file to specific destination
cp [original] [new] [../]
command to make a directory
mkdir [name]
command to move a file
mv [file] [dir]
command to remove
rm
command to remove A DIRECTORY
rmdir
command to rename a file
mv [oldName] [newName]
reference for current directory
.
reference for parent directory
..
command to display contents of a file
cat [file]
command to show first few lines of a file
head [file]
command to report number of lines, words, and bytes
wc [file]
command to display lines of a file that match a pattern
grep
redirection operator to send output to a file and replace its contents
>
redirection operator to append info to contents of the file
> >
redirection operator to send contents of file to a program
”
file [name]
give info about file
3 types of users
owner (user), group, other (world)
command to change permissions
chmod
command to take away read and write permissions from group from file “foo”
chmod g-rw [path to foo]
how would chmod 740 change permissions for each group
owner: r w x
group: r - -
other: - - -
numeric args for chmod
no access - 0
execute - 1
write - 2
read - 4
command to create a collection of files
tar cvf [newTar] [targetFile]
command to check contents of tar file
tar tvf [tarFile]
flat tar files have no…
path listed/directory structure
what happens if you tar a dir?
the tar file will contain path info
command to extract a tar file
tar xvf [tarName] (-C [destination])
commands to unzip zip, gzip, and bzip2 files
unzip, gunzip, bunzip2
SPECIAL CHARACTER RULE for ?
match any single character
SPECIAL CHARACTER RULE for *
match 0 or more characters
SPECIAL CHARACTER RULE for []
match any of the characters within the braces
SPECIAL CHARACTER RULE for *.txt
match any file with the ext txt
SPECIAL CHARACTER RULE for [abc]foo.html
match a file with html ext and name “afoo” “bfoo” “cfoo”
what does scp do?
copy a file between the local machine and remote machine
command to copy a file to rlogin
scp foo.txt username: targetDir
command to copy file FROM rlogin to the current dir
scp user: documents/foo.txt
create an int pointer named point
int *point;
assign the value of int “foo” to the int pointer “point”
point = &foo;
store the value of “foo” which pointer “point” points to in a NEW int variable called “var2”
int var2 = *point;
when assigning char pointers to string ARRAYS, do you need an & ?
NO
how many bytes is an int?
4 bytes
C function to find out how many bytes a data type is
sizeof(dataType)
assign initialized char pointer “point” to a char input of n using malloc
point = (char)malloc(nsizeof(char));
what is the type of &p if p is a char pointer with a target?
char**
int* q = NULL;
is
*q = 20;
valid?
No because q has no target. There will be a segfault error
When a pointer’s target becomes NULL what is the value of the pointer?
The pointer does not exist
int* p = &A;
int* q = &B;
p = q;
What does p point to now?
B
meaning of %d
base-10 integer
absolute value function
abs()
formatting to show 2 digits after decimal point in W columns
%W.2f
external linkage
not “static”, declared AND initialized outside function
internal linkage
static variable outside function
no linkage
vars inside a function
what goes at the top of a header called “foo.h”?
endif
#ifndef FOO_H #define FOO_H
static storage duration
Variables declared outside of everything or with “static”
command to create an executable for debugging
gcc -o executableName -std=c11 -Wall -ggdb3 (list C files ONLY)
while loop to use with fscanf
while(fscanf(fileName,”format”, variables) == numOfVariables)
whats the common format of a main() function?
int main(int argc, char* argv[]) { }
what happens if you accidentally call a c file where the new tar file name should be?
the c file will get overwritten with a tar file of the same name
when assigning a char ELEMENT to a char pointer do you need & ?
YES
what does calloc() do
allocates the memory and also initializes the allocated memory block to zero
args for strcpy() ?
strcpy(destinationArray, sourceArray)
how is strcpy() different from strncpy()?
strncpy() takes an arg of destination, source, index
strncpy() copies everything UP TO the index
function to get length of string
strlen()
args for calloc() ?
calloc(number of elements, sizeof(type))
code to make a duplicate of string array “Title”
char* pCopy = calloc( strlen(Title) + 1, sizeof(char) );
strncpy( pCopy, Title, strlen(Title) );
what goes at the end of a main() function
return 0;
static variables always
keep their values
variables in a function (that are passed as args) that get modified by the function should be…
pointer type
why would the terminal say that a command cannot be found after it was installed?
the directory where it was installed cannot be found in the path variable
what does warning: implicit function declaration mean?
the function was not declared before main() OR in a header file
how is an include statement for a header file IN a c file formatted?
“#include “
when assigning a variable to a pointer you need…
&
format specifier for string array vs char
string array -> %s
char -> %c
what are you going to forget when scanning?
& for the variables and “” for the format
what do we put in front of a variable in a function if we don’t want it to change
static
what does free() do
deallocates the memory previously allocated by a call to calloc, malloc, or realloc
what is a dangling pointer?
pointer pointing to a memory location that has been deleted (or freed)
int **p = …;
ptr = *p;
what type is ptr?
int*
args for realloc() ?
2 arguments, pointer to memory, new size in bytes
size of char*
8 bytes