unix talk 2010

Upload: amyjohnsonwing

Post on 05-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Unix Talk 2010

    1/58

    UNIX Talk 2010

    Reference Notes

    Dedicated to students of CENG & CSCI 3150.

    (the same handout as the one for CEG UNIX Talk, Jan 2010)

    Last update: September 13, 2010.

    Prepared by: Dr. WONG, Tsz Yeung.

    1

  • 7/31/2019 Unix Talk 2010

    2/58

    CONTENTS 2

    Contents

    1 UNIX and Our Department 5

    1.1 Your Rights - How Much Data Can You Own? . . . . . . . . . 6

    1.1.1 Keep an eye on your quota . . . . . . . . . . . . . . . . 9

    1.2 Computing Facilities - UNIX-Like Workstations . . . . . . . . 10

    1.2.1 Console login . . . . . . . . . . . . . . . . . . . . . . . 10

    1.2.2 Remote login . . . . . . . . . . . . . . . . . . . . . . . 10

    1.3 Network Services in Our Department . . . . . . . . . . . . . . 12

    1.3.1 Walkthrough: SSH login from a Windows PC . . . . . 12

    1.3.2 Web service: hosting your personal homepage . . . . . 19

    1.3.3 Email and email forwarding . . . . . . . . . . . . . . . 19

    1.4 A Short Summary . . . . . . . . . . . . . . . . . . . . . . . . . 20

    2 File Processing 21

    2.1 File & Directory . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    2.1.1 Create and Remove File . . . . . . . . . . . . . . . . . 21

    2.1.2 View Files Content . . . . . . . . . . . . . . . . . . . . 22

    2.1.3 Move and Copy Files . . . . . . . . . . . . . . . . . . . 23

    2.1.4 File Type . . . . . . . . . . . . . . . . . . . . . . . . . 24

    2.1.5 Create and Remove Directory . . . . . . . . . . . . . . 26

    2.1.6 Change Directory . . . . . . . . . . . . . . . . . . . . . 26

    2.1.7 View Directorys Content . . . . . . . . . . . . . . . . 27

    2.1.8 Special Directories . . . . . . . . . . . . . . . . . . . . 27

    2.1.9 Redirection and Pipe . . . . . . . . . . . . . . . . . . . 29

    2.2 File Permission . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    2.2.1 Read, Write, Execute Modes . . . . . . . . . . . . . . . 31

    2.2.2 Changing Modes . . . . . . . . . . . . . . . . . . . . . 322.2.3 Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    3 Process Management 34

    3.1 Display Process Details . . . . . . . . . . . . . . . . . . . . . . 34

    3.2 Kill Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

    3.3 Foreground and Background Job . . . . . . . . . . . . . . . . 35

    3.3.1 Create Background Job . . . . . . . . . . . . . . . . . . 36

  • 7/31/2019 Unix Talk 2010

    3/58

    CONTENTS 3

    3.4 Kill Background Job . . . . . . . . . . . . . . . . . . . . . . . 36

    4 Printing in Department 37

    4.1 Printing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    4.2 Printing Queue . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    4.3 Delete Print Job . . . . . . . . . . . . . . . . . . . . . . . . . 38

    4.4 Print Quota . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

    5 UNIX Tools 39

    5.1 Internal Communication . . . . . . . . . . . . . . . . . . . . . 39

    5.1.1 talk . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395.1.2 write . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    5.1.3 finger . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    5.2 Password and Personal Details . . . . . . . . . . . . . . . . . . 40

    5.2.1 passwd & yppasswd . . . . . . . . . . . . . . . . . . . 40

    5.2.2 chfn . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

    5.3 Text Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

    5.3.1 VI and VI IMproved . . . . . . . . . . . . . . . . . . . 40

    5.3.2 PICO . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

    5.4 Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

    5.4.1 SFTP . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

    5.4.2 PINE and ELM . . . . . . . . . . . . . . . . . . . . . . 41

    5.4.3 TIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

    5.4.4 LYNX . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

    5.4.5 WGET . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

    5.5 Compression and Archives . . . . . . . . . . . . . . . . . . . . 43

    5.5.1 ZIP, UnZip and Zipinfo . . . . . . . . . . . . . . . . . . 43

    5.5.2 GZIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445.5.3 Tar and GNU Tar . . . . . . . . . . . . . . . . . . . . . 44

    5.6 Image Manipulation . . . . . . . . . . . . . . . . . . . . . . . 45

    5.6.1 XV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

    5.6.2 GIMP . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

    5.7 Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

    5.7.1 GV and GhostView . . . . . . . . . . . . . . . . . . . . 46

  • 7/31/2019 Unix Talk 2010

    4/58

    CONTENTS 4

    5.7.2 ACROREAD . . . . . . . . . . . . . . . . . . . . . . . 46

    5.7.3 StarOffice . . . . . . . . . . . . . . . . . . . . . . . . . 46

    5.8 Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

    5.9 Manual Page . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

    A Installing the SSH Client Program 48

    B SHELL command 50

    C VI command 51

    D Pico Command 55

  • 7/31/2019 Unix Talk 2010

    5/58

    1 UNIX AND OUR DEPARTMENT 5

    1 UNIX and Our Department

    The rule of thumb to survive in our department is to know and to workwith UNIX. UNIX-like systems are everywhere in this department.

    Mac is a UNIX-like system;

    Linux is a UNIX-like system; and

    UNIX itself.

    UNIXStorageServers

    EmailServer

    WebServer

    Samba Servers

    (smb1, smb2, etc)Windows

    PCWindows

    PC

    UnixWorkstation

    UnixWorkstationUnix

    Workstation

    H Drive

    Mac PCsMac PCsMac PCs

    UsingSSH

    gateway

    (gw.cse)

    UsingSSH

    Internal Network

    External Network

    Mac PCsMac PCsLinux

    PCs

    Figure 1: Networking and services in our department.

    Figure 1 shows you the fact that nearly all services in our department

    are centered around the UNIX storage servers. They contain your user

  • 7/31/2019 Unix Talk 2010

    6/58

    1 UNIX AND OUR DEPARTMENT 6

    accounts and your emails (and, of course, there are tons of other things

    that you may not be interested).

    If you are still not convinced that you do not need any knowledge about

    UNIX systems, please take a look at the following list of inconvenient

    truths.

    The Windows PCs in our department only allow you to access files

    stored in your user account, but not other services such as checking

    your disk quota.

    You cannot use the H drive in the Windows PCs in your home.Only SSH programs can help you, and you may also need those UNIX

    commands, too.

    You cannot check your print quota in the Windows PCs. You can only

    do so in UNIX.

    For some courses, you can only work in UNIX-like systems, e.g., CSCI

    & CENG3150, CENG3430, CENG3470, CSCI3170, CSCI5470, etc.

    So, why not learning how to work with the UNIX system?

    1.1 Your Rights - How Much Data Can You Own?

    As a matter of fact, you are entitled to host more than 2GB of data in our

    department. However, the access to the data is quite restricted. Figure 2

    has shown the storage space and the corresponding ways to access them.

    UNIX personal account. This is the primary place for you to store

    your source code, lecture notes, etc. The good about this storage is

    not only big, but also is a shared place between the UNIX workstation

    and the Windows PCs.

    In order words, after you have copied a source code file from a Windows

    PC to the personal account, you can immediately modify it in a UNIX

    workstation!

  • 7/31/2019 Unix Talk 2010

    7/58

    1 UNIX AND OUR DEPARTMENT 7

    UNIX PersonalAccount

    2GB

    WindowsPC

    WindowsPC in lab

    WindowsProfile50MB

    Email50MB

    N Drive

    H Drive

    UnixWorkstation

    UnixWorkstationWorkstation

    Your home directory

    Directory:/var/mail/[login ID]

    /public100MB

    Directory:/public

    Figure 2: The storage service provided to every user in the department.

    Windows profile. The second attractive place is the Windows profile.

    It stores your Windows account data: your desktop, your wallpaper,

    etc. With this storage, you can log in at different Windows PCs but

    have the same desktop and the same wallpaper.

    However, the quota is just not enough and will easily be used up.

    Therefore, remember to always move files in your desktop to the UNIX

    personal account.

    Email. Emails are stored inside the UNIX storage system and therefore

    can only be accessed through UNIX workstations only, not Linux

    nor Mac. E.g., if you were the user tywong, then you can find your

    email at the location /var/mail/tywong.

    It is always interesting to know that all your emails are stored as ONE

  • 7/31/2019 Unix Talk 2010

    8/58

    1 UNIX AND OUR DEPARTMENT 8

    Story-Telling Time - the /public

    You may wonder why there is a public, sharable storage with 100MB

    space only. As a matter of fact, there are historical reasons.

    In the late 90s, every undergraduate student was only given a UNIX

    personal account of5MB space only. Now, think about it: what if

    I need to process a data file of 5MB? What if I need to produce an

    output of 5MB? (Yes, there were such needs. In my data structure

    course, I was told to read in a 1MB file. I needed to build some datastructures over the data and I also needed to output it.)

    To solve such a problem, a publicly accessible, huge storage place is

    born. Nevertheless, people started to abuse such a place, e.g., sharing

    MP3, games, etc.

    FILE ONLY. Those who are interested can take a look inside and

    guess why it is so different from those you found using the web mailservice.

    /public. The way that we name is because of its location: in the

    workstations, the location of the 100MB-space is /public.

    The special thing about this storage is that everyone can share files

    there. Occasionally, you will find some good stuffs there. Of course, the

    /public directory will be cleaned up everyday.

    Your Responsibility.

    A user shall not store any materials with offensive content in

    his/her computer account and /public in Unix workstations,

    or any materials that infringe the laws regarding Copyright,

    Patent and Trademark.

  • 7/31/2019 Unix Talk 2010

    9/58

    1 UNIX AND OUR DEPARTMENT 9

    For other responsibilities, you are required to read the following page:

    http://wiki.cse.cuhk.edu.hk/tech/regulations/main

    1.1.1 Keep an eye on your quota

    Now, you know that you are only given limited resources. It is your respon-

    sibility to keep track on your disk usage. But, what if you have used up your

    disk quota?

    If you have used up your disk quota, you cannot add any new

    data/files into your account.

    Whats the big deal? You may ask. The problems are:

    You cannot save any work in-progress.

    You cannot compile any programs.

    Well, the above problems are good sources of strange bugs whileyou are working on your assignments.

    To monitor your quota in your UNIX personal account and /public,

    please invoke:

    quota -v

    The above command displays your current usage and the quota imposed.

    For the usage of your email storage, you need another way:

    du -k /var/mail/[your login name]

    The above command measures how many KBytes you have used to store

    the emails.

  • 7/31/2019 Unix Talk 2010

    10/58

    1 UNIX AND OUR DEPARTMENT 10

    1.2 Computing Facilities - UNIX-Like Workstations

    The lists of UNIX-like workstations are given as follows.

    Machine OS Hostname

    Sun Ultra Solaris 8 sparc1 - sparc30

    Linux Ubuntu 8.04 / 9.04 server linux1 - linux9

    Ubuntu 10.04 64-bit server linux10 - linux15

    Mac Mac OS X / Darwin mac1 - mac12

    There are two ways to go into the machines and both ways require yourUNIX credential.

    What is a credential?

    It means your identity and is usually presented as the (login

    ID, password) pair.

    1.2.1 Console login

    The phrase console login means you log in the workstation in front of the

    workstation. However, except the Mac workstations, you can hardly find a

    console in the laboratory; They are hidden by our system administrators.

    An analogy. You are doing the console login action in front of your

    Windows PC everyday.

    1.2.2 Remote login

    On contrary, remote login means that you log in the workstation from

    another workstation/PC (not in front of the target workstation). There are

    several forms of remote logins.

    Windows: remote desktop.

  • 7/31/2019 Unix Talk 2010

    11/58

    1 UNIX AND OUR DEPARTMENT 11

    How many user accounts do you have?

    Since the first day you entered our department, you had been

    given two accounts: the UNIX account and the Windows

    account.

    The two accounts are different although they have the same

    login name. In other words, when you changing the password

    of the Windows account, you are not changing the password

    of the UNIX account, and vice versa.

    The UNIX account governs many things:

    - access to workstations;

    - access to printers;

    - access to email service;

    - access to the department VPN service;

    - access to some course web pages;

    However, the Windows account only governs the access to

    Windows PC only.

    UNIX-like workstations: ssh and telnet (depreciated because

    it is not secure).

    In most of the cases, we will use a Windows PC to remotely log in

    a UNIX workstation using a SSH client program. All UNIX worksta-

    tions, Mac workstations, and Linux workstations support the SSH service.

    In the next section, we will show you how to do so.

  • 7/31/2019 Unix Talk 2010

    12/58

    1 UNIX AND OUR DEPARTMENT 12

    1.3 Network Services in Our Department

    For further information, please refer to the following link:

    https://www.cse.cuhk.edu.hk/corner/tech/guide/network.html

    Mainly, there are three network services you will be interested:

    Remote login using SSH,

    Web server, and

    Email.

    1.3.1 Walkthrough: SSH login from a Windows PC

    The word SSH is a abbreviation of the name Secure SHell and we usually

    use SSH as a verb. E.g., you cannot ssh to a Windows PC. Figure 3

    shows how to ssh from your home to a UNIX machine. We describe the

    steps involved in the following context.

    Installing the SSH client program.

    Sorry, on behalf of Uncle Bill, all versions of Windows do not

    have any SSH client program pre-installed.

    Dont worry. Our university has purchased the license of a SSH client pro-

    gram. Every Windows PC in our department has such a program installed.

    Nevertheless, if you are connecting from home, you will need the installation.

    For the details, please refer to the Appendix of this handout.

    SSH to the gateway first if you are outside CSE network

    If you are using a connection outside the CSE department, that means:

    Commercial ISPs, such as PCCW and HKBN;

  • 7/31/2019 Unix Talk 2010

    13/58

    1 UNIX AND OUR DEPARTMENT 13

    WindowsPC in home

    UnixWorkstation

    UnixWorkstationUnixWorkstations

    Mac PCsMac PCsMac PCs

    gateway

    (gw.cse)

    Internal

    Network

    Mac PCsMac PCsLinux

    PCs

    SSH to gw.cse.cuhk.edu.hk

    SSH to a workstationin the gateway

    WindowsPC in Lab

    SSH to a workstationdirectly.

    Figure 3: How and where to ssh?

    CUHK network service, including the ClassNet, the Resnet, the VPN,

    and the CUHK Wifi service;

    ERGWAVE Wifi service;

    then, you must go through the department gateway in order to remotely log

    in the workstations. In Figures 4-8, step-by-step guidelines will be given.

    Step 1, Figure 4. Launch the SSH program and click the Quick

  • 7/31/2019 Unix Talk 2010

    14/58

    1 UNIX AND OUR DEPARTMENT 14

    Story-Telling Time - the gateway

    Before 2000, all workstations and Windows PCs in our department

    were directly connected to the outside world. I used to remotely

    control a Windows PC in the lab using VNC from my home.

    Nevertheless, this measure gave a window to hackers and we did suffer

    from an attack. After such an attack, our department tightened our

    network. The gateways were installed since that attack.

    Connect button.

    Step 2, Figure 5. Type in the name of the department gateway and

    your login name.

    Step 3, Figure 6. Type in your UNIX password.

    Step 4, Figure 7. If everything is smooth, you will be inside the gateway

    machine. Else, you will be prompted to enter the password again. It isbecause you have typed either a wrong login name or a wrong password.

    Now, you are one step away from logging in the workstation. The next

    step is to type the following command:

    ssh sparc1

    The above command means that you want to ssh to the UNIX work-

    station sparc1. Next, you will be asked to enter your password. Yes,

    you have to type in the same UNIX password again.

    tywongsparc1s password:

    Step 5, Figure 8. Great! You are now inside the UNIX workstation

    sparc1. Congratulations!

  • 7/31/2019 Unix Talk 2010

    15/58

    1 UNIX AND OUR DEPARTMENT 15

    Figure 4: Step 1. Click the Quick Connect button.

    Figure 5: Step 2. Host Name = gw.cse.cuhk.edu.hk; User Name = your

    login name.

    Figure 6: Step 3. Remember, type your UNIX password, and it is case-

    sensitive.

  • 7/31/2019 Unix Talk 2010

    16/58

    1 UNIX AND OUR DEPARTMENT 16

    Figure 7: Step 4. Now, you are inside our department gateway.

    Figure 8: Step 5. Congratulations! You are in the UNIX workstation sparc1.

  • 7/31/2019 Unix Talk 2010

    17/58

    1 UNIX AND OUR DEPARTMENT 17

    SSH to the workstations directly if you are inside CSE network

    Then, the procedure becomes very easy: just skip the gateway.

    Step 1. Launch the SSH program and click the Quick Connect but-

    ton.

    Step 2. Type in the name of the workstation you want to reach, e.g.,

    sparc1 or mac1, together with your login name. Right, you can omit

    .cse.cuhk.edu.hk (and thanks for the work done by our administra-

    tors).

    Step 3. Type in your UNIX password.

    Step 4. Bingo! You are now inside the UNIX workstation.

    That is not the end of the SSH program, you can do many things:

    Use the UNIX environment with commands, and such an interface is

    called the command line interface, CLI for short.

    Use another feature of the SSH program to transfer files to and from

    your UNIX account. Figures 9 and Figure 10 have shown you how.

  • 7/31/2019 Unix Talk 2010

    18/58

    1 UNIX AND OUR DEPARTMENT 18

    Figure 9: You can launch the Secure File Transfer by clicking New File

    Transfer.

    Figure 10: Left Hand Side: your local disks. Right Hand Side: the home

    directory of your UNIX account.

  • 7/31/2019 Unix Talk 2010

    19/58

    1 UNIX AND OUR DEPARTMENT 19

    1.3.2 Web service: hosting your personal homepage

    To host your personal homepage, the following steps can help you.

    1. Create the directory www in your UNIX account.

    2. Mark the directory as readable by all people with the following

    command:

    chmod 711 www

    (We will say more about the chmod command later.)

    3. Then, create your homepage inside that directory.

    4. Last, you can view your homepage. E.g., if your login name were

    tywong, then the location of your homepage would be:

    http://www.cse.cuhk.edu.hk/~tywong/

    1.3.3 Email and email forwarding

    By the way, do you know that you have a department email address E.g., if

    your login name were tywong, then your email address would be:

    [email protected]

    A truth: most tutors and teachers try to contact you using your depart-

    ment email address only. Therefore, in order to guarantee you are not going

    to miss any emails from our department, our system administrator has setup an email forwarding service.

    The configuration file about this service is called .forward and it is pre-

    installed inside your home directory of your UNIX account. The .forward

    file is a plaintext file and an example content of the .forward is as follows.

  • 7/31/2019 Unix Talk 2010

    20/58

    1 UNIX AND OUR DEPARTMENT 20

    [email protected]

    The content specifies that every email sending to your department email

    address will be forwarded to the email address [email protected].

    Can I disable the email forwarding service?

    Sure. To disable the service, you just have to remove the .forward file.

    How Can I check the department emails?

    The simplest way is to use the web mail system in the following link:

    http://webmail.cse.cuhk.edu.hk/

    More advanced ways will be using the UNIX commands and we will show

    you later.

    1.4 A Short Summary

    This is not the end of the basics of the usage of UNIX in our department.

    For more details, you are welcome to visit the following site:

    http://www.cse.cuhk.edu.hk/corner/

    In the next chapter, we start introducing you the UNIX commands.

  • 7/31/2019 Unix Talk 2010

    21/58

    2 FILE PROCESSING 21

    2 File Processing

    In this section, we are going to introduce the most important thing in UNIX,that is File. File is everything in UNIX including directory, hard disks, and

    even printers.

    In the following text, we would like to introduce the processing of files and

    directories. Including creation, removal, moving and copying, as well as per-

    mission policy in files in UNIX system.

    2.1 File & Directory

    2.1.1 Create and Remove File

    - We can use the following methods to create files

    Using command touch

    touch is a command that can create empty files (an empty file

    is a file contains zero byte). If the file that is being touched

    already exists, it will only change the file access and modifi-cation times.

    To use touch:

    touch [filename]

    Using text editor

    Text Editor is a program that can save the text we type.

    - To remove files, we can use the command rm. To invoke:

    rm [filename]

    rm can remove every file. So please be careful:

    rm * can be dangerous !!!

  • 7/31/2019 Unix Talk 2010

    22/58

    2 FILE PROCESSING 22

    2.1.2 View Files Content

    In this subsection, we will talk about text file (or ASCII file).

    - Using Text Editor

    Text Editor not only can view a files content, it can also modify a

    files content.

    - Other than Text Editor

    cat can be used to display a files content (Not a pet like dog:). Toinvoke:

    cat [filename(s)]

    It can be used to concatenate several files into one.

    e.g. cat file1 file2 file3 > aLargeFile

    more is a useful tool to browse through a text file. It is much better

    than cat. cat will dump out all the content. But, more can fit

    the text file into pages. To invoke:

    more [filename]

    Below shows some simple command for more

    b page up

    f page down

    space page downenter go down a line

    / search

    q quit

    less is the opposite of more (just kidding!!). less is a similar tool as

    more. It supports more commands than more. To invoke:

  • 7/31/2019 Unix Talk 2010

    23/58

    2 FILE PROCESSING 23

    less [filename]

    Below shows some simple command for less

    b page up

    f page down

    q quit

    scroll up

    scroll down

    / searchg Go to the first line

    G Go to the last line

    ng Go to the nth line

    head can display the first N lines of a file. It can be adjusted to display

    1 to N lines. The following example display the first 5 lines of the

    file aFile.

    e.g. head -5 aFile

    tail is the opposite of head (This time is not a joke). It displays the

    last N lines of a file.

    e.g. tail -8 aFile

    2.1.3 Move and Copy Files

    - We can move a file from one place to another by using mv. We can

    also use mv to change a files name. To invoke mv (move):

    mv [source] [destination]

    e.g. mv 3150.cpp 3150/example.cpp

    This example moves 3150.cpp into the directory 3150

    and the file name is changed to example.cpp.

  • 7/31/2019 Unix Talk 2010

    24/58

    2 FILE PROCESSING 24

    e.g. mv 3150.cpp 3150/

    This example has the similar effect as the previous one, ex-

    cept that the file name is still 3150.cpp.

    e.g. mv 3150.cpp 3150.cpp.backup

    This example changes the filename 3150.cpp into 3150.cpp.backup.

    - We can copy a file to other places by using the command cp. To invoke

    cp (copy):

    cp [source] [destination]

    e.g. cp 3150.cpp 3150.cpp.backup

    This example copies a backup of 3150.cpp and names the

    new file as 3150.cpp.backup.

    e.g. cp 3150.cpp 3150/assg1/

    This example copies 3150.cpp into the directory 3150/assg1.

    e.g. cp -R 3150/ passed course/

    This example copies all the files inside 3150 including sub-

    directory into the directory passed course. The argument

    -R is needed if you want to copy all the sub-directories inside

    3150.

    2.1.4 File Type

    - In DOS/Windows, the type of file is usually determined by its file

    extension. But in UNIX, the file extension is useless (or not significant).

    - We have a very useful tool which can determine the file type easily. It

    is called file. To invoke file:

    file [filename]

  • 7/31/2019 Unix Talk 2010

    25/58

    2 FILE PROCESSING 25

    e.g. file hello.gif

    return: hello.gif: GIF file, v89

    - Remember, file extensions in UNIX is not so important. Therefore, we

    need the file command to help us in determining file types. E.g.,

    mv hello.gif hello.mp3

    file hello.mp3

    return: hello.mp3: GIF file, v89

  • 7/31/2019 Unix Talk 2010

    26/58

    2 FILE PROCESSING 26

    2.1.5 Create and Remove Directory

    Directory is an important file type in UNIX system. The above commands

    such as mv, cp, etc are also applicable since directory is also a file. However,

    its creation, removal as well as content are special.

    - We can create a directory by using mkdir. To invoke:

    mkdir [directory name]

    e.g. mkdir unixTalk

    This creates a directory called unixTalk.

    - We can remove a directory by 2 ways:

    1. By using rmdir. To invoke:

    rmdir [directory name]

    This command fails if the target directory contains files. In this

    case, we should choose the second method.

    2. By using rm -r. To invoke:

    rm -r [directory name]

    This command will ask for confirmation of the removal of all the

    files in the directory.

    2.1.6 Change Directory

    We can browse through the directory structure by a famous command. It is

    cd (stand for Change Directory). To invoke:

    cd [directory name]

  • 7/31/2019 Unix Talk 2010

    27/58

    2 FILE PROCESSING 27

    2.1.7 View Directorys Content

    As directory is also a file, we can read its content. However, directory is a

    special type of file, we need a special and famous command to read it. It is

    ls. To invoke:

    ls [argument] [directory or files]

    e.g. ls -l assignment

    This example will list the directory assignment in a long format.

    There are a lot of arguments for ls. Here, we describe some of

    them.

    -a List all entries including hidden files.

    -l List all entries in long format.

    -R List all files and sub-directories recursively.

    2.1.8 Special Directories

    We will describe 3 kinds of special directory: . (a dot), .. (two dots) and .

    Below shows a table of these special directory:

    . current directory

    .. parent directory

    home directory

    e.g. ls -l .

    This command lists all the entries in current directory.

    e.g. cd ..

    This command browses to the parent directory.

  • 7/31/2019 Unix Talk 2010

    28/58

    2 FILE PROCESSING 28

    e.g. cd

    This command browses to the home directory of the current user.

    e.g. cd tywong

    This command browses to the home directory of tywong.

  • 7/31/2019 Unix Talk 2010

    29/58

    2 FILE PROCESSING 29

    2.1.9 Redirection and Pipe

    - In UNIX, we have 3 special (or default) files. They are namely STDIN

    (standard input), STDOUT (standard output) and STDERR

    (standard error). The following is the description of these 3 files.

    STDIN It stands for the input of a program. Typically, the standard

    input is the keyboard.

    STDOUT It stands for the output of a program. Typically, the

    standard output is the screen.

    STDERR It stands for the output of the error message(s) of a pro-

    gram. Typically, the standard output is also the screen.

    - We summarize these with the below analogy.

    STDIN keyboard

    STDOUT monitor

    STDERR monitor

    - We can change the STDIN and STDOUT of a program by using redi-

    rection and pipe file

    1. Redirection

    We have 3 kinds of redirections: >, < and >>.

    The > symbol is used in this way:

    [program] > [file]

    The STDOUT of the program will be replaced by the targetfile. If the file already exists, we add a ! after >.

    e.g. ls -l >! output

    This command will create(or replace) the file with

    name output. The file output will contain the

    result of ls -l.

  • 7/31/2019 Unix Talk 2010

    30/58

    2 FILE PROCESSING 30

    The symbol >> is used in this way:

    [program] >> [file]

    This symbol is similar to >. However, instead of erasing all

    the data in file, >> appends the STDOUT to file.

    The Replace STDOUT and flush to a file

    >> Replace STDOUT and append to a file

    < Replace STDIN by reading content of a file

    2. Pipe File

    A pipe File is a symbol, |. The usage is:

    [program1] | [program2]

    It is a special file. It acts as a temporary storage to store the STD-

    OUT of program1. This storage will then serve as the STDIN of

    program2.

    e.g. ls -l | more

    The ls -l will give its STDOUT to the pipe. Then,

    more will read the pipe as its STDIN. The result of this

    example is to generate a page-separated directory con-

    tent.

  • 7/31/2019 Unix Talk 2010

    31/58

    2 FILE PROCESSING 31

    2.2 File Permission

    In this sub-section, we would like to discuss the permission policy of files in

    UNIX system.

    2.2.1 Read, Write, Execute Modes

    Below is a typical result of ls -l:

    -rw------- 1 tywong lec 11 Jan 1 00:00 test.c

    The first 9 character, i.e.

    -rw-------

    are the permission that is set to the file. If all the states are on, the permission

    will be:

    -rwxrwxrwx

    The first rwx stands for the permission for the owner of the file.

    The middle rwx stands for the permission for the group of the owner.

    The last rwx stands for the permission for other users.

    From the following example:

    -rw------- 1 tywong lec 11 Jan 1 00:00 test.c

    We know the following information about this file.

    Owner tywong

    Group lec

    Permission for User Read, Write

    Permission for Group No permission grantedPermission for Other No permission granted

    The rw- permission of user means that the user is allowed to Read and Write

    the file. However, he/she is not allowed to eXecute the file. The users of the

    same group and other users are not allowed to Read, Write or eXecute the file.

  • 7/31/2019 Unix Talk 2010

    32/58

    2 FILE PROCESSING 32

    2.2.2 Changing Modes

    UNIX system has a very useful command to change permission of a file. It

    is chmod (change mode). The format is:

    chmod [absolute modes] [filename], or

    chmod [symbolic-mode-list] [filename]

    1. Absolute Modes

    The absolute mode contains 3 numbers between 0 and 7. The cal-

    culation of the mode is carried out like this:

    For example, if we want to change to the following mode:

    rw- --- --- = 600 (absolute mode)

    We convert the permission into a 9 bits representation, i.e.

    rw- --- --- = 110 000 000

    Then, we group the bits 3 into 1 group, and convert it into a base 8

    number, i.e.

    rw- --- --- = 110 000 000 = 6 0 0

    The mode calculation is completed, and then we can type:

    chmod 600 test.c

    to change mode.

    e.g. rw- r-- r-- = 110 100 100 = 644

    e.g. rwx r-x r-x = 111 101 101 = 755

  • 7/31/2019 Unix Talk 2010

    33/58

    2 FILE PROCESSING 33

    2. Symbolic Mode

    This mode uses symbols for changing mode. For example, you want

    all people to view your photo. By absolute mode, you need to change

    mode to 644. But, using symbolic mode, it is like this:

    chmod a+r myPhoto.jpg

    a+r means that All(a) Add(+) Read(r) permission.

    Or, you have written a program and want to share with all your Y09classmates only. you can:

    chmod g+rx myProgram

    a+r means that Group(g) Add(+) Read(r) and eXecute(x)

    permission.

    The following table shows the symbols used in symbolic mode.

    r read permission

    w write permission

    x execute permission

    a all users

    u owner(user)

    g group

    o other

    + add permission(s)

    - remove permission(s)

    2.2.3 Remarks

    Directory should be EXECUTABLE if you want to cd to it.

    Directory should be READABLE if you want to ls it.

    Program must be EXECUTABLE.

  • 7/31/2019 Unix Talk 2010

    34/58

    3 PROCESS MANAGEMENT 34

    3 Process Management

    Process is another important component of UNIX system. Every programwhich is executing is a process (you will learn a more formal definition later).

    In this section, we are going to introduce the management of processes.

    3.1 Display Process Details

    Whenever a process is created in UNIX, an unique ID will be created for

    the process also. It is called Process ID (PID). We can locate a process by

    searching the program name as well as PID. The following text introducessome of the commands and tools.

    top

    top is a tool that displays information about the processes including

    PID. It is an interactive one and updates the cpu information periodi-

    cally.

    ps

    ps is also a tool that displays information about processes. But, it

    only shows the jobs that are running on the working terminal. How-

    ever, if you type the command like the following, you can get all the

    processes PID that belong to you in a single machine.

    ps -u [username]

    w

    w cannot shows the PIDs of running processes. However, it can display

    all current active jobs in the machine.

    3.2 Kill Process

    There are cases that process will not terminate even if you use Ctrl+C. One

    of the method is to switch the machine off. However, this is FORBIDDEN

  • 7/31/2019 Unix Talk 2010

    35/58

    3 PROCESS MANAGEMENT 35

    in our department as you will kill other peoples jobs also. UNIX is a nice

    system; it provides ways for you to kill those stubborn processes.

    kill

    kill sends signal to your target process in order to let it to rest in

    peace. The format is :

    kill [PID]

    If the process is so tough that it is still not being killed, try to add

    an argument -9 to kill.

    kill -9 [PID]

    top

    top has a option for users to kill processes. Here, we provide some

    options of top.

    k kill

    u list specific users job

    3.3 Foreground and Background Job

    There are cases that you are running a job which consume a long period

    of time (several hours) to finish. You have dated your boy/girl friend, you

    cannot wait for it to finish. However, if you logout your machine, the terms

    and jobs will be killed too!!!! What should you do??

    No panic!! Those ordinary jobs that you are running are called foreground

    jobs. UNIX has another type of job which is called background job. This

    kind of job can be run behind the login terminals.

  • 7/31/2019 Unix Talk 2010

    36/58

    3 PROCESS MANAGEMENT 36

    3.3.1 Create Background Job

    To create background job, there are 2 ways.

    Create a Background One

    To create a background job, just type & at the end of the command.

    e.g. /usr/local/bin/netscape4.7 &

    Change Foreground to Background

    1. Type Ctrl+Z in the terminal that the foreground job is running.

    2. The job is now changing to a suspended job.

    3. Type bg (Back-Ground) onto the terminal that the suspended job

    is on, a background job is created.

    3.4 Kill Background Job

    1. You can type fg in the terminal that you create background jobs. Then,

    you can press Ctrl+C to kill it. If the term does not exist, then

    2. You can use the methods introduced in the previous subsection.

  • 7/31/2019 Unix Talk 2010

    37/58

    4 PRINTING IN DEPARTMENT 37

    4 Printing in Department

    Our department has provided us 7 postscript laser printers and 2 dot matrix

    printers for us to use. Their locations are:

    Printer Name Location Type

    ps SHB924 Laser

    ps2 SHB924 Laser

    ps3 SHB904 Laser

    ps4 SHB122 Laser

    cps SHB122 Color Lasercps1 SHB924 Color Laser

    cps2 SHB924 Color Laser

    openlab SHB904 Dot Matrix (Plaintext only)

    declab SHB924 Dot Matrix (Plaintext only)

    4.1 Printing Files

    We can print files in UNIX with this command:

    lpr -P[printer name] [filename]

    This command can only print plain text files and postscript files (usually

    with extension .ps).

    4.2 Printing Queue

    As the printers are shared among several hundreds of classmates, we will

    need to queue up in order to get the printing service. Once you send the job

    to the printer, you can check the queue of the printer:

    lpq -P[printer name], or

    showprint

  • 7/31/2019 Unix Talk 2010

    38/58

    4 PRINTING IN DEPARTMENT 38

    4.3 Delete Print Job

    If your job is not processing (or printing), you can dequeue your job from

    the printer by:

    lprm -P[printer name] [Job ID] [username]

    4.4 Print Quota

    Printing in our Department costs money. Initially, each undergraduate has

    50 quotas. After each semester, 50 more quotas will be added. Each quota

    costs $0.30. Below show the charges for printing.

    ps (Duplex) 1 quota

    ps2 (Duplex or non-duplex) 1 quota

    ps3 (Duplex or non-duplex) 1 quota

    ps4 (Duplex) 1 quota

    cps 5 quota

    cps1 5 quotacps2 5 quota

    openlab free of charge

    declab free of charge

    To check how many quotas are still left, use this:

    printquota

  • 7/31/2019 Unix Talk 2010

    39/58

    5 UNIX TOOLS 39

    5 UNIX Tools

    In this section, we introduce some useful tools in UNIX.

    5.1 Internal Communication

    This category of tools is for communicating with people within the same

    network.

    5.1.1 talk

    This tool allows 2 people to chat with each other. But, it only allows 2

    people.

    talk [username]

    5.1.2 write

    This tool allows an user to send message to other users.

    write [username] [terminal]

    5.1.3 finger

    It is not a communicating one, but it allows users to see other users infor-

    mation

    finger [username]

    e.g. finger tywong

    Login name: tywong In real life: Wong Tsz Yeung

    Directory: /uac/lec/tywong Shell: /bin/tcsh

    On since Jan 4 00:23:02 on pts/1 from 137.189.90.237

    Unread mail since Sun Jan 3 23:53:43 2010

    Plan:

    I teach OS.

  • 7/31/2019 Unix Talk 2010

    40/58

    5 UNIX TOOLS 40

    5.2 Password and Personal Details

    5.2.1 passwd & yppasswd

    You can change your UNIX password by using passwd. In our department,

    passwd and yppasswd are the same program. To invoke:

    passwd or yppasswd

    5.2.2 chfn

    You can change your finger information by using chfn. To invoke:

    chfn

    The above programs need your current UNIX password in order to change

    your personal informations.

    5.3 Text Editor

    Text editor is an important tools. It enables us to compose a text file such as

    email, programs, etc. There are a lot of text editors in UNIX. We introduce

    two useful text editors.

    5.3.1 VI and VI IMproved

    VI is nearly the most powerful text editor in UNIX system, and Vi IM-

    proved (VIM) is the VI-enhanced version. VI has 2 modes, one is Com-

    mand Mode and another one is Edit Mode. The detailed commands will

    be shown in the appendix. To invoke VI or VIM:

    vi [filename] or vim [filename]

    where the filename can be omitted.

    5.3.2 PICO

    PICO is a less powerful text editor than VI or VIM. However, it is easy to

    use and has a lot of useful commands. The detailed commands will be shown

    in the appendix. To invoke PICO:

  • 7/31/2019 Unix Talk 2010

    41/58

    5 UNIX TOOLS 41

    pico [filename]

    where the filename can be omitted.

    5.4 Internet

    This section introduces a lot of tools that are related to the Internet.

    5.4.1 SFTP

    SFTP stands for Secure File Transfer Protocol. The tool allows you to

    login to the target host, and can download or upload files from that host.To invoke sftp:

    sftp [hostname or IP address]

    Below shows some commands of sftp

    bye close connection

    cd [pathname] change the directory in the remote host

    lcd [pathname] change the directory in the local hostget [filename] download one file

    mget [filename(s)] download multiple files

    put [filename] upload one file

    mput [filename(s)] upload multiple files

    ls list file entries in hosts

    prompt turn prompting off

    5.4.2 PINE and ELM

    PINE and ELM are mail reader and composer. You can read and reply

    your email in these 2 programs.

    PINE is a program for Internet News and Email. It is a more convenient

    Email program. It supports attachment also. To invoke PINE:

    pine

  • 7/31/2019 Unix Talk 2010

    42/58

    5 UNIX TOOLS 42

    ELM is a not as user-friendly as PINE. However, it supports command line

    to send mail. To invoke ELM:

    elm [arguments] [email address]

    Notes: you can omit arguments and email address

    e.g. elm -s "Just to Say HI" [email protected]

    This will send an email to [email protected] with a subject

    Just to Say HI.

    5.4.3 TIN

    It is an Internet News program. It allows you to read, reply and subscribe

    to newsgroups. To invoke tin:

    tin

    Below shows some commands of tin.

    y Browse groups on server or Browse subscribed groups

    s subscribe group

    u unsubscribe group

    w post a news (or thread)

    f followup in a thread

    go down one level in the newsgroup

    go up one level in the newsgroup

    scroll up

    scroll down

    5.4.4 LYNX

    It is a famous text mode web program. It allows you to surf the Internet,

    but not Javascript support. To invoke lynx:

    lynx [hyperlink]

  • 7/31/2019 Unix Talk 2010

    43/58

    5 UNIX TOOLS 43

    5.4.5 WGET

    It is a very handy tool that allows you to download stuffs with hyperlinks.

    It also provides some great features, such as downloading from a list of hy-

    perlinks and recursively downloading a web site.

    wget [hyperlink]

    e.g. wget http://www.cse.cuhk.edu.hk/index.html

    This command downloads the file index.html from our depart-ment.

    e.g. wget -i list.txt

    This command instructs wget to download from the list of

    URLs stored in list.txt.

    e.g. wget -l 2 -R http://www.cse.cuhk.edu.hk/

    This command instructs wget to start downloading recursivelyfrom our department homepage, with a maximum depth of 2 lev-

    els.

    5.5 Compression and Archives

    There are a lot of compression tools in UNIX. We introduce some popular

    ones.

    5.5.1 ZIP, UnZip and Zipinfo

    ZIP is very popular in Windows. The UNIX Zip is compatible with the zip

    program in Windows environment. To use Zip:

    zip [destination file (zip file)] [file(s) to compress]

    unzip [destination file (zip file)]

  • 7/31/2019 Unix Talk 2010

    44/58

    5 UNIX TOOLS 44

    If you want to compress directory, then you need to argument -r.

    zip -r [destination file (zip file)] [directory(s) to compress]

    zipinfo is to view the content of a zip file. To invoke :

    zipinfo [zip file]

    5.5.2 GZIP

    GZIP is another compression tools in UNIX. To use GZip:gzip [filename]

    gunzip [filename]

    e.g. gzip hello.cpp

    A compressed file hello.cpp.gz will be created and hello.cpp will

    be deleted.

    5.5.3 Tar and GNU Tar

    Tar is not a compression tool, instead it is a tool to create an archive. An

    archive stands for a package of files. To use Tar or GNU Tar (gtar):

    tar -[arguments] [tar file] [filename(s)]

    gtar -[arguments] [tar file] [filename(s)]

    Below shows some arguments for tar and gtar.

    c Create tar file

    t View a tar files content

    x Extract a tar files content

    f Specify the name of a tar file

    v View the name of each file being processed by tar

    z Use Gzip in Creating and Extracting tar file

  • 7/31/2019 Unix Talk 2010

    45/58

    5 UNIX TOOLS 45

    e.g. tar -cf abc.tar test.cpp test.html test.c

    This command will create a tar file abc.tar. The tar file contains

    test.cpp, text.html and test.c.

    e.g tar -tf abc.tar

    This command will list the files contained in abc.tar.

    e.g. tar -xf abc.tar

    This command will extract the abc.tar.

    e.g. gtar -czf abc.tar.gz test.cpp test.html test.c

    This command will create a gzipped tar file named abc.tar.gz.

    e.g. gtar -xzf abc.tar.gz

    This command will extract the abc.tar.gz.

    5.6 Image Manipulation

    In this section, we introduce some image manipulation tools in UNIX.

    5.6.1 XV

    XV allows your to view, crop and print your images. It supports a lot of

    image format such as JPEG, GIF, TIFF, BMP, etc. To invoke XV:

    xv [image filename]

    where the image filename can be omitted.

    5.6.2 GIMP

    GIMP stands for GNU Image Manipulation Program. Or, it is the UNIX

    PhotoShop. It has the similar power as PhotoShop in Windows. To invoke

    GIMP:

  • 7/31/2019 Unix Talk 2010

    46/58

    5 UNIX TOOLS 46

    gimp [image filename]

    where the image filename can be omitted.

    5.7 Document

    In this section, we introduce a few document viewers and composers in UNIX.

    5.7.1 GV and GhostView

    GV and Ghostview are used to view PostScript files (usually with exten-sion .ps). To invoke:

    gv [filename]

    ghostview [filename]

    where the filename can be omitted.

    5.7.2 ACROREAD

    AcroRead is the AcroBat Reader. It is capable of opening PDF file. To

    invoke it:

    acroread [filename]

    The filename can be omitted.

    5.7.3 StarOffice

    StarOffice is a office suite implemented in JAVA. It can open nearly all kindsof MicroSoft Office files. The setup of StarOffice is a little bit troublesome.

    For reference, please go to:

    http://www.cse.cuhk.edu.hk/corner/tech/doc/ht/typeset/#soffice

  • 7/31/2019 Unix Talk 2010

    47/58

    5 UNIX TOOLS 47

    5.8 Dictionary

    We have a dictionary installed in our UNIX system, the webster. To invoke:

    webster [word]

    The word can be omitted.

    5.9 Manual Page

    Last but not least, we introduce you the manual page in UNIX. To invoke:

    man [program name]

    e.g. man ls

    The manual page (or man page) of ls will be shown.

  • 7/31/2019 Unix Talk 2010

    48/58

    A Installing the SSH Client Program

    Step 1. Go to ITSC homepage:

    http://www.cuhk.edu.hk/itsc/index-en.html

    Then, select the option as shown in Figure 11.

    Figure 11: Step 1. Go to ITSC homepage and select the Useful Tools and

    Links.

    Step 2. Select SSH as shown in Figure 12.

    Step 3. After some nexts and agrees, you will reach the page shown

    in Figure 13. Download the first two exe files. The first exe file isthe primary installer. Please install it first. The second exe file is the

    update. Please install it after the first one.

    48

  • 7/31/2019 Unix Talk 2010

    49/58

    Figure 12: Step 2. Select the Secure Remote Access with SSH.

    Figure 13: Step 3. Download two exe files.

    49

  • 7/31/2019 Unix Talk 2010

    50/58

    B SHELL command

    This following commands are applicable in bash and tcsh.

    Ctrl + b move to left by 1 character

    Ctrl + f move to right by 1 character

    Ctrl + a move to the beginning of a line

    Ctrl + e move to the end of a line

    Ctrl + u cut and copy all the characters on the left of the cursor

    Ctrl + k cut and copy all the characters on the right of the cursor

    Ctrl + y paste the copied characters on the right of the cursor

    Ctrl + d delete the character at the cursor position

    Ctrl + h backspace

    Ctrl + s Scroll lock (lock keyboard)

    Ctrl + q Unlock scroll lock

    Ctrl + l Clear Screen

    history show all the commands previously invoked

    jobs show all the jobs running or suspendedtab auto completion

    50

  • 7/31/2019 Unix Talk 2010

    51/58

    C VI command

    Cursor movement Commands

    ------------------------

    j - down 1 line

    k - up 1 line

    h - left 1 char

    l - right 1 char

    ^f - forward 1 screen

    ^b - backward 1 screen

    ^u - up half screen

    ^d - down half screen

    H - top (Head line) of screen

    L - bottom (Last line) of screen

    ^y - scroll down 1 line at top of screen (cursor not move)

    ^e - scroll up 1 line at bottom of screen (cursor not move)

    0 - (zero) - first char of current line

    $ - last char of current line

    w - move to start of next wordW - move to start of next WORD (white-space delimited)

    e - move to end of word

    E - move to end of WORD

    b - move back to previous word

    B - move back to previous WORD

    f - find char c in current line in forward direction

    F - find char c in current line in backward direction

    ; - repeat last Find in same direction

    , - repeat last Find in opposite direction

    % - find matching () [] {}

    m - mark current line -- can be a to z

    - goto line with mark

    G - goto last line of file

    1G - goto 1-st line of file

    123G - goto line number 123

    51

  • 7/31/2019 Unix Talk 2010

    52/58

    Insert Commands (insert mode terminated by )

    ---------------

    a - append after curser

    i - insert before cursor

    A - Append after end of line

    I - Insert before 1st non-white space

    o - open an empty line after current line for insert

    O - Open an empty line before current line for insert

    Other Commands (replace/change-command terminated by )

    --------------

    r - replace current character by char

    R - replace characters until pressed

    s - substitute current char until pressed

    S - substitute current line until pressed

    cw - change up to end of word until pressed

    cW - change up to end of WORD until pressed

    dw - delete word

    dW - delete WORD

    dd - delete line

    yw - yank (store into buffer) 1 word

    yy - yank (store into buffer) 1 line

    Y - yank (store into buffer) 1 line

    p - put buffer content after current position

    P - put buffer content before current position

    [c|d|y]t - change/delete/yank up To char u - undo last command

    U - ignore all changes in line since cursor moves into

    current line

    . - repeat last editing command

    NOTE:

    ----

    52

  • 7/31/2019 Unix Talk 2010

    53/58

    (1) All above commands can be preceded by a number,

    which indicates number of repetition.

    E.g. 100G go to line number 100

    2dd delete 2 lines

    3yW yank 3 WORDS

    (2) There are 10 unnamed buffers: "1 to "9

    and 26 named buffers: "a to "z

    Deleted lines are stored in to "1 to "9 as a stack implicitly.

    Line/word/WORD(s) can be deleted/yanked into "a to "z explicitly.E.g. "a3Y yank 3 lines into "a

    "bP put content of "b before current cursor position

    EX line editing commands

    ------------------------

    :q - quit

    :q! - quit - no change of the file being edited

    :w - write out the file being edited

    :w! - overwrite the file being edited

    :w fileName - write new file with name "fileName"

    :w! fileName - overwrite the file "fileName"

    :r fileName - read "fileName" in after current line

    :e fileName - edit another file "fileName"

    :vi fileName - edit another file "fileName" (same as above)

    :e! fileName - edit another file - ignore change in current file

    :!vi fileName - fork another process to edit another file "fileName"

    :1 - goto 1-st line of file

    :$ - goto last line of file

    :1,$/pattern1/p - search for "pattern1" in file

    globally & print it

    :g/pattern1/p - search for "pattern1" in file

    globally & print it

    :g/pattern1/s//pattern3/ - search globally,

    53

  • 7/31/2019 Unix Talk 2010

    54/58

    replace first occurrence of "pattern1"

    in ALL lines by "pattern3"

    :g/pattern1/s//pattern3/g - search globally,

    replace ALL occurrences of "pattern1"

    in ALL lines by "pattern3"

    :g/pattern1/s/pattern2/pattern3/g

    - search globally,

    in those lines with "pattern1",

    replace ALL occurrences of "pattern2"

    by "pattern3":set nu - set NUmbering

    :set nonu - set NO NUmbering

    :set ai - set auto-indent

    :set ts=4 - set Tab-Stop = multiple of 4 char positions

    54

  • 7/31/2019 Unix Talk 2010

    55/58

    D Pico Command

    Curser Movement

    ===============

    ^F move forward a character

    ^B move backwad a character

    ^P move to the Previous line.

    ^N move to the Next line.

    ^A move to the beginning of the current line.

    ^E move to the End of the current line.

    ^V move forward a page of text.

    ^Y move backward a page of text.

    ^W Search for (where is) text, neglecting case.

    Note: After ^W, press ^T to search for the line

    ^L Refresh the display.

    Delete, Copy and Paste

    ======================

    ^D Delete the character at the cursor position.^^ Mark cursor position as beginning of selected text.

    Note: Setting mark when already set unselects text.

    ^K Cut selected text (displayed in inverse characters)

    Note: The selected texts boundary on the cursor side

    ends at the left edge of the cursor. So, with

    selected text to the left of the cursor, the

    character under the cursor is not selected.

    Or, cut the currrent line.

    ^U Uncut (paste) last cut text inserting it at the current cursor

    position.

    Other Command

    =============

    ^I Insert a tab at the current cursor position.

    ^J Format (justify) the current paragraph.

    55

  • 7/31/2019 Unix Talk 2010

    56/58

    Note: paragraphs delimited by blank lines or indentation.

    ^T To invoke the spelling checker

    ^C Report current cursor position

    ^R Insert an external file at the current cursor position.

    ^O Output the current buffer to a file, saving it.

    ^X Exit pico, saving buffer.

    ^G Display Help

    56

  • 7/31/2019 Unix Talk 2010

    57/58

    Index, 29

    >>, 30

    , 27

    ., 27

    .., 27

    .forward, 19

    acroread, 46

    background job, 35

    bg, 36

    cat, 22

    cd, 26

    chfn, 40

    chmod, 32

    Absolute mode, 32

    Symbolic mode, 32

    cp, 24

    credential, 10

    du -k, 9

    elm, 41

    email forwarding, 19

    fg, 36

    file, 24

    finger, 39

    foreground job, 35

    ghostview, 46

    gimp, 45

    gtar, 44

    gunzip, 44

    gv, 46

    gzip, 44

    head, 23

    kill, 35

    less, 22Linux, 5

    lpq, 37

    lpr, 37

    lprm, 38

    ls, 27

    lynx, 42

    Mac, 5

    man, 47mkdir, 26

    more, 22

    mv, 23

    passwd, 40

    pico, 40

    pine, 41

    printquota, 38

    ps, 34

    quota -v, 9

    rm, 21

    rm -r (directory), 26

    rmdir, 26

    Secure shell, 12

    57

  • 7/31/2019 Unix Talk 2010

    58/58

    sftp, 41

    SSH, 12

    staroffice, 46

    STDERR, 29

    STDIN, 29

    STDOUT, 29

    tail, 23

    talk, 39

    tar, 44

    tin, 42

    top, 34, 35

    touch, 21

    UNIX, 5

    UNIX account, 11

    UNIX personal account, 6

    unzip, 43

    vi, 40vim, 40

    w, 34

    webster, 47

    wget, 43

    Windows account, 11

    Windows profile, 6

    write, 39

    xv, 45

    yppasswd, 40

    zip, 43

    zipinfo, 43