Linux UNIX knowledge

Source: Internet
Author: User
Tags add numbers control characters printable characters unpack line editor

Common Unix Commands-directory and file operation commands
1.1 ls

[Syntax]: ls [-radcxmlnogrtucpfbqisf1] [directory or file...]
[Note]: The LS command lists the files in the specified directory. The default directory is the current directory./, and the default output order is vertical in character order.
-R recursively lists the content of each subdirectory.
-A: List all files, including hidden files with the first character "."
-D if the following parameter is a directory, only the directory name is listed instead of the directory content. It is often connected to the-L option.
Used to display the directory status.
-Multi-Column Display in C output
-X horizontally arranged by characters
-M outputs are arranged horizontally in Streaming Format and separated by commas (,).
-L the output of the long list shows the detailed information of the file. Each row contains one file, which is displayed from left to right:
File Access Mode connection count file master file group file Byte Count last modification time
The file access mode is represented by 10 letters. The meaning from left to right is as follows:
The first letter indicates the file type, which may be in the following situations:
D is the directory file.
L is the link
B is a block File
C is a balanced File
P is named pipe (FIFO)
-Common File
The last nine letters indicate the power of the file master, users in the same group, and other users. r indicates readable, W indicates writable, and X indicates executable. If it is a device file, it is displayed in the number of bytes of the file: the master device is from the device.
The-N option is the same as the-L option, but only the file owner displays the number (UID) and the file group displays the number.
(GID) indicates
-O and-l options are the same, but do not display file groups
The-G option is the same as the-L option, but the file master is not displayed.
-R in reverse order
-T arranged in chronological order rather than by name
-U indicates the last access time instead of the last modification time.
-C: Use the last modified I node time instead of the last modified time when displaying the time
-P If the listed files are directory files, a slash (/) is displayed after them (/)
-F Add '/' After the directory file and '*' After the executable file '*'
-If the file name B contains non-printable characters, it is displayed in octal format.
-Q '? 'Indicates
-I: display the node number.
-S: Use the block length instead of the byte length when displaying the file length
-F interprets the following parameters as directories and lists each of them.
-1 each row contains only one column
[Example]:
Ls to list files in the current directory
Ls-Al/bin lists all files in the directory/bin in a long list, including hidden files.

1.2 pwd

[Syntax]: pwd
[Note]: This command is used to display the current working directory.
[Example]:
PWD displays the current working directory

1.3 CD

[Syntax]: CD [Directory]
[Note]: This command is used to change the current working directory. When no parameter is set, the environment variable $ home is used as its parameter. $ home is generally the Path entered at registration.
[Example]:
CD back to the directory at registration entry
CD/tmp go to the/tmp directory
CD ../enter the parent directory
1.4 mkdir

[Syntax]: mkdir [-M mode] [-p] Directory Name
[Note]: This command is used to create a directory. The directory access mode is determined by the mask (umask) and requires write permission on its parent directory. The directory UID and GID are actual UID and GID.
-M: create a directory in the specified Access Mode
-P creates all non-existing parent directories when creating a directory.
[Example]:
Mkdir TMP create a subdirectory TMP in the current directory
Mkdir-M 777/tmp/ABC use all readable and writable executable access modes.
Create the directory/tmp/AAA. For the access mode, see the CHMOD command.
Mkdir-P/tmp/A/B/C create a directory/tmp/A/B/C. If the directory does not exist,/tmp/
And/tmp/a/B.

1.5 rmdir

[Syntax]: rmdir [-p] [-S] Directory Name
[Note]: This command is used to delete directories.
-P: delete all empty parent directories.
-S when the-P option is used, the error is not prompted.
[Example]:
Rmdir/tmp/ABC Delete directory/tmp/ABC
Rmdir-P/tmp/A/B/C Delete directory/tmp/A/B/C, if directory/tmp/a/B
And/tmp/a empty, delete

1.6 cat

[Syntax]: CAT [-u] [-S] [-V [-T] [-E] file...
[Description]: displays and connects one or more files to the standard output.
-U unbuffered output (with buffered output by default)
-S: Do not prompt for nonexistent files
-V shows non-printable characters in the file, control characters are displayed as ^ N, and N is an octal number,
Other non-printable characters are displayed as M-X, which is an octal value with a minimum of 7 characters.
-T when the-V option is used, the tab is displayed as ^ I, and the page break is
(Formfeed) displayed as ^ L
-E: when the-V option is used, $
[Example]:
Cat file display file
Cat-S-v-e file1 file2 file3 show file file1 file2 file3 one by one

1.7 head

[Syntax]: head [-N] [file...]
[Description]: displays the output in the first n lines of the file. The default value is 10. When multiple files are displayed, add ==> file name before each file <=
[Example]:
Head-9999 file1 file2: display the first 9999 lines of the files file1 and file2

More than 1.8

[Syntax]: more [-cdflrsuw] [-number of rows] [+ number of rows] [+/mode] [file...]
[Description]: displays the file on the terminal. -- more -- is displayed at the lower left of each screen. If the file is read rather than the pipe, the percentage is displayed at the end, indicates the displayed part. Press the Enter key to roll up a line and press the Space key to roll up a screen. If not, you can use the subcommand in the more command.
-Clear the screen before C displays the file
-D. When an error command is input, the error message is displayed instead of the bell)
-F: Do not fold long lines.
-L do not use the paging control character (CTRL d) as the page end
-R generally, more does not display the control operator. This option enables more to display the control operator,
For example, display (ctrl c) as ^ C
-S converts multiple empty rows into one empty row display.
-U prohibits the generation of underline Sequences
-W is usually released immediately after the display is complete. This option is provided after the display is complete.
Show, press any key to launch
-N rows specify the number of rows per screen
+ The row number is displayed starting from the specified row number.
+ // Mode: Search for the specified mode in the file. When the last two lines in the Mode show that the file is not displayed, you can use the subcommand in the more command! And/are not displayed, and do not press Enter. When the command destroys the more prompt line, the Return key can be used to restore the prompt line. In the following sub-command operation, I indicates a number. The default value is 1.
I space to roll one screen multiple I rows
I press enter to roll up I
I Ctrl + d I missing saves time to roll up 11 rows; otherwise, roll up I rows
If id I is missing, 11 rows will be rolled up; otherwise, I rows will be rolled up.
Iz I does not need to roll up one screen; otherwise, each screen is defined as one line.
Is skips line I and a screen is displayed
If you skip the I screen, a screen is displayed.
I Ctrl + B jump back to the I screen and a screen is displayed
B. One screen is displayed after one screen is jumped back.
Q or Q releases more
= Display the current row number
V edit the current file editor from the current row by Environment Variables
$ Editor Definition
H. display help information
I/mode: searches forward until the first time in the mode appears. A screen is displayed starting from the last two rows of the row.
In searches forward until the first time in the previous mode appears. A screen is displayed starting from the last two rows of the row.
Single quotes return to the start point of the last search. If there is no search, return to the start position.
! Command to activate an SH to execute the specified command
I: N: jump to the next I file. If it does not exist, jump to the last file.
: F displays the current file name and row number
: Q or: Q launches more
. (Point) Repeat the previous command
[Example]:
After the more-C + 50 file is cleared, the file will be displayed from line 3
More-S-W file1 file2 file3 display file file1 file2 file3

1.9 CP

[Syntax]: CP [-p] [-R] File 1 [file 2...] Target
[Description]: Set file 1 (file 2 ...) if the object is a file name, only one file can be copied. if the object is a directory, multiple files can be copied, if the target file does not exist, create this file. If yes, overwrite the previous content. If the target file is a directory, copy the file to this directory.
-I will prompt when overwriting an existing file. If the answer is Y, overwrite the existing file. If the answer is Y, stop overwriting.
-P not only copies the file content, but also the modification time, access mode, access control table, but does not copy
UID and GID
-R if the file name is a directory, copy all the files and subdirectories and their files in the directory.
The target must be a directory.
[Example]:
CP file1 file2 copy file file1 to file file2
CP file1 file2/tmp: Copy file1 and file2 to the/tmp directory.
CP-r/tmp/mytmp copy all files and Their subdirectories under the/tmp directory to the/mytmp directory

1.10 videos

[Syntax]: MV [-F] [-I] File 1 [file 2...] Target
[Note]: Move a file to the target. If the target is a file name, it is equivalent to renaming the file.
-I will prompt when overwriting an existing file. If the answer is Y, overwrite the existing file. If the answer is Y, stop overwriting.
-No prompt before F Overwrite
[Example]:
MV file1 file2 rename file file1 to file2
MV file1 file2/tmp move the file file1 and file file2 to the directory/tmp

1.11 RM

[Syntax]: Rm [-F] [-I] file...
Or Rm-R [-F] [-I] directory name... [file]
[Description]: Used to delete files or directories.
-F do not prompt when deleting the file
-R recursively deletes directories and all their subdirectories.
-I Prompt before deleting the file
[Example]:
Rm file1 delete file file1
Rm-I/tmp/* Delete all files under the/tmp directory
Rm-r/mytmp recursively Delete the directory/mytmp

1.12 chmod

[Syntax]: chmod [-R] mode file...
Or chmod [ugoa] {+ |-| =} [rwxst] file...
[Note]: changes the file access mode. The access mode can be expressed as a number or a symbol string, for example:
Chmod NNNN file, where n is a number ranging from 0 to 7, has the following meanings:
4000 uid can be changed during runtime
2000 GID can be changed during runtime
1000 stick position
0400 file master readable
0200 file master writable
0100 file master executable
0040 readable for users in the same group
0020 users in the same group can write
0010 users in the same group can execute
0004 other user readable
0002 other users can write
0001 Executable by other users
NNNN is obtained by adding the numbers in the upper column. For example, chmod 0777 file sets the file access permission to readable and executable by all users.
-R recursively changes the access mode of all files in all subdirectories.
U file master
G same group users
O other users
A All Users
+ Added the post-column permission.
-Cancel the post-column permission
= Post-column permission
R readable
W writable
X executable
UID can be set during s operation
T indicates that GID can be set during running.
[Example]:
Chmod 0666 file1 file2 sets file1 and file2 as readable and writable for all users
Chmod U + X file adds the file master executable permission to the file
Chmod o-rwx cancels all permissions of other users on file

1.13 chown

[Syntax]: chown [-R] File master file...
[Note]: The file uid indicates the file master. The file master can be represented by numbers or a valid user name. This command changes the UID of a file, only when the file master or super user of this file is available.
-R recursively changes the access mode of all files in all subdirectories.
[Example]:
Chown Mary file: Change the file master to Mary.
Chown 150 file: Change the file UID to 150

1.14 chgrp

[Syntax]: chgrp [-R] File Group...
[Note]: the GID of a file indicates the file group of the file. The file group can be represented by numbers or a valid group name. This command changes the GID of a file. For more information, see chown.
-R recursively changes the access mode of all files in all subdirectories.
[Example]:
Change the file group of the file to group.

1.15 CMP

[Syntax]: CMP [-L] [-S] File 1 file 2
[Description]: Compares two files. If file 1 is "-", standard input is used. If the two files are the same, no prompt is displayed, different characters indicate the number of the first character and the row number.
-L display the number of bytes (in decimal format) and the number of different bytes (in octal format)
-S: No prompt, only return code
[Example]:
CMP file1 file2 comparison files file1 and file2
CMP-l file1 file2 compares the differences between file1 and file2.

1.16 diff

[Syntax]: Diff [-be] File 1 file 2
[Note]: This command compares two text files and displays different columns.
-B converts a string of spaces or tabs into a space or tab.
-E generates an editing angular, which can be used as the input for ex or Ed to convert file 1 to file 2.
[Example]:
Diff file1 file2
Diff-B file1 file2
Diff-e file1 file2> edscript

1.17 WC

[Syntax]: WC [-LWC] file...
[Description]: number of rows, characters, and characters in the statistical file. If no file is specified, the statistical standard input is used.
-L only count the number of rows
-W only count words
-C: Count only characters
[Example]:
WC-l file1 file2 the number of lines in the file1 and file2 statistical files

1.18 split

[Syntax]: Split [-N] [file [name]
[Description]: Split Splits a specified large file into several small files. Each file has n lines (1000 by default). The first small file name is the specified name followed by AA, until ZZ, the default value is X. If a large file name is not specified, standard input is used.
[Example]:
Split-500 largefile little
Write the file largefile into one file in every 500 lines. The first file name is littleaa.

1.19 touch

[Syntax]: Touch [-AMC] [mmddhhmm [YY] file...
[Description]: changes the access time and modification time of the specified file. If the specified file does not exist, it is created. If no time is specified, the current time is used, the returned value is the number of objects that fail to change the time, including objects that do not exist but cannot be created.
-A only changes the access time
-M: only change the modification time
-C if the file does not exist, do not create it and do not prompt
Mmddhhmm [YY] Two represents the month, day, And hour [year]
[Example]:
Touch File
File Update Time
Touch 0701000097 Hongkong
Change the file Hongkong time to July 1 00:00

1.20 File

[Syntax]: file [-F file name file] file...
[Note]: file is used to test the specified file. Try to guess the file type and display it.
-F: The file name is a text file that contains the file name.-F option Test
Files listed in file names
[Example]:
File * displays the types of all files in the current directory.

1.21 pack

[Syntax]: Pack file...
[Note]: Pack dumps the specified file into a compression format, and adds ". Z" after the file name. The file access mode, access time, and modification time remain unchanged.
[Example]:
Pack largefile compresses largefile and dumps it to largefile. Z.

1.22 pcat display compressed files

[Syntax]: pcat file...
[Note]: pcat displays compressed output files

[Example]:
Pcat largefile. Z displays the largefile before compression.
Pcat largefile. z> oldfile displays the compressed laregfile and redirects it
File oldfile

1.23 unpack

[Syntax]: unpack file...
[Note]: Decompress the compressed file and dump it to the format before compression.
[Example]:
Unpack largefile. Z decompress the compressed file largefile. Z and then dump it to largefile.

1.24 find

[Syntax]: Find path name... expression
[Note]: The find command recursively traverses each file and subdirectory in the specified path to see if the file can make the expression value true. The following n represents a decimal integer, and + N represents printing n, -N indicates less than n. The following is a description of valid expressions:
-The name of the file in name mode matches the pattern to true, (/is a specifier)
-Perm [-] If the eight-digit file access mode is the same as the eight-digit file access mode, the file is saved if the "-" option is available.
The bitwise mode contains the octal number. The specified bitwise mode is true.
-Size N [c] if the length of the file block is N, it is true (one block is 512 bytes). If
If the C option is available, the object's byte length is N.
-Atime N: true if the last file access time is n days ago,
The find command changes the access time of the directories it accesses.
-Mtime N: true if the last modification time of the file is n days ago
-Ctime N: true if the file status changes n days ago
-Exec command {}/; if the return value of the command is 0, it is true. {} contains the command parameter,
This command must end /;
-OK command {}/; is the same as exec. It is only prompted before the command is executed. If
Run the command to Answer Y.
-Print: display the output to make the expression true file name
-Newer files: if the file access time is longer than the file specified by newer
-Depth first drops to the subdirectory of the search directory before it reaches its own
-Mount: only find the file system that contains the specified directory.
-The local file is true in the current file system.
-If the type C file type is C, it is true. The value C can be B (Block file) C (character file)
D (directory) L (symbolic link) P (Named Pipe) f (common file)
The/(expression/) expression is true.
-True when the number of links n file links is n
-The user is true when the file belongs to the user. The user can use numbers to indicate uid.
-Nouser: It is true when the file does not belong to a user in/etc/passwd.
-The group file group is true when a file belongs to a file group. A number can be used to indicate a GID.
-Nogroup: It is true when the file does not belong to a group in/etc/group.
-Fstype: true when the file system type to which the file belongs is specified
-Inum N: true when the node number of the file is n
-Prune: When the directory name matches the pattern, no subdirectories are searched.
You can use logical operators to concatenate simple expressions into complex expressions.
Logical operators! Indicates a non-operation.-O indicates an operation. If two expressions are used together,-O indicates an operation.
And operations
[Example]:
Find/-name find *-print
Search for the file name such as find * from the root directory and display it
Find./-exec sleep {1}/;-print
Displays a file in the current directory per second
Find $ home/(-name A. Out-o-name '*. o'/)-atime + 7-exec RM {}/;
Search from the $ home directory and delete all files named A. out or *. o that were accessed seven days ago.

1.25 grep

[Syntax]: grep [Option] mode [file...]
[Note]: searches for the mode in the specified file and displays all rows containing the mode. The mode is a regular expression. When using a regular expression, it is best to enclose it in single quotes ('). If the specified file is the default value, standard input is used. The regular expression can be:
. Match any character
* Match 0 or more * characters before
^ Match the beginning of a row
$ Match the end of a row
[] Matches any character in []. [] indicates the range,
For example, [A-Z] indicates any one of the letters A to Z.
/Conversion character
The options in the command are:
-B: displays the block number.
-C only displays the total number of lines in the mode in each specified file
-Uppercase and lowercase letters in I Mode
-H does not display the file name in the include mode on this row.
-L only display the file name in the include Mode
-N: row number of the row in the display mode
-S: if the specified file does not exist or is unreadable, no error message is displayed.
-V: Display All rows that do not contain the Mode
[Example]:
Grep 'good' * search all files for rows containing the string 'good'
Grep '^ myline' mytext searches myline strings at the beginning of the mytext file.

1.26 vi

[Syntax]: VI [-wn] [-R] file...
[Note]: VI is a full-screen editor based on the line editor ex. All commands of ex and Ed can be used in VI, in the VI option, "-WN" indicates that the size of the editing window is set to N rows, and "-R" indicates that the edited file is set to read-only. The vi working mode is divided into command mode and input mode, in command mode, you can enter the VI command and edit the text to be edited when entering input mode, the command a I I o C S R can enter the input mode. In the input mode, Press ESC to bring the input mode back to the command mode. In the command mode, enter: command, you can enter the ex mode, and a prompt is displayed at the bottom of the screen: at this time, you can use any ex command, the bottom line of the screen is also used /? ! Command Prompt line. Most commands can be preceded by a number, indicating the number of times the command is repeated. The following briefly introduces the VI command set, ^ represents (CTRL) Key.
^ B returns to the previous page. Adding a number to the previous page indicates the number of duplicates.
Retain the two rows of the previous page
^ D in command mode, it indicates half of the rolling screen. In input mode, it indicates rolling back
Auto indent on the left
^ E display the line below the screen bottom line
^ F indicates the number of duplicates on the previous page.
Retain the two rows of the previous page
^ G: displays the current file name, the current row number, and the total number of lines of the file.
Location in the entire file
^ H (unspace) in command mode, the cursor moves one cell to the left; in input mode, delete the previous character
^ I (Tab) generates a string of spaces in input mode.
^ J (LF) move the cursor down a row
^ L refresh the screen to re-display the screen
^ M (Press ENTER) in command mode, move the cursor to the beginning of the downstream
Open up a new line in input mode
^ N move the cursor down a row
^ P move the cursor up a row
^ In input mode, Q inserts the non-printable character after it into the body.
^ R refresh the screen
^ U the screen is rolled in half. Adding a number in front of the screen indicates the number of rows to be rolled up.
The subsequent ^ d ^ U command is valid.
^ V in input mode, insert the non-printable character after it as the body
^ W enables the cursor to return a word in input mode
^ Y displays the line above the screen bottom line
^ Z pause editing and return to the Upper Shell
^ [(ESC) Exit input mode and return to command mode
! Temporarily exit editing and execute shell commands
Double quotation marks (double quotation marks) are used to mark the famous buffer. Serial number buffer 1-9 is used to save the deleted body, word
The parent name buffer zone A-Z is used to store the custom body.
$ Move the cursor to the end of the current row. Adding a number before the cursor indicates moving the row forward, for example, 2 $ indicates moving
To the end of the next row
% Move the cursor to the paired parentheses () or braces {}
(Return the beginning of the sentence
) Forward to the beginning of a sentence
-Return to the first non-space character in the previous line
. Repeat the last command to change the buffer content
/Mode: Forward search mode. move the cursor to the appearance of the mode. The mode is a regular
Expression (see grep)
: At the bottom of the screen, you can use the ex command.
? The function is the same as/, but the direction is forward lookup.
[[Move the cursor back to the boundary of the previous section
/Specifier
] Move cursor forward to the section boundary
^ (Not CTRL) move the cursor to the first non-empty character in the current row
'Two consecutive ''' indicates that the cursor is moved to the position before it is moved, 'followed by a letter indicates the cursor word
The beginning of the line marked by the mother (refer to the M command)
A inserts the body at the end of a row into the input mode.
B. move the cursor back to a word.
C. Content after replacing the cursor
D. Delete the content after the cursor.
E move the cursor to the end
The F character searches for the specified character on the left of the current line.
G move the cursor to the row specified by the number before it, and move to the last row if not specified
H move the cursor to the top line of the screen. If there is a number in front, move it to the number on the screen.
Specified row
I insert the body at the beginning of a row
J connects two rows. If there is a number in front, the row specified by the number is connected.
L move the cursor to the bottom line of the screen. If there is a number in front, move the cursor to the bottom line of the screen to count this
Row specified by number
M move the cursor to the midline of the screen
N use mode lookup/or? Find the next matching pattern again, but the direction is consistent with the previous
N, but in the opposite direction.
O open up a new line on the current line
P inserts the last deleted body into the front of the cursor. You can add a buffer number before it to compile
1-9 is used to save the deleted body. The letter name buffer zone A-Z is used for user-defined storage.
Text
Q from VI to the ex command status
R replacement string
S replaces the entire line
T character to search for characters on the left
U restores the current row to the status before the first modification
W move cursor to the next beginning
X Delete the character before the cursor
Y saves the current row to the Untitled buffer zone. The preceding number indicates the number of rows to be saved.
Name Buffer to save. You can use the command P or P to retrieve it later.
Log on to the ZZ disk and exit VI.
Insert body after a cursor
B. move the cursor back to the beginning.
CW replaces the current word
C) Replace the current sentence
DW deletes a word
Dd deletes a row
E move the cursor to the end of the next word
The F character looks forward to the current row.
H move the cursor to the left
I insert the body before the cursor
J move the cursor down a row
K move the cursor up a row
L move the cursor one cell to the right
The M letter marks the current row with a letter. In the future, use the 'letter to move the cursor to the current row,
(Refer to the 'COMMAND)
N repeat the previous // or? Command
O open up a new line under the current row
P place the user buffer content at the cursor position (see the p command)
R replaces the current character
S replaces the current character with a string of characters
T character cursor move to before character
U cancels the last operation
W move the cursor to the next line
X Delete the current character
YW saves the current word to the unnamed buffer zone. "X" can be added to the front to indicate the name of X.
The buffer zone (X is a-z). You can add numbers to indicate the number of words stored in the buffer. In the future, you can use P or P.
Retrieve
YY saves the current row to the unknown buffer. For usage, see YW
{Move the cursor to the beginning of the previous paragraph
| Move the cursor to the beginning of the row. If a number is added to the front of the row, move it to the beginning of the row specified by the number.
} Move the cursor to the beginning of the next section.
At the prompt, Common commands are as follows:
: W current file storage disk
: W! Forced disk storage
: W file writes content to the specified file
: W! File forced write to the specified file
: X, y w file writes lines X to Y to the specified file
: R file reads the file to the cursor position
: R! Command to read the output of the system command to the cursor position
: Q: Exit editing.
: Q! Force exit
: X is the same as the command ZZ.
: E file name Edit another file
: E! Re-edit the file and discard any changes
: Sh, execute SH, and return to edit
:! Run the command and return to edit
: N: edit the next file
: N file table redefinition file table to be edited
: Set sets VI options. For example, set nu indicates that the row number is displayed before each row.
If no is added, this option is cleared. For example, set Nonu indicates that the row is not displayed before each row.
And the following are some common options:
Automatic AI indent
Aw automatically saves the disk before editing the next file
The IC is case insensitive when searching strings.
Nu displays the row number before each row
SM input) and} are matched (or {
Delayed screen refresh during slow insertion
WS enables searching to bypass the end of a file and start from the beginning
Wa does not check the file before writing it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.