1 / 18

Midterm Review

This review covers basic utilities in Unix/Linux, including commands like ls, cat, echo, more, less, head, tail, pwd, cd, cp, mv, rm, mkdir, rmdir, sort, wc, grep, and file compression with bzip2, gzip, and tar. It also covers file and path conventions, access permissions, links, executing commands, job control, redirection, variables, and expansions.

greyes
Download Presentation

Midterm Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Midterm Review IT244 - Introduction to Linux / Unix Instructor: Bo Sheng

  2. Basic Utilities • ls, cat, echo • ls –l, ls -a • cat file1 file2 file3 … • echo “hello world” > file • echo $VAR, echo hello*

  3. Basic Utilities • more, less, head, tail • head -5 file • tail -3 file • pwd, cd • cp, mv, rm, mkdir, rmdir • ‘-i’ option • ‘-r’ option: rm –r dir1 • rmdiran empty directory

  4. Basic Utilities • sort, wc, grep, |(pipe) • wc -l file, wc –c file • grep “keyword” file, grep -v • sort linux | head -5 • bzip2, gzip, tar (no compression)

  5. Filename and Path • Hierarchical tree structure • Absolute path name • ls /home/it244/it244 • Relative path name • cd /home/it244 • ls it244 • ‘.’ ‘..’ ‘~’ • ‘*’ ‘?’ • echo hello*, echo ./.?a*

  6. Access Permissions • r, w, x (chmod) • chmoda+rw file • chmod a=rx file • chmod 644 file • Execute permission of a directory • A directory is a table of files (filename:meta) • Executable means searchable

  7. Access Permissions • Operations on book/book1 • ls book/book1 • book ( x ) • cat book/book1 • book1 ( r ), book ( x ) • rm book/book1 • book ( xw ), book1 ( w )

  8. Links • Hard link and soft link • Hard link cannot refer to a directory • Soft link can point to a nonexistent file $ ln -s hello hello.sl $ rm hello $ echo “new” > hello $ cat hello.sl new

  9. Execute Commands • Foreground and background jobs • command &, CTRL+Z • difference between a suspended job and a background job, • jobs, ps, kill, bg, fg • Group commands • (cmd1; cmd2; cmd3)

  10. Processes • PID and PPID • sleep 10& • ps -f

  11. Redirection • Standard input, output, error output • cat file1 file2 > out 2>err • cat file1 file2 &> out • cat file1 file2 > out 2>&1 • Redirected output will not be displayed on the screen.

  12. Variables • System variables • $PATH, $PWD, $HOME • User defined variables • VAR=hello • export VAR=hello • declare; declare -x

  13. Expansion/ Quote • Types • echo hello*; echo ~ • echo $VAR • VAR=hello* • echo $VAR • Single quote suspends all expansions

  14. Questions Both hard links and symbolic links can refer to directories. True / False Utilities gzip, bzip2, and tar are used to compress files. True / False A shell script that needs user’s input cannot be running on the background. True / False

  15. Questions • Assume there are 3 files: file1, file2, and file3. After executing the following commands, how many files are there and what are the contents? $ cp file1 file2 $ mv file2 file3 $ rm file2 • Assume there are two directories dir1 and dir2, and dir1 contains a subdirectory dir3, what’s the result of $ cp -r dir1 dir2

  16. Questions We have learned that “grep -v” can exclude the lines containing the specified keywords. Assume there exist the following files, $ls abcbabbcdabcdbcdeabcde What is the output of “ls | grep –v ab | wc -l” : ( “wc -l” outputs the number of lines of the input text ) a. 4 b. 3 c. 2 d. 1

  17. Questions Assume your permissions allow you to write to ‘file1’, but not to delete it. Which of the following operations will certainly be denied: • ls -l file1 • cat file1 • cp file1 file2 • echo “hello world” >> file1

  18. Questions • How to determine if a given filename is a regular file or directory? • To execute ‘cat dir1/file1’, what permissions are needed and why

More Related