Introduction to UNIX

zhaozj2021-02-16  170

Title: Unix Introduction

Introduction to UNIX

Login workstation

==========

.. Login workstation through the PC

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

Perform format: Telnet Hostname (executed under DOS)

Telnet IP-Address

EXAMPLE:

Telnet Doc Telnet 140.122.77.120

The workstation available in the current system is as follows:

Pacific atlantic atlantic

Indian Graph1 DOC Happy Grumpy Sneezy BashFule Dopey Ice

Note: IP_ADDRESS can be queried using instruction ARP HOSTNAME or ARP DOMAIN_NAME

.. Login steps

=========

Login: _______ => Enter username

Password: _______ => Enter a password

.. Logout steps

=========

% logout

Or% exit

Or%

Change account password

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

% YPASSWD => The following message will appear after the execution

CHANGING NIS Password for User On Ice.

Old Password: ______ => Enter the old password

New password: ______ => Enter a new password (preferably 6-8 words, English letters and digital mixing)

Retype new password: ______ => Enter a password

Online instruction description

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

Perform format: man command-name

EXAMPLE:% MAN LS

Enter a remote computer system

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

Perform format: rlogin hostname [-1 username]

EXAMPLE:

% rlogin doc

Remote login enters the workstation DOC.

% rlogin doc -l user

Use the USER account to enter the workstation DOC.

Perform format: Telnet Hostname or Telnet IP Address

EXAMPLE:

% Telnet Doc OR% Telnet 140.109.20.251

Archive or directory processing

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

. List the file names in the file or directory

Perform format: ls [-tflgr] [name] (Name) (Name can be a file name or directory name.)

EXAMPLE:

Ls lists the names in the current directory.

LS -A lists the included. Started hidden files all file names. Ls -t is sequenced in accordance with the order in which the file is finally modified.

LS -F lists the file names and their types in the current directory. "/" The end is expressed as a directory name,

"*" Is indicated as an execution file, and "@" is indicated as Symblic Link.

LS -L lists the permissions, owners, file sizes, modifications, and names of all files in the directory.

Ls -lg is the same as above, and display the owner group name of the file.

Ls -r displays the name of the directory and all its subdirectories. (Recursive Listing)

Directory Abbreviation:

===========

~ Working Directory at the user login (starting directory)

~ Username Specifies a USER's Working Directory (starting directory)

.. current work directory (Current Working Directory)

.. Parent of Working Directory (Parent of Working Directory)

Change the location of the catalog

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

Perform format: CD [Name]: Name can be abbreviated for directory name, path, or directory.

EXAMPLE:

The CD changes the directory location to the Working Directory (starting directory) when the user login.

CD DIR1 changes the directory location to the directory location of DIR1.

CD ~ User changes the directory location to the user's Working Directory.

Cd .. Change the directory location, to the upper layer of the current directory (ie, Parent of Working Directory)

CD ../user changes the directory location to the location where the relative path User is located.

CD /../ .. Change the directory location to the directory location of the absolute path (Full Path).

Copy file

=========

Perform format: CP [-r] Source Destination

EXAMPLE:

CP file1 file2 copies file file1 into file2

CP file1 Dir1 copies the file file1 to the directory DIR1, the file is still file1.

CP / TMP / FILE1. Copy file file1 under directory / TMP to the current directory, and the file is still file1.

CP / TMP / FILE1 FILE2 Copy file file1 under directory / TMP to the current directory, file name is file2 □

CP -R DIR1 DIR2 (Recursive Copy) Copy the entire directory.

If the directory DIR2 does not exist, copy the directory DIR1, and all its files and subdirectories,

Under the directory DIR2, the new directory name is DIR1. If the directory DIR2 does not exist,

DIR1, and all its files and subdites, copy as directory DIR2.

Move or change files, directory name

======================== Performed format: MV Source Destination

EXAMPLE:

MV file1 file2 converts file file1 to file2.

MV file1 DIR1 moves file file1 to the directory DIR1, and the file name is still FILE1.

MV DIR1 DIR2 If the directory DIR2 does not exist, the directory DIR1, and all its files and subdirector are moved.

Under the directory DIR2, the new directory name is DIR1. If the directory DIR2 does not exist,

DIR1, and all its files and subdirectors, change to directory DIR2.

Establish a new directory

==========

Perform format: MKDir Directory-name

Exmaple:

MKDir Dir1 establishes a new directory DIR1.

Delete directory

=========

Perform format: RMDir Directory-Name or RM Directory-Name

EXAMPLE:

RMDir Dir1 deletes directory DIR1, but there is no file in Dir1, otherwise it cannot be deleted.

RM -R DIR1 Removes Directory DIR1, and all files and subdirectories.

Delete file

=========

Perform format: RM FileName (filename can be file name, or file abbreviation symbol.)

EXAMPLE:

RM file1 deletes files filed as file1.

RM file? There are five characters in the deletion file, the first four vollands are all files.

RM f * deletes all files named in F as a file.

Davidation symbol

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

• A single-word element representing the file name.

* Represents one of the strings in the file name.

List the current directory location

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

Perform format: PWD

View file content

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

Perform format: Cat FileName

EXAMPLE:

Cat file1 is displayed in a continuous display, view the contents of the file name File1.

Perform format: more filename or cat filename | More

EXAMPLE:

More file1 View the contents of the file name File1 in paging mode.

Cat file1 | more.

View the catalog The disk capacity

==================== Perform format: du [-s] Directory

EXAMPLE:

DU DIR1 Displays the total capacity of the directory DIR1 and the capacity of their second directory (with K byte).

DU -S DIR1 displays the total capacity of the directory DIR1.

View your own Disk quota usage

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

Disk quota: The use limit of the workstation disk space.

Perform format: quota -v

EXAMPLE:

Quota -v will display the following message

Filesystem usage quota limit timeleft files quota limit timelef.

/ Home / Ice / U01

9344 8192 12288 1.9 Days 160 0 0

The column commentary:

USAGE: The current disk is used.

Quota: Your disk usage quota. Although you can continue to use when your usage exceeds Quota,

It is necessary to drop to Quota within seven days, otherwise there is no ultra LIMIT (the highest limit) even if the amount is used.

Write or copy any files again.

Limit: The maximum use quota. When your USAGE reaches Limit, no file cannot be written or replicated.

Archive transmission

=========

. Copy file or directory to the remote workstation

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

Perform format: RCP [-r] Source Hostnome: Destination

(Source can be file name, directory name, or path, hostnome is the workstation station name, Destination is the path name.

EXAMPLE:

RCP file1 doc: / home / user

Copy the file file1 to the DOC Path / Home / User Directory.

RCP -R DIR1 DOC: / HOME / User

Copy the directory DIR1 to the workstation DOC path / home / user directory.

. Self-ended workstation, copy file or directory

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

Perform format: RCP [-r] hostname: Source Destination

(Hostname is the workstation name, Source is the path name, the Destination can be the file name, directory name or path).

EXAMPLE:

RCP doc: / home / file1 file2

In the workstation DOC, click on the directory DIR1 of the / home / user directory, copy it to the current workstation directory, the directory name is still DIR1.

RCP -R DOC: / HOME / USER / DIR1.

In the IIS1 in the / home / user directory, copy it to the current workstation directory.

The directory name is still DIR1.

. File transfer between local workstations and remote workstations

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

(You must have the account number and password of the remote workstation to transfer the transfer)

Perform format: FTP Hostname or FTP IP_Address

EXAMPLE:

FTP DOC and remote workstation DOC for file transfer

Name (DOC: User-name): Enter an account

Password (DOC: user-name): Enter a password

FTP> HELP lists any commands that FTP files are transmitted.

FTP>! Ls lists the local workstation and all files under the current directory.

FTP>! PWD lists the local workstation and the current work directory location.

FTP> Ls list all the files under the current directory of the remote workstation.

FTP> DIR lists all files (slightly unix LS -L instructions) under the current directory of remote workstation.

FTP> Dir. | More, but will be paused per page (FTP may not apply to Unix).

FTP> PWD lists the current directory locations currently in the remote workstation.

FTP> CD DIR1 Changes the working directory location of the remote workstation to DIR1.

FTP> GET File1 Copy the file file of the remote workstation to the local workstation.

FTP> PUT file2 will copy the file file of the local workstation to the remote workstation.

FTP> MGET * .C The remote workstation, the deployment of the reputation is all the files, copies to the local workstation.

FTP> MPUT * .TXT In the local workstation, the secondary file is named TXT, copy the remote workstation.

FTP> PROMPT Switch Talking Directive (Do not use each file when using MPUT / MGET asking YES / NO).

FTP> quit ends FTP work.

FTP> BYE ends FTP work.

Note: The file transfer from the PC and the workstation can also be filed through the FTP instruction of the PC side, the instruction usage is

The above is approximately the same.

Setting of archive mode

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

. Change the permission of the file or directory reading, write, execute

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

Perform format: chmod [-r] mode name (Name can be a file name or directory name; Mode can be 3 8-bit numerals, or using the ls -l command, list

Read, write, write, and perform a text abbreviation. )

Mode: RWX RWX RWX R: Read W: Write X: Execute

User group Other

Abbreviation: (U) (G) (O)

EXAMPLE:

% Chmod 755 Dir1

The directory DIR1 is set to any user, all have the right to read and execute, but only the owner can make changes.

% chmod 700 file1

Set file file1, setting only owners can read, write, and execute.

% CHMOD O X File2

Put file file2, increase the rights of the owner to perform.

% CHMOD G X File3

Increase the file file3 to increase the rights of the group user.

% Chmod O-R File4

Remove the file file4 to remove other users to read.

. Change the ownership of the file or directory

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

Perform format: chown [-r] username name (Name can be a file name or directory name.)

EXAMPLE:

% Chown User File1

Change the owner of the file file1 to the user.

% Chown -R User Dir1

Change the directory DIR1, and all the ownership of all files and subdirectories, all of the user User.

Check the name of the group you belong to

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

Perform format: groups

. Change the group ownership of the file or directory

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

Perform format: chgrp [-r] groupname name (Name can be a file name or directory name)

EXAMPLE:

% chgrp vlsi file1

Change the population of file file1 and change to the VLSI group.

% chgrp -r image dir1

Call directory DIR1, and all files and subdites under them are changed to the Image group.

. Change the final modification time of the file or directory

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

Perform format: Touch Name (Name can be a file or directory name.)

Connection

==========

With the same file, you can have more than one name to make a number of files.

Perform format: ln oldname new_AMPLLE (HARD LINK) EXAMPLE:

Ln file1 file2 will be the name file2 to the file file1.

Perform format: ln -s oldname newname (Symblick Link)

EXAMPLE:

Ln -s file3 file4 will connect the name file4 to the file file3.

Archive string

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

Perform format: GREP STRING FILE

EXAMPLE:

GREP ABC FILE1

Look for file file1, list the entire text content of the string ABC.

Find files or orders

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

Perform format: Whereis command (displays the path of the command.)

Perform format: Which command (the path to the command, and the alias defined by the user.)

Perform format: Whats Command (Display Command Features Summary.)

Perform format: Find search-path -name filename -print

(Search for the specified path, the path of a file.)

EXAMPLE:

% FIND / -NAME FILE1 -PRINT (Since the root directory, find the path to file1..

Compare files or contents of directory

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

Perform format: DIFF [-r] name1 name2 (Name1 Name2 can be mataly named, or directory name.)

EXAMPLE:

% DIFF file1 file2

The comparison files File1 are different from the file2, and each line is different.

% DIFF -R Dir1 Dir2

The comparison directory DIR1 and DIR2 are different from DIR2.

Archive list output

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

Users can use the setENV PRINTER in the .login file to set the list of lists when the print data is set.

Printername: SP1 or SP2 (1005 classroom)

EXAMPLE:

% STENV PRINTER SP2 sets from SP2 print data.

Printing of general archives

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

Perform format: lpr [-pprinter-name] filename

% lpr file1 or lpr -psp2 file1

Since SP2, the print file file1.

Perform format: EnScript [-pprinter-name] FileName

% ENSCRIPT FILE3 or ENScript -psp1 file3

Since the SP1 print file file3.

. Troff Print

================== Performed format: Ptroff [-pprinter-name] [-man] [- ms] filename

% ptroff -man /usr/local/man/man1/ptroff.1

In Troff format, the instructions for use from Apple Laser Writer Print Ptroff Commands.

% Ptroff -PSP2-Man / USR / MAN / Man1 / LPR1

In Troff format, the instructions for use from the SP2 list LPR command.

List machine control command

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

. Check the list of lists, and print job sequence numbers and user names

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

Perform format: lpq [-pprinter -name]

% LPQ or LPQ -PSP1

Check the status of the SP1 list machine.

. Delete the print job in the list machine (users can only delete their own printing work)

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

Perform format: lprm [-pprinter -name] UserName or Job Number

% LPRM User or LPRM -PSP1 User

Delete SP1, the user user's printing work, at which time the user name must be User.

% lprm -psp2 456

Delete the SP2 number 456 print job.

JOB control

===========

Unix O.S., can handle multiple processs simultaneously in Foregrourd and Background.

When the general user executes the command, it is performed in Foreground, and Process can also be processed.

Placed in Background, perform Process in non-talk.

. View Systems Process

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

Perform format: PS [-aux]

EXAMPLE:

% PS or PS -X (view the system, belonging to your own process.)

% PS -AU (view the system, all users' process.)

% PS -AUX (view the system, including the internal, and all users of all users)

. End or terminate Process

==================== Perform format: kill [-9] PID (PID is the process ID used by the PS command.)

EXAMPLE:

% KILL 456 or KILL -9 456

Terminate the Process ID of 456 Process.

. How to perform Process on Background

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

Perform format: Command & (join a "&" symbol after Command.)

EXAMPLE:

% cc file1.c &

The work of the file1.c file will be compiled and placed in Background.

Perform format: Press the "Control Z" button to pause the processs being executed. Type the "BG" command,

Command, the paused process is placed in Background.

EXAMPLE:

% cc file2.c

^ Z

STOPPED

% BG

. View processs that are executing in Background

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

Perform format: Jobs

. End or terminate Process in Background

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

Perform format: kill% n

(N is the BACKGROUND JOB number that uses the "jobs" command.

EXAMPLE:

% kill% terminates the first Job in Background.

% KILL% 2 terminates the second Job in Background.

Shell Varialbe

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

. View the set value of Shell Variable

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

Perform format: Set to view all the set values ​​of all shell variable.

% set

Perform format: Echo $ Variable-name Displays the set value of the specified shell variable. % Echo $ PRINTER

SP1

. Set Shell Variable

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

Perform format: SET VAR = Value

EXAMPLE:

% Set Term = VT100

Set Shell Variable "Term" is the type of VT100 terminal.

. Delete Shell Variable

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

Perform format: unset var

EXAMPLE:

% unset printer

Delete the set value of the Shell Variable "Printer".

Environment Variable, ENVIRONMENT Variable

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

. View Environment Variable Settings

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

Perform format: STENV View all Environment Variable settings.

EXAMPLE:% SetENV

Perform format: Echo $ Name Displays the specified Environment Variable "Name" setting value.

EXAMPLE:

% Echo $ PRINTER

The set value of the Environment Variable "Printer" list machine name is displayed.

. Set Environment Variable

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

Perform format: STENV Name Word

EXAMPLE:

% SetENV Printer SP1

Set the Environment Variable "Printer" list machine name is SP1.

. Delete Environment Variable

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

Perform format: unstenv name

EXAMPLE:

% unstenv printer

Delete the set value of the Environment Variable "Printer" list machine name.

Alias

=====

. View the alias =======================================================================================================================================================================

Perform format: Alias ​​View all commands you currently define, and the corresponding Alias ​​name.

Perform format: Alias ​​Name View commands defined by the specified Alias ​​name.

EXAMPLE:

% Alias ​​Dir (see the command defined by alias DIR)

ls -atl

. Define the alias

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

Perform format: Alias ​​Name 'Command Line'

EXAMPLE:

% Alias ​​Dir 'ls -l'

Define the command "LS - L" or name DIR.

. Delete the defined alias

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

Perform format: UNALIAS NAME

EXAMPLE:

% UNALIAS DIR (Delete Alias ​​is DIR definition.)

% Unalias * (Delete settings all aliases.)

History

=======

. Set the length of the command record

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

Perform format: set history = n

EXAMPLE:

% set history = 40

Set the length of the command record table to 40 (40 commands that can be recorded).

. View the content of the command record

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

Perform format: HISTORY

. Use command record table

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

Perform format:!!

EXAMPLE:% !! (Relative Execution Previous Command)

Perform format:! N (n is the command number for the command log.)

EXAMPLE:%! 5 (execute the fifth command in the command log table.)

Perform format:! String (overhead execution with string as the starting font of the starting pen)

EXAMPLE:%! CAT (Reproduction, with CAT as the starting font command.)

. Display the contents of the previous command

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

Perform format: !!: p. Change the content of the previous command and execute it

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

Perform format: ^ oldstring ^ newstring

Change part of OldString in the previous order, and execute it.

EXAMPLE:

% Find. -name file1.c -print

^ file1.c ^ core

% Find. -Name Core -Print

Note: The file generated by the system when an error occurs or an error occurs for an execution program or command. As an error (Debug)

Because it is extremely space, it is usually deleted.

Compression of information

==========

To avoid uncommon files or information, occupy too large disk space, please compress it. Want to use compression

Before the file or information, it will be reducing it to restore the original data. Any file that has been compressed,

It will be attached to the ".z" letter in the file name, indicating that this is a compressed file.

. Compression information

==========

Perform format: Compress FileName Capacity

Perform format: CompressDir Directory-Name Compression Directory

. Unzip reduction materials

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

Perform format: Uncompress FileName Anti-compression file

Perform format: UncompressDir Directory-Name Anti-compression Directory

Pipe-line use

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

Perform format: Command1 | Command2

Execute the Command1 as a result of Command2 as a Command2.

EXAMPLE:

% ls -rl | more

With paging mode, all files in current directory are listed, and the name of the subdirectory is listed.

% Cat File1 | More

List the contents of file file1 in paging mode.

I / O Control

===========

. Standard input control

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

Perform format: Command-line

Use File as the input of Command-Line.

EXAMPLE:

% mail -s "mail test" user@isis.sinica.edu.tw

Will the file file1 when doing the content of the letter, the Subject name is Mail Test, give it to the recipient.

. Standard output control

================ Perform format: Command> FileName

Send the results of the Command to the specified filename.

EXAMPLE:% ls -l> list

The result of the "LS -L" command will be executed, and write into the file list.

Perform format: Command>! FileName

Also, if the file of FileName already exists, it is forced OverWrite.

EXAMPLE:% ls -lg>! List

The result of the "LS - LG" command will be executed, forced writing to the file list.

Perform format: Command> & FileName

When performing Command, any message generated on the screen, written in the specified filename.

EXAMPLE:% cc file1.c> & error

Any message generated when compiling file1.c files is compiled, and write to archive error.

Perform format: Command >> FileName

Execute the result of the Command, Additional (Append) to the specified filename.

EXAMPLE:% LS - LAG >> LIST

The result of the "LS - LAG" command will be executed, which is attached to the file list.

Perform format: Command >> & filename

When performing Command, any message generated on the screen is attached to the specified filename.

EXAMPLE:% cc file2.c >> & Error

When the file2.c file will be compiled, any information generated by the screen is attached to the archive error.

View the user in the system:

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

Perform format: WHO or FINGER

Perform format: W

Perform format: finger username or finger username @ domainname

Change your username to other users' accounts, have their right to use.

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

Perform format: SU Username

EXAMPLE:

% SU User enters the user account

Passwrod: Enter the user's password

View username:

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

Perform format: Who am i View Login, your own username. Perform format: WHOAMI Views the current UserName. If the "SU" command has been performed, the SU "command has been executed,

This Username is displayed.

See the user of all workstations in the current class:

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

Perform format: RUSERS

=> end

Talk to the user on a workstation:

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

Perform format: Talk username @ hostname or talk username @ ip_address

EXAMPLE:

1. You can use the RUSERS directive to view the user on the network.

2. Suppose your account is U84987, use it on Indian, now you want to be on DOC

U84123 conversation.

% TALK U84123 @ DOC ==> At this time, the waiting screen will appear on the screen.

The following messages will appear on the other party (U84123) screen

Message from talk_daemon @ local_host_name at xx: xx

Talk: Connection Requested by U84987 @ Indian

Talk: Respond with: Talk U84987 @ Indian

At this point the other party (U84123) must perform TALK U84987 @ Indian to talk to each other.

Finally, press .

Check if the remote computer system is normal

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

Perform format: ping hostname or ping ip-address

EXAMPLE:

% ping doc

Introduction to email (e-mail)

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

The E-mail address of this department is Ice.ntnu.edu.tw

.. Send the file as the content of E-MAIL

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

Perform format: mail -s "subject-string" UserName @ address

% mail -s "program" user

Put file.c as the content of Mail, send to user, subs name is Program. .. Transfer E-mail to this user

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

Perform format: mail username

% Mail User

.. Transfer E-mail to the field

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

Perform format: mail username @ receivediver-address

EXAMPLE

% mail paul@gate.sinica.edu.tw

Subject: Mail Test

:

:

Type a letter content

:

:

Press the "Control D" button or "." To end the letter.

When you press the "Control C" button twice, it will be interrupted and do not send this letter.

CC:

(Carbon Copy: Copy a letter, give other recipients)

.. Check whether the E-mail transmitted is sent or stranded in the mail servo station of this office.

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

Perform format: / usr / lib / sendmail -bp

(If the screen is displayed as the message "Mail Queue Is Empty", it means that Mail has been sent.

If you have other error messages, E-mail has not been sent because it is. )

.. read letters

=========

Perform format: Mail

Commonly used instructions are as follows:

CD [Directory] Chdir to Directory or Home IF None Given

D [Message List] delete Messages

h print out active message headers

M [User List] mail to special users

N goto and type next message

P [Message List] Print Messages

Q Quit, Saving Unresolved Messages in Mbox

R [Message List] reply to sender (only) of Messages

R [Message List] reply to sender and all recipients of messages [message list] file append messages to file

T [Message List] Type Messages (Same as Print)

U [Message List] Undelete Messages

v [Message List] Edit Messages with Display Editor

W [Message List] file append messages to file, WITHOUT from line

x Quit, Do Not Change System Mailbox

z [-] Display Next [Previous] Page Of Headers

! shell escape

Introduction to the Method of File Editor VI

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

Vi, Celvis (CVI) is a Chinese and English editing software that is used in the workstation. For beginners,

Often because of its special use, not to enter the door; for users who have been using VI,

Frequently, because of the unfamiliar or not understanding of VI, it is impossible to play the powerful editing ability of VI, below

Introduction to the method of use of VI.

.. Syllabus of this article

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

Enter VI

Leaving VI

Input mode

How to enter the input mode

How to leave the input mode

Instruction mode

Movement of the cursor

Mobile window

Delete, copy, and modify instructions (Delete, Change, Yank)

Delete and modification (Delete, Replace)

Movement and replication (delete / PUT, YANK / PUT)

Instruction

Cancel the previous action (UNDO)

String search

Data connection and branch

Environment setting

EX instruction

Other ways

Chinese editor

Restore the file being interrupted

Edit multiple files

VI is an abbreviation of Visual Editor and is one of the editors provided by UNIX. It provides a user

The editing environment of the window, under this window, the user edits the desired file.

.. Enter VI

=======

Execute the VI editorial program directly:

% vi test

The editing window of the VI will appear on the screen at this moment, and the VI will copy a file into the memory.

Buffer. The VI will remain in the file in the disk, and the file of the buffer is first

After the case is edited, after the editing is completed, the user can decide whether to replace the original old file.

.. Leaving VI

=======

If in the input mode, then use "ESC" to enter the instruction mode, then the following instructions can be used.

Leave VI.

: Q! Leave the VI and give up the content that is just edited in the buffer.

: WQ writes the data within the buffer to the disk and leaves the VI.

: Zz with WQ.

: X with WQ.

: W Write the data within the buffer into the disk, but does not leave the VI.

: Q Leaves VI, if the file is modified, will be required to confirm whether to give up the modified content.

This instruction can be used in conjunction with: W.

..vi's operating mode

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

VI provides two modes: Insert Mode and Command Mode

. When the user enters the VI, it is in the instruction mode, and any characters typed at the moment are considered.

instruction. Delete, modify, etc. can be deleted, modified in this mode. To enter the information, you need to enter the input.

mode.

.. input mode

=========

How to enter the input mode

A (append) is added after the cursor.

A is added to the end of the line.

i (insert) is added to the data before the cursor.

I is the first to add information from the first line.

O (Open) Added a diploma for the use of the information.

O Added a dip address on the line for input information.

How to leave the input mode

"ESC" ends the input mode.

.. instruction mode

=========

Movement of the cursor

h shifts one of the characters left left.

j moves up one by one.

k moves down one of the characters.

l Move a word to the right.

0 moved to the first line

$ Move to the end of the line.

^ Move to the first character of the row.

H Move to the first column of the window.

M Move to the middle of the window.

L Move to the last column of the window.

G moves to the last column of the file.

Move to the first character of the next column.

- Move to the first character of the previous column.

(Move to the beginning of this sentence. (Note 1)

Move to the end of this sentence.

{Move to the first paragraph. (Note)

} Move to the end of this paragraph.

Ng moved to the nth column of the file.

N moves to the nth column after the cursor is located.

n- Move to Nth columns before the cursor is located.

will display the line number, file name, and the number of line numbers in the file, the cursor

The number of the line accounts for the full line.

Note 1: Sentence "refers to"! ","."or"? "The end of the word.

Note: Paragraphs In vi, refers to the text spaced from blank row.

.. Mobile

===========

Window is wound down.

Window Top Page.

Window is wound down and half.

Window Top Page.

Window is rolled down.

Window is rolled up.

.. Delete, copy, and modify the instructions (this unit is less)

========================= D (DELETE), CHANGE and Y (YANK) instruction format in the VI for:

Operator Scope = Command

(Operator) (range)

Operator:

D Delete the instruction. Delete information, but copy the deleted data to the memory buffer.

Y Copy the information (group, ranks, sentences or paragraphs) to the buffer.

P Placement (PUT) instructions, with D and Y and use. Can make the last DELETE or YANK

The material is placed under the row of the cursor.

C Modify the command, similar to the group and inserts of Delete. Delete a group, sentence

The information of the child and insert a new key information.

range:

E is the last character of the string to the string by the cursor.

w by the cursor location to the first character of the next string.

b The first character of the cursor at the position to the previous string.

$ The last character of the row is located at the position of the row.

0 By the position of the cursor to the first character of the line.

) The first character of the cursor at the position to the next sentence.

(The first character of the cursor is positioned to the sentence.

{The last character of the cursor is in the position of the paragraph.

} The first character of the passage from the cursor to the paragraph.

Allocation

DD delete the whole line.

D Taking behavioral units and deleting the clearance after the cursor.

CC modifies the content of the whole line.

YY YANK is fully line to copy the row in the row to the memory buffer.

.. Delete and modification

===========

x Delete the cursor where the vol is located.

X Delete the word element before the cursor is located.

DD Deletes the row where the cursor is located.

R The cell replacement (Replace) cursor after the connection is connected to this instruction.

Such as: RA replaces the cursor in A.

R Enter the substitution until "ESC".

s Delete the vol of the cursor and enter the input mode until "ESC".

S Delete the line of information where the cursor is located, and enter the input mode until "ESC".

.. Movement and Replication

==========

Use the delete and PUT instructions to complete the purpose of the data movement.

Use the YANK and PUT instructions to complete the purpose of data copy.

YANK and DELETE copies the specified data to the memory buffer, and by the PUT instruction

The data within the buffer can be copied to the screen.

example:

Move a row. Perform DD in this line

. Switches to the destination

. Execute P

Copy a row. Perform YY in this line

. Switches to the destination

. Execute P

.. Instruction repeat

=========

In the instruction mode, a digital N can be added in front of the instruction, then this instruction action repeats N

Time.

example:

Delete 10 lines. 10dd

Copy 10 lines. 10YY

. Switches to the destination

. p

The indicator moves down 10 lines. 10J

.. cancel the previous action (UNDO) ====================

That is, restore the content before performing the previous command.

u Restores the result before the last instruction.

U Recovering the row of the row.

..search

=====

A string can be searched in VI to move the cursor to the point.

/ String is looking for the string after going to the game.

The string looks for the string before the string is coming.

N Continue to look for the next identical string.

N Continue to find the next same string.

.. data connection

===========

J sentence connection. Connect the next row under the cursor to the back of the row.

If the data is too long, it can be divided into two lines, as long as the cursor is moved to the separate point, enter the input mode

(You can use the A, I and other instructions) to press "Enter".

.. Environment settings

===========

: Set Nu Set the line number of the information.

: Set Nonu cancels the line number setting.

: SET AI automatically contracted.

: Set NOAI cancels automatic contraction.

Automatic Indentation

When editing files or programs, sometimes there is a condition that needs to be contracted, ": SET AI" is provided

The function of the interpolation is explained in the following example:

. Vi Test

. (After entering the edit window)

this is the test for auto indent

"Tab" Start Indent ←: SET AI (set automatic contraction)

"Tab" DATA

"Tab" DATA

"Tab" Data ←: SET NOAI (cancel automatic contracted)

The end of auto indent.

. Note: Delete the "Tab" character.

..ex instruction

=======

Read and write

: W Write the data of the buffer into the disk.

: 10, 20W TEST Write the data of the 10th line to 20th line to the TEST file.

: 10, 20W >> TEST will add information on the 10th line to 20th line to the TEST file.

: R Test reads the data of the TEST file into the finals of the editing buffer.

Delete, copy, and move

: 10, 20D Delete the information of the 10th line to 20th line.

: 10D Delete the data of the 10th line.

:% D Delete the entire editing buffer.

: 10, 20CO30 copy the data of the 10th line to 20th line to 30th line.

: 10, 20 MO30 moves the data of the 10th line to 20th line to 30 lines.

String search and replacement

S (SUBSTITE) instructions can search for a range of ranks.

G (Global) instructions can search for the entire editing buffer.

The S command is an object that is substituted with the string that satisfies the condition. If there is several strings that meet the condition, it can only replace the first, if you want to replace all the strings, you need to add G. parameter.

: 1. $ S / OLD / NEW / G changes all "OLD" in the file to "New".

: 10, 20s / ^ / / Plus the top 10 rows to 20th line of data into 5 blank.

:% S / OLD / NEW / G changes the "OLD" in the edit buffer to "New".

.. file that is interrupted when you restore editing

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

In the editing process, if the system is dropped or connected, the data of the buffer has not yet

When written back, when it returns to the system again, the following instructions can be replied before the interrupt

Archive content.

% vi -r filename

.. Edit multiple files

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

VI also provides functions of editing multiple files at the same time, as follows:

% vi file1 file2 ..

When the first archive is completed, ": w" can be used to archive the buffer, and then

Use ": n" to load the next file.

转载请注明原文地址:https://www.9cbs.com/read-8445.html

New Post(0)