170 likes | 279 Views
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
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, PID • 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 • echo $(pwd) • echo $((1+1)) • VAR=hello* • echo $VAR • Single quote suspends all expansions
Alias • Short names (commands) • alias rm=‘rm –i’ • alias ll=‘ls –l’ • alias mypwd1=“echo pwd is $PWD” • alias mypwd2=‘echo pwd is $PWD’
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 • In command line, the order of command name and arguments can be changed as long as there is no ambiguous interpretation. We tried an example in class: ‘echo hello world > hello world’ generated a file ‘hello’ which contains ‘hello world world’. Now, if we execute “> echo echoecho” 1). What is the output: • Display “echo echo” • Create a file “echo echo” • Create a file “echo” which contains a line of “echo” • An error message of “command not found” 2). Which echo is the command name: a. The 1st b. The 2nd c. The 3rd
Questions • Which of the following commands displays the value of the present working directory: • $pwd • echo pwd • echo $(pwd) • pwd | echo