xuan guo review for exam 1 exam 1 on june 24 csc 3320 1

17
Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Upload: oscar-todd

Post on 24-Dec-2015

238 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 1

Review for Exam 1

Exam 1 on June 24

Page 2: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 2

• pwd• cat (like concatenate), head, tail• ls, cd• mv, cp, rm• mkdir, rmdir• file (determine file type), wc (word count)• chmod• Regular Expression• grep, egrep, awk, sed• at, crontab• find, sort, tr, tar, ln, gzip, su, sudo

Page 3: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 3

1) Create a sub-directory called “temp” in your home directory $ mkdir temp

2) Create a sub-directory called “subtemp” in “temp” $ mkdir ./temp/subtemp

3) Create file ex1.txt in “temp” and ex2.txt in “subtemp” $ cd temp $ cat > ex1.txt pwd ls ^D $ cd subtemp $ cat > ex2.txt Hello ex2! ^D 4) Check file type and file's user access mode for file ex1.txt and ex2.txt $ cd ~ $ ls -l ./temp/ex1.txt

Page 4: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 4

5) rename ex1.txt as ex1 and move it to home directory $ mv ~/temp/ex1.txt ~/ex1

6) change file pemissions of ex1, add user and group execute permission. $ chmod ug+x ~/ex1

7) copy file ex1 to your home directory $ cp ~/ex1 ~/

8) copy the whole “temp” to ~/temp1 $ cp -r ~/temp ~/temp1

9) remove all files and sub-directories in “temp” $ rm -r ~/temp/*

10) remove “temp” $ rmdir ~/temp

Page 5: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 5

Example Questions

• grant all exe files (extended name is exe) in the current directory or its subdirectories permission 777

• create a hard link file1link for file1

• display the hard link count for file1 and file1link

• remove file1

• display the hard link count for file1link

• create a soft link file1 for file1link

• use ls –l display attributes of file1 and file1link

Page 6: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 6

• display the content of file1

• use ls-l display file1

• create a directory tartest in your home directory

• copy all files and directories in your home directory into tartest

• archive tartest to tartest.tar

• archive tartest to tartest1.tar with gzip option

Page 7: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 7

• display file size of tartest.tar and tartest1.tar

• archive the current directory to current.tar

• create a directory tartest2 in your home directory

• extract tartest.tar

• copy tartest1.tar to tartest2 and extract tartest1.tar in tartest2

Page 8: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 8

Given the file ‘rolllist' format:first-name last-name patherID register_way major credit

Page 9: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 9

Example Questions (sort)

• sort file

• sort it in reverse order

• sort on second field

• set “,” as separator, sort on second field

• set “.” As separator , sort on the third field by numeric order

Page 10: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSc 3320 10

Basic Regular Expression & Extended Regular Expression

Meta-characters in Basic Regular Expression^ $ . * \( \) [ ] \{ \} \

vi, grep, sed accept basic regular expression.

Meta-characters in Extended Regular Expression

| ^ $ . * + ? ( ) [ ] { } \

egrep, grep –E, sed –E accept extended regular expression

Page 11: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 11

Regular Expression Text Match?[A-Z] AB[0-9] 2111* 11

[V|B]+ VB^[A-Z][a-z]*3[0-5] Xabcdefghijklmnopqrstuv30

^[A-Za-z]*[^,][A-Za-z]*$ AaBbCc,AaBbCc^[A-Z]..*$ A bcd

Page 12: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 12

Example Qustions (grep/egrep)

Given the file 'databook' (you can download it from websitehttp://www.cs.gsu.edu/~xguo9/teaching/csc3320/databook) containing the lines of the following format:Type first-name last-name email-address

Page 13: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 13

Example Qustions (grep/egrep)

Do the following queries:a. Print all lines containing the string CS4520.

b. Print all lines where the person's first name starts with J.

c. Print all lines that contain .com

d. Print all lines containing an upper-case letter, followed by four lower-case letters, a space and one uppercase letter.

Page 14: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 14

Example Qustions (sed)

Use the file 'databook', do the following queries:a. Change Dumitru's name to Dima. b. Delete the first 3 line. c. Print all lines where the email address contains @student.gsu.edu d. Replace the line containing "CS2010" with "NULL NULL NULL NULL".

e. Append the following new line at the end of the file.CS 3320 Xuan Guo [email protected]

Page 15: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 15

Example Qustions (awk)

a. Print all email address.

b. Print Dumitru's name and email address.

c. Change the type with the following rule:If line number modulo 3 is 1, the type field should be changed toCS4520. If line number modulo 3 is 2, the type field should be changed toCS2210. Otherwise keep the original type field.

Page 16: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 16

• Write a command that archives and compresses the contents of a file, and writes the result to a new file. What is the corresponding command to extract it to produce the original file?

• Write a command to find files in a directory hierarchy (e.g. your home directory) that have the name pattern '*.txt" and compress them.

• Display the name of the owner of the shell

• Switch User to root

• Schedule jobs in file crontab.cron to be executed on a periodic basis.

• List the content of a registered crontab file.

• Unregister crontab.cron file

Page 17: Xuan Guo Review for Exam 1 Exam 1 on June 24 CSC 3320 1

Xuan Guo CSC 3320 17

• Schedule jobs in file at.csh to be executed 3 minutes later.

• List the jobs which is scheduled by at

• Delete jobs of at.csh

• Print the line number and the content of file /etc/passwd from Line 10 to Line 50

• Display the results of file “float” which covert all upper-case characters in file float into lower-case.