UNIX common command
The basic usage of each common instruction will be described below. If you need to explain, use Man to read detailed Manual.
1. About the file / directory processing
LS - column directory
This is the most basic archive instruction. The meaning of LS is "List", which is to put a directory or
The content of a certain file is displayed.
Format: ls -1acflrabcdfgilmnopqrstux -w [sv] [files]
example:
#LS (not with any parameters list all files in the current directory)
#ls bin (Simple format lists all files in files named bin) or all files under the directory)
#LS / U / ILASII_GB / LIB (full path, list all files in the lib directory)
The common parameters of the LS are as follows:
-a: If a directory or file name is "in Unix". ", use LS.
Will not show the name of this file, we call this file as a hidden file. Such as .profile, .tcshrc, etc.
If we want to see such a file, you must add parameters -a.
-l: This parameter represents the long (long) format using LS, you can display more information, such as file access rights, file owners (OWNER), file home group, file size, file last update time, even Symbolic Link The file is a file, such as the LINK, and more. The results are shown below:
DRWXRWXRWX 30 root bin 1024 May 23 10:38 U
Drwxrwxrwx 2 root sys 512 JUL 28 1999 UACN
DRWXRWXRWX 5 root sys 512 JUL 27 1999 UDK
LRWXRWXRWX 1 Root Sys 11 Jul 27 1999 Unix -> / Stand / UNIX
Drwxrwxrwx 35 root auth 1024 APR 3 13:45 USR
The user privileges given the file on the 10 characters starting. This sequence is divided into four domains. The first character is the type domain, the second, 3, 4 characters are the user's main domain, the 5th, 6th, and 7 characters are the group user domain, the 8th, 9th, 10 characters are other user domains, the domain The meaning of characters is as follows:
l In type field:
D indicates that this file is a directory.
- Indicates this file is a normal file
b, this file is a special block device I / O file
c indicates that this file is a special character device I / O file
l Indicates that this file is a connection file. Keeping the file path and name that is connected to it after its file name. Such as:
UNIX -> / stand / unix
l In "User Lord", "Group User", "Other User" fields:
R indicates a read permission. Meaning is to copy or display content in the file or directory.
w indicates that there is a write permission. The meaning is that it can change or modify the file.
x indicates that there is execution permission. The meaning is that the file can be executed or enter the directory with the CD command, and build in this directory.
File or subdirectory, etc.
- Expressed no authority.
CHMOD - Change Mode (Change Mod)
This instruction is used to change the access mode of the file (Access Mode). There is a profile-writable (W) to perform (X) three modes on a file in a Unix file, respectively, of the owner of the file (Group MEMBER) (you can ls -lg Watch the group of a certain file, and others. A file If you change to an executable mode, the system will treat it as an executable file, and a directory executable represents the user's right to enter the directory. CHMOD is used to change the model of some files. Format: chmod [-fr] mode filename ...
The significance of the main parameters is as follows:
-f (force): chmod will not pay the failure.
-R (Recurive): Change all sub-directories and files under all subtrands to the mode you have to change.
Mode: Refers to the change mode. Includes three aspects:
A. Which users have changed
U - the user itself
g - the same group of users
O - other users
B. How to change
- Add permission
--- Remove the permissions
C. What permissions
R - read rights
W - write permissions
X - Execution Permissions
example:
#CHMOD G0 W File1
The privilege of fila1 before modifying is: -rwxr - r -
The authority of file1 after modification is: -rwxrw-rw-
You can also use a three-digit album to represent the access to certain objects.
example:
#CHMOD 666 * (All users can read, write)
#CHMOD 777 * (All users can read, write, execute)
CAT - series display command
Example: #cat file1 (display the contents of file file1 on the screen)
The CAT command can also be used to create files, such as:
#cat> Newfile
this is a text
Ctrl D
Establish a newfile file, content is: this is a text
#cat file1 file2> file3 (connect file1, file2 two files Generate file file3)
#cat f1 f2 >> F3 (the end of the F1, F2 two files is connected to the end of the F3 file)
More - Split screen display file content
More can display the observed files according to the split screen and change the page or row according to the user's request.
If the user wants to search for a specific string in a certain file, press / and then follow the words to be searched to search.
If you feel that some part you want, you can use 'Q' to leave more.
Press 'V' in use or you can use the editor to edit the viewed file.
Format: more filename
CD - change the current directory
Format: CD DIRNAME
example:
#CD (to the user's "home" directory)
#CD / USR (transfer the current directory to / usr directory, also enter / usr)
#CD .. (Return to the previous directory)
#cd ../ .. (Return to the previous directory of the previous directory)
CP - copy
The meaning of this instruction is to replicate ("copy"), that is, copy one or more files into another.
A file or copy it to another directory.
Format: CP [-fip] Source_File Target_file (Copy File)
CP [-r | -r] [- fip] Source_File ... target_file (copy directory) The common parameters are as follows:
-i: This parameter is when the file has been named F2, if the CP will cover the contents of the original F2, so you must ask the user before you have to cover it. If the user's answer is Y (YES), the copying action is performed.
-r: This parameter is used to make backup replication, and you can copy a whole subtree into another directory.
The use of CP is as follows:
#CP F1 F2 (copy a file named F1 copy a file named F2)
#CP F1 F2 F3 ... DIR (copy the file F1 F2 F3 ... copy a copy of the directory DIR)
#CP -R Dir1 Dir2 (copy all the contents of DIR1 to DIR2)
MV - mobile or changed
The meaning of MV is Move, mainly to change the file to another directory.
Format: MV [-fi] Source_File ... Target_File
The main parameters:
-i: -i meaning is the same as the CP, all of which are interested in Intective.
-f: Force (Force) execution. All other parameters encountered -f all invalid.
example:
#mv F1 F2 (changed a file named F1 is called F2 file)
#mv Dir1 Dir2 (changed a directory named DIR1 to Dir2)
#mv F1 F2 F3 ... DIR (transfer file F1 F2 F3 ... all in the directory DIR)
RM - delete
The meaning of RM is remove, which is used to delete a file. One deleted file in UNIX unless the system is just a backup, otherwise it is possible to recover like DOS. So when doing RM actions, users should be particularly careful.
Format: rm [-firr] file ...
The main parameters:
-f: The system will make any warning messages when the system is deleted.
-i: You will ask if you want to remove it before removing the file.
-r: Reclaimed deletion.
note:
Don't use RM-RF, otherwise you will "cry without tears" one day ...
example:
RM F1 (delete file named F1)
RM -R DIR1 (Deleting Directory Named Dir1 and all files under
RM -I Sendmarc1 (delete the file called SendMarc1 before prompted, to answer (Y / N)?) as follows:
REMOVE Sendmarc1? y
MKDIR - Create a directory
MKDir is a directive that allows users to create a directory. You can use it under a directory
MIDIR creates a subdirectory.
Format: mkdir dirname1 [dirname2 ...]
example:
#CD / u / ILASII_GB (replace the current path to / u / ILASII_GB)
# MKDIR ILASBAK (Create a subdirectory named Ilasbak in / u / ilasii_gb directory)
RMDIR - Delete Directory
RMDIR is used to delete an "empty" directory. If there is no file below a directory, you can remove it with the RMDIR instruction.
format:
Rmdir dirname1 [dirname2 ....]]
If there are other files under a directory, RMDIR will not be able to delete this directory unless the -R option is used. example :
RMDir Ilasbak (Deleting an empty directory named Ilasbak)
PWD - Display the current path
E.g:
#pwd
/ u / ilasii_gb / data (Show current path is: / u / ilasi / data)
2. About the process processing command:
PS - Shows the status of your Process or System Processes
format:
PS [-AADEFL] [-g groups] [-o format] [-p pids] [-t termlist] [-U users] [-u users] [-g pgrplist]
Common parameters:
-A lists all users' Process status.
-u Displays the User - Oriented Process situation.
-x Display includes a process situation without Terminal control.
-W Use a wide display mode to display the process situation.
example:
#ps -ae (display all processes and status)
#ps -u ing ilAsNT1 (display user IlasNT1 process status)
PID TTY TIME CMD
1194 TTYP0 00:00:00 SH
#ps -t tty1a (Process on TTY1A)
As shown above: We can get the status of the current processes via the PS, such as PID (process number), TTY (device name), Time (time), cmd (program name), etc.
Kill - killing processes
The use of the Kill instruction is to send a signal to a process. Because most of them are used to kill the process, it is called KILL.
format:
Kill [-signal] PID ...
Kill -l
Signal: For a signal number, from 0 to 31, 9 is Sigkill, which is generally used to kill some signals that cannot be stopped normally.
You can also look at the number of words that can replace the Signal number with Kill -L.
3. User Operation Directive
Who --- Query now there are those people online
example:
#Who
IlasNT1 TTYP0 May 24 10:23
Root TTYP3 May 24 11:27
Root TTYP4 May 24 09:39
W - Query currently have those people online, showing the current work of those people
example:
#w
12:17 PM Up 3:59, 3 Uses, Load Average: 2.03, 2.02, 2.00
User tty login @ iDLE JCPU PCPUWHAT
IlasNT1 TTYP0 10:23 AM 1:54 1 - -sh
Root TTYP3 11:27 AM 2 1 - W
Root TTYP4 9:39 AM 38 1 - -sh
CHGRP - change the properties of the group
format:
Chgrp [-r] group file ...
example:
#chgrp library file1 file2 ... (turn file1, file2 ..., etc. to library)
Chown - change the owner of the file or directory
Format: Chown [-r] Owner [: group] file ...
example:
#Chown ILASNT1 ILASII_GB (change the user of ILASII_GB to ILASNT1)
Passwd - Change the user password
format:
Passwd username (not with your username, to modify the root password)
4. Network instruction
UNIX provides a connection to the network so that you can do some special things on different machines. Some work can utilize UNIX's network instructions, connect to each different machine on your position. In this way, even if you are in the bedroom, you can work easily oriented in the system, you don't have to bubble in cold ice.
The instructions of these networks are as follows:
Telnet - Simulation Terminal Program
Telnet is a User connected to Remote Host.
format:
Telnet [Hostname | ip-address] [port]
among them:
Hostname: For a name address, like ccsun1 or ccsun1.cc.nctu.edu.cn;
IP-Address: The IP address consisting of four less than 255 numbers, such as 140.113.17.173, 210.26.147.1, etc.
Port: For some special programs, the communication point supplied to the outside world. If the other party is not requested, this item is not required.
example:
#telnet ccsun1
#telnet 140.113.17.173
FTP - File Transfer Protocol
The meaning of ftp is File Transfer Program, which is a very common application of online file transmission.
program.
format:
FTP [Hostname | ip-address]
Where Hostname | IP-Address is the same as Telnet.
After entering the FTP, if it is connected to the Remote Host, it will ask your username.
With the password, you can start file transfer if you input pair.
FTP is often used commands:
ASCII: Sets the transfer mode to ASCII mode. Usually used to transfer text files.
Binary: Set the transfer mode to a binary mode, usually used to transfer the execution file, the compressor, and the image stach.
CD Remote-Directory: Change the work directory on the Remote Host.
LCD [Directory]: Change the working directory of Local Host.
LS [Remote-Directory] [local-file] lists the files on the Remote Host.
Get Remote-file [local-file]: Available in distant files.
MGET Remote-files: You can use a general-purpose nine to get multiple files at a time.
Put local-file [remote-file]: Send the file of Local Host to Remote Host.
MPUT LOCAL-FILES: You can use the general-purpose character to put multiple files on the Remote Host once.
Help [Command]: Online Auxiliary Directive.
Mkdir Directory-name: Create a directory in Remote Host.
Prompt changes the conversation mode. If ON is transferred to the MPUT and MGET
Inquiry when the input is input.
Quit / Bye leaves FTP.
5. Other instructions
Vi - editorial command
Any user's most frequently created and edited files, including documents, reports, and text, VI (Visual Editor) is a valid and relatively simple full screen editor, using VI, just remember a small amount of basic instructions, Start start, learn other more complex instructions, and system administrators use VI management and maintenance systems. VI is a full screen editor included in the SCO System V job system. In fact, VI is not alone in SCO UNIX, but is quite popular in UNIX. Opening files can be used in Whether it is open a new file or modify the old file.
format:
#vi filename
If the file is new, you will see a message at the bottom of the screen and tell the user that you are creating a new file. If the file already exists, VI will display the first four lines of the file, the user can use the cursor (CURSOR).
This is the screen style after executing VI:
~
~
The above is an analog file opened by a VI, and the row number (~) indicates the end of the file. VI uses two states, one is a command mode, and the other is an insert mode. When the VI is in the order state, the incoming content will be regarded as an instruction; on the other hand, when the VI is inserted, the text can be entered into the file.
Most VI instructions are single characters, changed by the insert state to the instruction state, press the
l insert
i insert the text in the cursor
I Insert a body in a row
a appended the body after the cursor
A appended the body at the end
o (lowercase Europe) new line in the cursor
O (uppercase Europe) newly opened in the cursor
To remember a little, inserted into the state, you can't get into the instruction, you must press
l storage and exit
How to archive and exit the specified file is important when modifying the file. In VI, when you exercise an archive or exit, you must press the colon (:), change to the instruction state, the user can see the lower left of the screen, there is a colon (:), showing VI has changed to the directive state, can Make an archive or exit.
Below is some commonly used instructions in this regard.
: q! Give up any changes to exit VI, which is forcibly exiting
: w Archive
: WQ archive and exit VI
: X is the same as WQ
: ZZ deletes the body like WQ
l Delete
Deleting or modifying the body is using the insert state, so the instructions mentioned below are only in the insert state, and the instructions are directly selected.
x Delete Cursor Character (Character)
Nx deletes n characters after the cursor
Nx deleted N characters before the cursor
NDW Delete Cursor N word (Word)
DD delete
D $ or D Delete by the cursor to the end of the line
u Restore the previous time to delete
l Modify the body
When using the VI to modify the body, when adding minimal, another set of instructions inserted into the state will be employed.
- R char Reated characters by Char instead of the cursor - RTEXT
-CWText
-Ctext
-Cc makes the whole line blank, but retains a cursor position, let you start to enter
- If you delete an instruction, the number of imported before the command indicates how many times is executed.
l Text mode search
To retrieve files, you must do it in an order state. The so-called "mode" is a specific string, which can be spaced.
/ Str
Str
Nup retrieval in the same direction
N opposite direction repeated retrieves
Vi entangles all files, constantly retrieving until the next appearance appears to find the pattern. Others If you want to execute during the VI execution, use an exclamation mark (!) To execute the system instruction, such as during the VI, list the current directory content, you can be entered:! If
On the other hand, the user can create a .exrc environment file in the primary directory, use the SET to enter the option, and when the VI is called each time, the instructions and settings in .exrc are read. Here is an instance of the .exrc environment file:
SET WRAPMARGING = 8
SET ShowMode
Set autoindent
Set number
Backup command: TAR (C)
TAR is the most easy to use and the most reliable utility (utility), reserved and recovered files from archive media, and can extract a single file from the archive archive.
TAR archives uses the relative or absolute path name of the file and directory.
All variable options are displayed in TAR.
Such as:
Tar - {TXRUC} [0-9VFBKELMNOPWAFLTP] [TAPEFILE] [blocksize] [TapeSize] FILES ...
Key Device Block Size (K) TAPE
0 / DEV / RFD048DS9 18 360 NO
1 / DEV / RFD148DS9 18 360 NO
2 / dev / rfd096ds15 10 1200 NO
3 / dev / rfd196ds15 10 1200 NO
4 / DEV / RFD0135DS9 18 720 NO
5 / dev / rfd1135ds9 18 720 NO
6 / dev / rfd0135ds18 18 1440 NO
7 / DEV / RFD1135DS18 18 1440 NO
8 / dev / RSTP0 20 0 YES
9 / dev / rctmini 20 0 yes
10 / DEV / RDSK / FP03D 18 720 NO
11 / DEV / RDSK / FP03H 18 1440 NO
12 / DEV / RDSK / FP03V21 10 20330 NO
among them:
"CV" is created archiving;
"CV #" for device number from / etc / default / tar
"RV" has added an archive; "UV" updates the file on the existing archive;
"TV" shows the archive content table;
"XV" extracts files from archiving;
"F" is read or written from the specified file;
"L" makes Tar follow the symbolic connection to continue to be traced, and the symbol connection is ignored by default.
example:
(1) To archive the specified file, the existing data on the cover disk, the instructions are as follows:
$ CD PUB
$ TAR CV8 ASCII Greek (8 is a tape drive)
Volume End At 1199k, Block Factor = 5K
Seek = 0k a ascii 3k
Seek = 3k a Greek 1k
(2) To list the contents of Tar:
$ TAR TV8
RWXRWXRWX201 / 50 1731 APR 11 00:58 1997 Web50 / Web / srchbib.htm
RWXRWXRWX201 / 50 1002 APR 11 00:58 1997 Web50 / Web / ReadInfo.htm
RWXRWXRWX201 / 50 1070 APR 11 00:58 1997 Web50 / Web / Stflag.gif
RWXRWXRWX201 / 50 45 Mar 22 01:27 1997 Web50 / Web / CGI-BIN / ILASPROF
RWXR-XR-X201 / 50 136799 APR 10 04:10 1998 Web50 / Web / CGI-BIN / OPENHOLD
Note: Create a TAR archive, use the relative path name, otherwise, restore another system will cover files of other systems. Such as:
#TAR CV8 / ETC / MOTD
#CD / TMP
#TAR XV8
X / ETC / MOTD, 943 BYtes, 2K
DF - Display hard disk space usage
Disk space is assigned in blocks, and typical blocks are 512 bytes.
example:
#df -v
Mount Dir FileSystem Blocks Used Free% Used
/ / DEV / ROOT 2123740 990450 1133290 47%
/ Stand / dev / boot 100000 19796 80204 20%
/ U / DEV / U 15000000 12529568 2470432 84%
DU - Detects a directory and (recursively) all the disk space occupied by the files in its subdirectory, with a block size identifier.
example:
# d
# d --s only displaying the space occupied throughout the directory
Find - Start with the specified path to find files with the specified feature
example:
#find / -name ory.ini (From the root of the root directory to find file named Ilas.ini, and display it on the screen)
Date - Display System Date
example:
#date
Thu May 24 14:31:49 CST 2001
Format - floppy disk format
example:
#Format / DEV / RFD096DS15 (Format 5 inch high-density floppy disk (A drive)
HALTSYS - emergency shutdown
Format: #haltsys Enter (this point is not performed to turn off the database, etc., "best use Shutdown)
Shutdown - multiple users are shut down
format: