Common commands in Linux (1) and Common commands in linux

Source: Internet
Author: User
Tags clear screen printable characters line editor

Common commands in Linux (1) and Common commands in linux

Address:Http://www.cnblogs.com/archimedes/p/linux-commands1.html, Reprinted, please specify the source address.

Ls command

Ls is used to list the contents of a directory. It is one of the most commonly used commands. The format of ls is as follows:

Ls [Option] [directory name or file name]

Main parameters:

. Options Main Parameters
-A, -- all: Do not hide any items starting with the "." character.
-A, -- almost-all: list any projects except "." and.
-- Author: prints the author of each file.
-B, -- escape: an octal overflow sequence to indicate non-printable characters.
-- Block-size = size: the block is in the specified bytes.
-B, -- ignore-backups: do not list any ~ The project whose character ends.
-F: No sorting is performed. The-aU parameter takes effect and the-lst parameter is invalid.
-F, -- classify: add the file type indicator (*/= @ | one of them ).
-G: like-l, but do not list owner.
-G, -- no-group: inhibit display of group information.
-I, -- inode: List inode numbers of each file.
-I, -- ignore = style: do not print any items that match the Shell universal character.
-K: -- block-size = 1 K.
-L: Used to list information in a long format.
-L, -- dereference: when the file information of the symbolic link is displayed, the object indicated by the symbolic link is displayed, not the information of the symbolic link itself.
-M: All items are separated by commas (,) and the whole row width is filled.
-N, -- numeric-uid-gid: similar to-l, but list UID and GID.
-N, -- literal: List unprocessed project names, for example, not specially processed control characters.
-P, -- file-type: add the file type indicator (/= @ | one of them ).
-Q, -- quote-name: Enclose the project name in double quotation marks.
-R, -- reverse: in reverse order.
-R, -- recursive: Lists All Sub-directory layers at the same time.
-S, -- size: Order the block size.

When using the ls command, there will be several different colors, in which Blue indicates a directory, Green indicates an executable file, red indicates a compressed file, and light blue indicates a linked file, the bold black indicates the symbolic link, and the gray indicates other format files ,:

The most common use of ls is ls-l ,:

The start of the file type is a string consisting of 10 characters. The first character indicates the file type. It can be one of the following types:

-(Common files), d (directory), l (symbolic link), B (Block device files), and c (character device files ). The following nine characters indicate the object access permissions. They are divided into three groups, each with three characters.

The first group indicates the permissions of the file owner, the second group indicates the permissions of users in the same group, and the third group indicates the permissions of other users.

The three characters in each group indicate the read (r), write (w), and execution permission (x) of the object respectively ). For a directory, it indicates the access permission. S indicates that when the file is executed, the UID or GID of the file is assigned to the UID (User ID) or GID (group ID) of the execution process ). T indicates that the flag is set (left in memory and not swapped out ). If the file is a directory, the files in the directory can only be deleted by the Super User, directory owner, or file owner. If it is an executable file, after the file is executed, the pointer pointing to its body segment remains in the memory. In this way, the system will be able to mount the file more quickly when you execute it again. The file size, generation time, file or command name is displayed.

Pwd and cd commands

Pwd is used to display the absolute path of the current working directory. Format: pwd

Cd is used to change the working directory. The format is cd.

Mkdir command

Used to create a new directory in the format:

Mkdir [Option] Directory Name

Role: The mkdir command is used to create a subdirectory named dirname. Similar to the md command in ms dos, the command has the permission to use all users.

[Option] Main Parameters
-M, -- mode = mode: Set permissions, similar to chmod.
-P, -- parents: Create the upper-level directory when necessary. If the directory already exists, it is not treated as an error.
-V, -- verbose: information is displayed every time a new directory is created.
-- Version: displays the version information and leaves.

Cp command

Function: copy a file or directory.
Note: The cp command is used to copy files or directories. If you specify more than two files or directories at the same time, and the last destination is an existing Directory, then it copies all the previously specified files or directories to this directory. If multiple files or directories are specified at the same time, but the last destination is not an existing Directory, an error message will appear.
Parameters:
-A or -- archive: the effect of this parameter is the same as that of the "-dpR" parameter.
-B or -- backup deletes and overwrites the destination file. The backed up file or directory is also established as a symbolic link and points to the source file or directory link. If this parameter is not added, if a symbolic link is encountered during the copy process, the source file or directory will be copied directly.
-F or -- force forcibly copies a file or directory, regardless of whether the target file or directory already exists
-I or -- interactive ask the user before overwriting the file
-L or -- link creates a hard link to the source file instead of copying the file.
-P or -- preserve retains the attributes of the source file or directory, including the owner, group, permission, and time.
-P or -- parents retains the path of the source file or directory. This path can be an absolute or relative path, and the target directory must already exist in
-R recursive processing: processes the files in the specified directory along with subdirectories. If the source file or directory does not belong to a directory or symbolic link, it will be treated as a normal file.
-R or -- recursive processing, which processes the files and subdirectories under the specified directory together
-S or -- symbolic-link creates a symbolic link to the source file instead of copying the file.
-S <backup suffix string> or -- suffix = <backup suffix string> after you use the "-B" parameter to back up the target file, a backup string is added at the end of the backup file. The default backup suffix is a symbol "~ "
-U or -- update: After this parameter is used, the file will be copied only when the source file's Modification Time (Modification Time) is newer than the target file, or the target file with the corresponding names does not exist.
-V or -- verbose displays the execution process
-V <backup mode> or -- version-control = <backup mode> specifies the naming method of the backup file name when the backup file is created. The following three methods are available:
1. numbered or t, the backup number will be used, and ~ will be added at the end of the word ~ 1 ~ String, whose numbers are incremented in turn
2. simple or never will use simple backup. The default backup character string is ~, You can also use-S to specify
3. existing or nil will use the current method. The program will first check whether there is a backup number. If yes, the backup number will be used. If not, a simple backup will be used.
-X or -- one-file-system: the file system in which the file or directory is copied must be the same as the file system in which the cp command is executed; otherwise, the file system will not be copied, files in other partitions are not processed.
-- Help displays online help
-- Sparse = <> set the time to save the xishu File
-- Display version

Example:
. Copy the file. The file is copied only when the source file is modified later than the target file.
Cp-u-v file1 file2

. Copy file file1 to file file2
Cp file1 file2

. Copy file file1 to file file2.
Cp-I file1 file2

. Copy the file file1 to file2. Because the target file already exists, use the forced copy mode.
Cp-f file1 file2

. Copy the directory dir1 to the directory dir2
Cp-R file1 file2

. Copy the file file1, file2, file3, and directory dir1 to dir2.
Cp-R file1 file2 file3 dir1 dir2

. File attributes are retained during replication.
Cp-p a.txt tmp/

. The directory structure of the file is retained during replication.
Cp-P/var/tmp/a.txt./temp/

. Backup files generated during replication
Cp-B a.txt tmp/

. The backup file is generated during replication ~ 1 ~ Format
Cp-B-V t a.txt/tmp

. Specifies the tail mark of the backup file
Cp-B-S _ bak a.txt/tmp

Mv command

Purpose:
The mv command is used to rename a file or directory, or move the file from one directory to another. Its permission is granted to all users. This command is like a combination of ren and move in the doscommand.
Format:
Mv [options] source file or directory, target file or directory
[Options] main parameters:
-I: interactive operation. If the mv operation will overwrite the existing target file, the system will ask whether to rewrite the file and ask the user to answer "y" or "n" to avoid overwrite the file by mistake.
-F: Disable interactive operations. When an mv operation overwrites an existing target file, no indication is given. If this parameter is specified, the I parameter will no longer work.
Application instance:
(1) Rename the file test. c to test1.c:
$ Mv test. c test1.c

(2) Move the test1.c file to the Ccode Folder:
$ Mv test1./Ccode

Rm command

Rm is a common command used to delete one or more files or directories in a directory. It can also delete all files and subdirectories in a directory. For linked files, only the links are deleted, and the original files remain unchanged.

Rm is a dangerous command. Be careful when using it, especially for beginners. Otherwise, the entire system will be destroyed in this command (for example, in the/(root directory) run rm *-rf ). Therefore, before executing rm, we 'd better first check which directory we are in and what we want to delete and keep a high degree of clarity during operations.

1. Command Format:

Rm [Option] file...

2. command functions:

Delete one or more files or directories in a directory. If the-r option is not used, rm will not delete the directory. If you use rm to delete a file, you can restore it to its original state.

3. command parameters:

-F, -- force ignores non-existing files and never gives a prompt.

-I, -- interactive for interactive Deletion

-R,-R, -- recursive indicates that rm recursively deletes all directories and subdirectories listed in the parameter.

-V, -- verbose detailed display steps

-- Help: displays the help information and exits.

-- Version: Output version information and exit

Instance:

To delete the file test, the system will first ask whether to delete it.

Delete all files in sub-directories and sub-directories of projects

Cat command

The cat command is used to connect files or standard input and print. This command is often used to display the file content, connect several files, or read and display the content from the standard input. It is often used with the redirection symbol.

1. Command Format:

Cat [Option] [file]...

2. command functions:

Cat has three main functions:

(1) display the entire file at one time: cat filename

(2) create a file from the keyboard: cat> filename can only create new files, but cannot edit existing files.

(3) Merge several files into one file: cat file1 file2> file

3. command parameters:

-A, -- show-all is equivalent to-vET.

-B, -- number-nonblank: number of non-empty output rows

-E is equivalent to-vE.

-E, -- show-ends is displayed at the end of each line $

-N, -- number indicates the number of all rows output, starting from 1.

-S, -- squeeze-blank has more than two rows of blank rows in a row.

-T is equivalent to-vT.

-T, -- show-tabs: display the Skip character as ^ I

-U (ignored)

-V, -- show-nonprinting use ^ and M-reference, except LFD and TAB

 


Common commands in linux

Just write it.
Common linux commands (BASICS)

1. man provides help explanations for familiar or unfamiliar commands

For example: man ls, you can view the ls-related usage.

Note: Press q or ctrl + c to exit. in linux, you can use ctrl + c to terminate the current program.
2. ls view the directory or file owner * and list the files under any directory

Eg: ls/usr/man

Ls-l

A. d indicates directory. If it is a "-", it indicates a file. If it is l, it indicates a connection file (link)

B. Permission for file or directory permission. Read (r), write (w), and run (x) respectively ).

3. Copy files using cp

Eg: cp filename1 filename2 // copy filename1 to filename2

Cp 1.c netseek/2.c // copy 1.c to the netseek directory and name it 2.c.

4. rm delete files and directories

Eg: rm 1.c // Delete the. c file.

5. Remove the directory or change the file name.

Eg: mv filename1 filename2 // rename filename1 to filename2

Mv qib. tgz ../qib. tgz // move to the upper-level directory

6. Change the current directory pwd on cd to view the complete path of the current directory

Eg: pwd // view the current directory path

Cd netseek // enter the netseek directory

Cd // exit the current directory

7. cat, more command

Displays the content of a file. The two commands are different: cat prints the file content all the time, and more is displayed on the split screen.

For example; cat> 1.c // You can paste the code into the. c file and press ctrl + d to save the code.

Cat 1.c or more 1.c // you can view the content in it.

Gcc-o 1 1.c // compile 1.c into the. exe file. We can compile the Code with this command.

8. Modify the chmod command permission usage: chmod one-digit octal number filename.

Eg: chmod u + x filenmame // you only want to run the command for yourself.

// U indicates the file owner. g indicates the group of the file. O indicates others; r table readable; w table writable; x table can run

Chmod g + x filename // the same group of people to execute

9. clear, date command

Clear: clear screen, equivalent to cls in DOS; date: displays the current time.

10. mount a hardware device

Usage: mount [parameter] device load point to be loaded

Eg: mount/dev/cdrom

Cd/mnt/cdrom // enter the cd directory

11. su switches to another person's identity without logging out.

Usage: su-l user name (if the user name defaults, the user name is switched to the root state)

Eg: su-l netseek (switch to the netseek user and the user will be prompted to enter the password)

12. whoami, whereis, which, id

// Whoami: confirm your identity

// Whereis: queries the directory where the command is located and the directory where the help document is located

// Which: query the directory where the command is located (similar to w ...... the remaining full text>

What are common commands of vi in linux?

[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 A I I o O c s 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, and 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" means to move the cursor to the position before it moves, "followed by a letter means 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? , Repeat ...... the remaining full text>

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.