Co004 projects on operating systems
This presentation is the property of its rightful owner.
Sponsored Links
1 / 16

CO004 Projects on Operating Systems PowerPoint PPT Presentation


  • 92 Views
  • Uploaded on
  • Presentation posted in: General

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Co004 projects on operating systems

CO004 Projects on Operating Systems

UNIX - Basics 02


Outline

Outline

  • Directory

  • Display a file

  • Input/Output Redirection

  • Pipe


1 directory

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.


Several directories

Several directories:

  • . current directory

  • .. parent directory

  • ~ home directory of the current user.

    • E.g., [[email protected]] cd ~/program

    • Will change current working directory to / home/s10X0157/program


2 displayfiles

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


Co004 projects on operating systems

cat

  • Display a file

  • -E :end-of-line is displayed as $;

  • -n :display with line no. ;

  • -T :[tab] is shown as ^I ;


Co004 projects on operating systems

tac

  • Display a file in reversing way

  • Display the last line first, then the second last line, so on…


Co004 projects on operating systems

nl

  • display a file with line no.

  • The same as cat - n file


More and less

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


Head and tail

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


Co004 projects on operating systems

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 ;


3 redirecting the output

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)


3 redirecting the input

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.


4 pipes

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


Wildcards

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


Reference

Reference

  • 鳥哥的 Linux 私房菜 http://linux.vbird.org/

  • UNIX Quick Reference Sheet http://sunsite.utk.edu/UNIX-help/quickref.html


  • Login