Homework Quiz Questions Flashcards
Linux is a free operating system developed for the __________
processor that is intended to replicate the functionality of ________
80X86, Unix
Linux was first released by ___________ , who was a student at University of Helsinki at the time.
Linus Torvalds
C was developed at _________ in the early 1970’s simultaneously with
_______.
Bell Labs, Unix
The command ____________ prints the absolute path to your current working directory.
pwd
The ____________ command is used to change permissions on a file.
chmod
________ changes the working directory to the root directory
cd /
________ changes the working directory to the user’s home without using tilde expansion.
cd
______ changes the working directory to the user’s home directory using tilde expansion.
cd ~
______ changes the working directory to the user bob’s home directory using tilde expansion.
cd ~bob
Explain the differences between a static C library and a C shared library
Static libraries are libraries that can be used in multiple programs, inside of a program when it is compiled. Conversely, shared libraries exist completely separate from the compiled program as a separate file or files
Write a command that assigns the value “CSI 3336” to an environment variable named classNumber.
classNumber=”CSI 3336”
Write a command that assigns the value “Systems Programming” to an environment variable named className.
className=”Systems Programming”
Write a command that concatenates the values found in classNumber and className into a new environment variable named class
class=”$classNumber$className”
Write a command that lists the directory contents of the local directory and all subdirectories.
ls -r
Write a command that creates a new directory named cs3336 in the current working directory.
mkdir cs3336
Write a command that displays the current system time.
date
Write a command that changes the permissions of a file named output rwxr-xr— using octal numbers in combination with chmod.
chmod 754 output
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
Write a command that displays all exported environment variables
env
Explain what cat does
cat reads the files you provide and writes them out sequentially to stdout. It can be used to quickly examine the contents of a file, or a few small files.
Explain what less does
less is a quicker version of more. It displays the contents of a file in a page-by-page format, but doesn’t load the whole file at once which makes it faster. This makes it a much better option for just viewing files than opening them up in something like vi or vim.
Write a command that displays the first 5 lines of a file named classList.txt.
head -n 5 classList.txt
Write a command that displays the last 10 lines of a file named classList.txt.
tail -n 10 classList.txt
Write a command that changes the status time (this includes access, modify, and change times) of a file named myFile to the current system time.
touch myFile
Write a command that removes all files in the current directory that end with .del
rm *.del
What command can be used to copy files from one system to another (e.g. your local computer to the department Linux boxes)?
scp
Explain how bash manages execution of commands with regards to processes.
When a command is executed, a new child process is created and put in the foreground. Other processes are put in the background. You can switch between these different commands being executed similarly to switching tabs on a computer by moving processes to the foreground/background.
Provide the proper filename expansion for the following (assume local directory) for all files ending in .sh
*.sh
Provide the proper filename expansion for the following (assume local directory) for all files beginning with assign
assign*
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
Provide the proper filename expansion for the following (assume local directory) for all files beginning with assign, containing a single digit, and ending with .tar.gz.
assign[0-9].tar.gz
Provide the proper filename expansion for the following (assume local directory) for all files in bob’s home directory ending with .csv.
~bob/*.csv
Provide the proper regular expression (regex) for the following (assume single match per line) for all items that contain the string “file”.
.file.
Provide the proper regular expression (regex) for the following (assume single match per line) for all items that begin with the string “file”.
^file.*
Provide the proper regular expression (regex) for the following (assume single match per line) for all items that end with the string “ing”.
.*ing$
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.
.([a-zA-Z]{4,5}).\1
Provide the proper regular expression (regex) for the following (assume single match per line) for all items that starts with a number (multiple digits possibly) immediately followed by a colon (don’t worry about 0: )
^[0-9]+:
Provide a one-liner to print all processes being run by the first user listed by who.
ps -u who | head -n 1 | sed "s/ .*//"
Provide a one-liner to send email with the subject, “welcome”, to all users listed in a tab delimited file, named “folks.csv” (the third value in the record is the email address). The body for the email is found in a file named “welcome”.
awk -F’\t’ ‘{print $3}’ folks.csv | xargs -I{} mail -s “welcome” {} < welcome
What must be provided to execute a program located in the local directory (assuming the local directory is not in the path and the file is set as executable)? Why?
./ must be provided before the filename. This is because the shell only searches for executable files in the PATH, so it won’t be able to find anything outside of the PATH without some kind of explicit instruction. The ./ tells the shell that the executable file is in the current directory. This is done for security as files outside the PATH could be tampered with, so it is best to make sure what you are executing is something that you have cleared and put in your PATH, or are sure that you are running from the current directory.