Homework 1: Linux

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

7 % 7 = ?

0

Use the following code (the name of this program is test.py) for the next six questions. 1 import sys 2 3 var1 = sys.argv[1] 4 var2 = sys.argv[2] 5 6 total = var1 + var2 7 8 var3 = var1.upper() 9 var2 = var2.upper() 10 11 var4 = var1.count("T") 12 var5 = var2.count("T") 13 14 var6 = len(var1) 15 What is the value of var4 at line 13 when my command line is: python3 test.py "ttt" "ttt"?

0

7 % 6 = ?

1

Count the words, characters and lines in a file

wc

After seeing the first and last lines of names.txt, you're wondering how many total lines are in names.txt. How would you find out how many lines there are (and only the number of lines)?

wc -l names.txt

How about how many words are in names.txt (and only the number of words)?

wc -w names.txt

Referring to the file system above, indicate if the following path is an absolute path, a relative path, or both. /fslhome/Lucy/genomes/

absolute path

Referring to the file system above, indicate if the following path is an absolute path, a relative path, or both. ~/compute/

absolute path

Print the contents of a file to the screen

cat

Assume that in the current working directory there are two files, names1.txt and names2.txt, and you want to combine them into one file with the contents of names1.txt appearing first, followed by the contents of names2.txt. How would you do this? The name of the combined file should be names1.txt.

cat names2.txt >> names1.txt

Change between directories

cd

Immediately after moving to /fslgroup/fslg_BIO165/, which command(s) will move you back to your home directory? (Mark all that are correct.)

cd --, cd ~, cd

Assuming you are in your home directory, how would you move to /fslgroup/fslg_BIO165/?

cd /fslgroup/fslg_BIO165/

Copy (or duplicate) a file

cp

Assuming you are in your home directory and there is a file called test.txt in the /fslgroup/fslg_BIO165/ directory, how would you copy it to your home directory?

cp /fslgroup/fslg_BIO165/test.txt .

Assuming you are not in your home directory and there is a file called test.txt in the /fslgroup/fslg_BIO165/ directory, how would you copy it to your home directory?

cp /fslgroup/fslg_BIO165/test.txt ~/

Assuming you are in your home directory and the file test.txt is located in your home directory, how would you create a duplicate copy of the file, called test.txt, in the /fslgroup/fslg_BIO165/ directory? (Mark all that are correct.)

cp test.txt /fslgroup/fslg_BIO165/test.txt cp test.txt /fslgroup/fslg_BIO165/

Assuming you are in your home directory and the file test.txt is located in your home directory, how would you create a duplicate copy of the file, called test2.txt, in your home directory?

cp test.txt test2.txt

7 / 2 = the answer of this expression is what variable type?

float/double

7 / 2.0 = the answer of this expression is what variable type?

float/double

27.0

floating point

3.7

floating point

List the first lines of a file

head

Assume there's a file called names.txt in the current working directory but you can't remember what's in it. How would you print the first three lines of the file to the screen?

head -n 3 names.txt

For questions 26-30, assume there are two files, names1.txt and names2.txt, in the current working directory. Which of the following commands will print only the third line from names1.txt to the screen?

head -n 3 names1.txt | tail -n 1

Use the following snippet of Python code to answer the next five questions. 1 #!/usr/bin/env Python 2 3 Var1 = "hi" 4 hi = "goodbye" 5 Var2 = "hello" 6 Food = "hamburger" 7 Nucleotide = "A" 8 9 print("hi") 10 print(Var1) 11 print("My favorite food is",Food) What is printed to the screen when line 10 is executed?

hi

Use the following snippet of Python code to answer the next five questions. 1 #!/usr/bin/env Python 2 3 Var1 = "hi" 4 hi = "goodbye" 5 Var2 = "hello" 6 Food = "hamburger" 7 Nucleotide = "A" 8 9 print("hi") 10 print(Var1) 11 print("My favorite food is",Food) What is printed to the screen when line 9 is executed?

hi

-10

integer

13

integer

7 % 7 = the answer of this expression is what variable type?

integer

Look at the first page of a file with the ability to scroll through the rest of the file

less

Assuming I'm still in my home directory, how would I see all the files located in my home directory?

ls

List files or directories

ls

Assuming you are in /fslgroup/fslg_BIO165/, how would you list all the files and directories in your home directory?

ls ~/

Open a manual page for a command

man

Create a new directory

mkdir

Assuming you are in your home directory, how would you create a directory called bio165_labs in your home directory? (Mark all that are correct.)

mkdir bio165_labs mkdir ~/bio165_labs

Rename a file

mv

Assume you created a file called dna.txt in the current working directory, but you didn't realize that you weren't in your home directory. How would you move dna.txt to your home directory?

mv dna.txt ~/

Assuming you created a file called tset.txt in the current working directory and you meant to name it test.txt, how would you rename it?

mv tset.txt test.txt

List the current working directory

pwd

What is the output of the following command: int("3.5")?

python error

Referring to the file system above, indicate if the following path is an absolute path, a relative path, or both. Lucy/fslarchive/project1/

relative path

Delete a file

rm

Assuming you are back in your home directory, how would you delete dna.txt, a file currently in your home directory?

rm dna.txt

Assume you don't know which directory you're in, you've forgotten how to figure out where you are, and you know there's a file called dna.txt in your home directory. How would you delete dna.txt even though you may, or may not be, in your home directory where the file is located?

rm ~/dna.txt

It turns out there wasn't a file called dna.txt in your home directory. What message appears when you try to delete it?

rm: cannot remove 'dna.txt': No such file or directory

Delete an empty directory

rmdir

How would you delete the sequences directory (located in the current working directory)?

rmdir sequences/

"-5"

string

"-5.1"

string

"Hello"

string

"no"

string

List the last lines of a file

tail

What about the last ten lines of names.txt?

tail names.txt

Use the following code (the name of this program is test.py) for the next six questions. 1 import sys 2 3 var1 = sys.argv[1] 4 var2 = sys.argv[2] 5 6 total = var1 + var2 7 8 var3 = var1.upper() 9 var2 = var2.upper() 10 11 var4 = var1.count("T") 12 var5 = var2.count("T") 13 14 var6 = len(var1) 15 What is the value of total at line 7 when my command line is: python3 test.py "1" "2"?

"12"

Use the following code (the name of this program is test.py) for the next six questions. 1 import sys 2 3 var1 = sys.argv[1] 4 var2 = sys.argv[2] 5 6 total = var1 + var2 7 8 var3 = var1.upper() 9 var2 = var2.upper() 10 11 var4 = var1.count("T") 12 var5 = var2.count("T") 13 14 var6 = len(var1) 15 What is the value of var2 at line 10 when my command line is: python3 test.py "aaa" "aaa"?

"AAA"

Use the following code (the name of this program is test.py) for the next six questions. 1 import sys 2 3 var1 = sys.argv[1] 4 var2 = sys.argv[2] 5 6 total = var1 + var2 7 8 var3 = var1.upper() 9 var2 = var2.upper() 10 11 var4 = var1.count("T") 12 var5 = var2.count("T") 13 14 var6 = len(var1) 15 What is the value of var1 at line 10 when my command line is: python3 test.py "aaa" "aaa"?

"aaa"

Use the following snippet of Python code to answer the next five questions. 1 #!/usr/bin/env Python 2 3 Var1 = "hi" 4 hi = "goodbye" 5 Var2 = "hello" 6 Food = "hamburger" 7 Nucleotide = "A" 8 9 print("hi") 10 print(Var1) 11 print("My favorite food is",Food) What is the value of Var2 (line 5)?

"hello"

Use the following snippet of Python code to answer the next five questions. 1 #!/usr/bin/env Python 2 3 Var1 = "hi" 4 hi = "goodbye" 5 Var2 = "hello" 6 Food = "hamburger" 7 Nucleotide = "A" 8 9 print("hi") 10 print(Var1) 11 print("My favorite food is",Food) What is the variable type of Var2 (line 5)?

"hello" Boolean Var2 integer ANS: None of the options is correct.

Use the following code (the name of this program is test.py) for the next six questions. 1 import sys 2 3 var1 = sys.argv[1] 4 var2 = sys.argv[2] 5 6 total = var1 + var2 7 8 var3 = var1.upper() 9 var2 = var2.upper() 10 11 var4 = var1.count("T") 12 var5 = var2.count("T") 13 14 var6 = len(var1) 15 What is the value of var5 at line 13 when my command line is: python3 test.py "ttt" "ttt"?

3

Use the following code (the name of this program is test.py) for the next six questions. 1 import sys 2 3 var1 = sys.argv[1] 4 var2 = sys.argv[2] 5 6 total = var1 + var2 7 8 var3 = var1.upper() 9 var2 = var2.upper() 10 11 var4 = var1.count("T") 12 var5 = var2.count("T") 13 14 var6 = len(var1) 15 What is the value of var6 at line 15 when my command line is: python3 test.py "aaa" "aaa"?

3

What is the output of the following command: int("3")?

3

What is the output of the following command: int(3.5)?

3

What is the output of the following command: int(float("3"))?

3

What is the output of the following command: int(float("3.5"))?

3

What is the output of the following command: float("3")?

3.0

What is the output of the following command: float(3)?

3.0

What is the output of the following command: float(int("3"))?

3.0

7 / 2 = ?

3.5

7 / 2.0 = ?

3.5

What is the output of the following command: float("3.5")?

3.5

What is the output of the following command: float(3.5)?

3.5

For questions 26-30, assume there are two files, names1.txt and names2.txt, in the current working directory. If I assume (just for this question) that names1.txt has 33 lines in it and I execute cat names1.txt > names2.txt, how many lines will be in names1.txt and names2.txt, respectively?

33, 33

For questions 26-30, assume there are two files, names1.txt and names2.txt, in the current working directory. If I execute, cat names1.txt, how many lines will print to the screen?

All the lines in names1.txt will be printed.

False

Boolean

True

Boolean

Assume you created a file called test.txt in the current working directory but you meant to name it dna.txt. Furthermore, assume there is already a file named dna.txt in the current working directory. What would happen if you tried to rename test.txt dna.txt?

It would overwrite dna.txt.

In question 10, if there were already a file called test.txt in the /fslgroup/fslg_BIO165/ directory, what would happen to the existing file when you try to create a file called test.txt in the /fslgroup/fslg_BIO165/ directory?

It would overwrite the existing file.

Use the following snippet of Python code to answer the next five questions. 1 #!/usr/bin/env Python 2 3 Var1 = "hi" 4 hi = "goodbye" 5 Var2 = "hello" 6 Food = "hamburger" 7 Nucleotide = "A" 8 9 print("hi") 10 print(Var1) 11 print("My favorite food is",Food) What is printed to the screen when line 11 is executed?

My favorite food is hamburger

What is the output of the following command: float("hello")?

Python error

What is the output of the following command: float(int("hello"))?

Python error

For questions 26-30 assume there are two files, names1.txt and names2.txt, in the current working directory. If I execute, cat names1.txt | head, how many lines will print to the screen?

There's no way to know the answer without more information.

For questions 26-30, assume there are two files, names1.txt and names2.txt, in the current working directory. If I assume (just for this question) that names1.txt has 33 lines in it and I execute cat names1.txt >> names2.txt, how many lines are in names1.txt and names2.txt, respectively?

There's no way to know the answer without more information.

You've just deleted a file, genomes.txt. How do you recover it?

You can't. In Linux, when you delete a file, it's gone forever.

What happens when you try to delete a directory called sequences that has other directories or files in it?

You receive a message that says, "rmdir: failed to remove 'sequences': Directory not empty."

What's the absolute path of the directory you're in when you first log in?

~/


संबंधित स्टडी सेट्स

OB - Chapter 16 : Nursing Managment During Postpartum Period

View Set

Microbiology: Chapter 13 - Reading Assignment

View Set

Fundamental HESI, Hesi Fundamentals, Hesi Fundamentals Practice Test, UNIT 1: Foundations of Nursing Practice

View Set

Chapter 4 and 5 Servsafe Practice

View Set

DECA-Business Administration Core, BUSINESS ADMINISTRATION CORE EXAM, Business Administration Core Exam, Business Administration Core Sample Exam, Business Administration Core Sample Exam, DECA Sample Exam (Business Administration Core), DECA Busines...

View Set

Python Essentials: Part 1 - Module 3

View Set

sublimation, vaporization , condensation, deposition, melting, freezing

View Set