180 likes | 188 Views
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.
E N D
Midterm Review IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Basic Utilities • ls, cat, echo • ls –l, ls -a • cat file1 file2 file3 … • echo “hello world” > file • echo $VAR, echo hello*
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
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)
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*
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
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 )
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
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)
Processes • PID and PPID • sleep 10& • ps -f
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.
Variables • System variables • $PATH, $PWD, $HOME • User defined variables • VAR=hello • export VAR=hello • declare; declare -x
Expansion/ Quote • Types • echo hello*; echo ~ • echo $VAR • VAR=hello* • echo $VAR • Single quote suspends all expansions
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
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
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
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
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