1 / 16

CO004 Projects on Operating Systems

CO004 Projects on Operating Systems. UNIX - Basics 02. Outline. Directory Display a file Input/Output Redirection Pipe. 1. Directory. Absolute directory /home/s 1 0 X 157/program Relative directory: the directory relative to your current working directory

Download Presentation

CO004 Projects on Operating Systems

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. CO004 Projects on Operating Systems UNIX - Basics 02

  2. Outline • Directory • Display a file • Input/Output Redirection • Pipe

  3. 1. Directory • Absolute directory • /home/s10X157/program • Relative directory: the directory relative to your current working directory • E.g., your current working directory: /home/s10X157/ • Then, you can use “cd ../program”, which is a relative directory.

  4. Several directories: • . current directory • .. parent directory • ~ home directory of the current user. • E.g., [s10X0157@localhost] cd ~/program • Will change current working directory to / home/s10X0157/program

  5. 2. DisplayFiles • cat (concatenate) • tac (display a file in reversing way) • nl (display a file with line no.) • more (display a file in pages) • less (display a file in pages) • head • tail

  6. cat • Display a file • -E :end-of-line is displayed as $; • -n :display with line no. ; • -T :[tab] is shown as ^I ;

  7. tac • Display a file in reversing way • Display the last line first, then the second last line, so on…

  8. nl • display a file with line no. • The same as cat - n file

  9. more display a file with pages Press ‘space’ to the next page Only forward No backward less display a file with pages Similar to “more” Allow backward more and less

  10. head [-n number] file List the first n lines of file tail [-n number] file List the last n lines of file head and tail

  11. od • od -t • Display a file in non-text file • -t :with various (TYPE), e.g. c :ASCII d[size] :decimal display; o[size] :octal display; x[size] :hexadecimal display ;

  12. 3. Redirecting the Output • We use the > symbol to redirect the output of a command. % cat > list1 pearbananaapple^D {this means press [Ctrl] and [d] to stop} % cat list1 • Appending to a file >> % cat >> list1 peach grape orange ^D (Control D to stop)

  13. 3. Redirecting the Input • Using < you can redirect the input to come from a file % sort < list1 • To output the sorted list to a file, type, % sort < lists > slist Note that lists and slist should be different.

  14. 4. Pipes • To see who is on the system with you, type % who • One method to get a sorted list of names is to type, % who > names.txt % sort < names.txt • We can use pipe to do this % who | sort • will give the same result as above, but quicker and cleaner. To find out how many users are logged on, type % who | wc -l

  15. Wildcards • The * wildcard • The character * is called a wildcard, and will match against none or more character(s) in a file (or directory) name. For example % ls list* This will list all files in the current directory starting with list.... • Try typing % ls *list This will list all files in the current directory ending with ....list • The ? wildcard • The character ? will match exactly one character.So ?ouse will match files like house and mouse, but not grouse. Try typing % ls ?list

  16. Reference • 鳥哥的 Linux 私房菜 http://linux.vbird.org/ • UNIX Quick Reference Sheet http://sunsite.utk.edu/UNIX-help/quickref.html

More Related