[Add to favorites] common Linux commands

Source: Internet
Author: User
Tags disk usage
Common Linux commands

Command

Explanation

Usage

Example

Ls

Display the contents of a directory (Files And Directories)

Usage: ls or ls directory

If LS is left blank, the contents in the face-to-face directory are displayed. You can add the directory path to be viewed after ls.

Ls

Ls/

Ls/home/

Ls/etc/sysconf

Ls-l

Detailed display

Usage: ls-l or LS-l directory

Note: L is a letter, not a number 1.

Ls-l

Ls-L/home

Ls-

Show all files

Usage: ls-A or LS-a directory

The file starting with "." is a hidden file, which is also displayed. Otherwise, it is not displayed.

Ls-

Ls-La/etc/

CP

Copy a file

Usage: CP source file target file

Note: you can add a path name to the file.

CP/home/lion/test1/home/lion/test/Test2

CP-R

Copy the entire directory

Usage: target directory of the original CP-r directory

Note: All files in the directory will be copied.

CP/home/lion/mjli/home/lion/test/mjli2

MV

Move a file or directory

Similar to CP, but the original file or directory does not exist after moving.

Note: The-R parameter is not used to move a directory.

MV/home/lion/test1/home/lion/Test2

MV/home/lion/mjli/home/lion/mjli2

Touch

Create a file

Usage: Touch file name

Touch/home/lion/test1

Mkdir

Create directory

Usage: mkdir directory name

Touch/home/lion/mjli

Rm

Delete an object

Usage: RM file name

Rm/home/lion/test1

Rm-R

Delete directory

Usage: Rm-r directory name

Rm-r/home/lion/mjli2

Rmdir

Delete an empty directory

Usage: rmdir directory name

Note: This directory must be empty; otherwise, it cannot be deleted.

Rmdir/home/lion/mjli2

CD

Change directory path

Usage: CD directory name

CD/etc

CD/home/lion

CD ..

To the directory on the previous Layer

Usage: CD ..

CD ..

CD/

To the root directory

Usage: CD/

CD/

PWD

Display the current directory path

Usage: pwd

PWD

Cat

View File Content

Usage: CAT file name

CAT/home/lion/test1

More

View files with long Content

Usage: more file name

Note: More can be used with other commands, such as LS-L | more

Note: In the display,

Press the Space key to scroll one page, press the Enter key to scroll one line, and press the Q key to exit

Ls-L | more

More/home/lion/Test2

Less

View files with long Content

Similar to more.

In the display, Press Y to scroll up a row

Less/home/lion/Test2

PS aux

View System Processes

Note: It is best to use the aux parameter together.

PS aux

Kill-9

Kill Process

Usage: Kill-9 PID

Note: PID (process ID) can be obtained by the PS aux command

Kill-9 1231

W

Show online user information

Usage: W

Note: It is more detailed than the WHO command.

W

Who

Top

Displays System Task information, including CPU and memory.

Usage: Top

Top

Mesg

Whether to accept write information from others

Usage: mesg y or mesg n

Note: accept is Y, and N is not accept.

Mesg y

Mesg n

Write

Send information to other users

Usage: write user or write user TTY.

Note: tty is used for multiple identical users, which can be obtained by W command.

Write lion

Write lion pts/2

Passwd

Change Password

Usage: passwd

Note: A super user can change the password of another user, which is a passwd user.

Passwd

Du

Displays the disk usage of each file in the directory (including files in subdirectories)

Usage: du directory name

NOTE: If no directory name exists, the current directory is used.

Du

DU/home/lion

Du-S

Displays the size of all files in the directory.

Usage: Du-s directory name

NOTE: If no directory name exists, the current directory is used.

Du-S

Du-S/home/lion

Date

Display System Date and Time

Usage: Date

Date

Uptime

Display System running time

Usage: uptime

Uptime

Clear

Clear current screen

Usage: Clear

Clear

WC

Statistics file, indicating the number of lines, characters, and characters of the file

Usage: WC file name

WC/home/lion/test1

Grep

Filter text

Used with other commands, such

Ls | grep sring indicates that only the rows with strings are displayed.

Cat file name | grep string indicates that only the rows with strings in the file are displayed.

Ls-L | grep string

CAT/home/lion | grep hehe

PS aux | grep test1

Grep-n

Filter the text and add the row number before the row.

The user is similar to grep. Just add the parameter.

Ls-L | grep-N string

PS aux | grep-N test1

Grep-V

Filters text and lists rows that do not contain a given string.

The user is similar to grep. Just add the parameter.

Ls-L | grep-V string

PS aux | grep-V test1

Grep string-R

Search Text

Usage: grep string-r directory name

Search for lines containing strings in all objects in the given directory

Note: You can also add the-n-V parameter.

Grep string-r/

Grep hehe-r/home/lion

DF

View system hard disk Information

Usage: DF

DF

Free

View system memory information

Usage: free

Free

Ping

Check whether it is connected to the other machine

Usage: ping the IP address or domain name

Ping bbs.ustc.edu.cn

Ping 202.38.64.1

Ifconfig

View System Nic Information

Usage: ifconfig

Note: common users use/sbin/ifconfig

Ifconfig

Ifconfig | more

Route

View System route information

Usage: Route

Note: common users use/sbin/route

Route

Echo

Response content

Usage: Echo string

Note: The result is string.

Echo hello

Echo hehe

Whoami

Displays the username currently in operation

Usage: whoami

Whoami

Exit

Log out of the system

Usage: Exit

Exit

Chmod

See the following description.

CTRL + c

Abort Program Execution

Usage: Ctrl + c

CTRL + c

CTRL + d

Exit System

Usage: Ctrl + d

CTRL + d

Halt

Disable computer

Usage: Halt

Halt

Reboot

Restart the computer

Usage: reboot

Reboot

 

Chmod is used to change the File Permission. In Linux, a file can be read (r) writable (w) executable (x) in three modes, respectively for the owner of the file (onwer), group, and others (other ). If a file is changed to the executable mode, the system regards it as an executable file, and the executable mode of a directory indicates that the user has the right to enter the directory. Chmod is used to change the mode of some files. Its usage is as follows:

Chmod [-R] mode file name

-R: change all subdirectories and files to the mode you want to change.

The mode can be represented by numbers or letters, respectively, as follows:

(1) Number

A three-digit number is given in the order of owner, same-group, and others. R is 4, W is 2, and X is 1, for example, the first digit 7 in 765 indicates that the owner has the R + W + x permission (7 = 4 + 2 + 1 ), the second number 6 indicates that the same group has the R + W permission (6 = 4 + 2 ), the third digit 5 indicates that the other person has the R + x permission (5 = R + x ).

Usage: chmod 765 file name

You can change the number to the required permissions.

(2) Letters

Usage: chmod [Ugo] +/-[rwx] File Name

Example: chmod U + R/home/lion/test1 chmod ug + Rx/home/lion/mjli/hello.com

[] Can appear at the same time, with the following meanings:

+ Or-

R

W

X

U

U + R, u-r indicates that the owner has or cancels the read permission

U + W, U-W indicates that the owner owns or cancels the write permission

U + x, u-X indicates that the owner owns or cancels the executable permission.

G

G + R. G-r indicates that the same group owner has or cancels the read permission.

G + W, G-W indicates that the same group owner or cancelling write permission

G + X, G-X indicates that the same group owner has or cancels the executable permission.

O

O + R and o-r indicate that others have or cancel the read permission.

O + W and o-w indicate that others have or cancel the write permission.

O + X and o-x indicate that others have or cancel executable permissions.

 

Other common features:

 

Explanation

 

 

>

The output is redirected from the screen to the file, and the original content of the file is cleared.

Usage: Command> file name

Note: The command can be the above command, and the file name can have a directory path

Ls-L>/home/lion/lsresult

 

>

The output is redirected from the screen to the end of the file, and the original content of the file is retained.

Similar to>, but the content of the original file is retained.

Ls-L>/home/lion/lsresult

 

<

Input redirection. The file content replaces the keyboard input.

Usage: Command <file name

Note: The command can be the above command, and the file name can have a directory path

WC

|

Connect two commands (the result of the previous command serves as the input of the next command)

Usage: Command | command

Ls-L | more

Ls | grep hello

Ls | WC

.

Current Directory

Usage:./file or directory

Ls ./

CP/home/lion/mjli./test/

..

Previous directory

Usage: ../file or directory

CD ..

CP ../test1./home/lion/

&

Command as a background command

User: Command &

Gw03 Test &

Edit file VI command usage

Mode Conversion:

 

Commands in command mode:

Command

Explanation

Command

Explanation

Save and exit

A

Add after current location

: WQ

Save and exit

I

Insert before current position

: W

Save files

O

Create a new row under the current row

: Q

Exit

O

Create a new row above the current row

: Q!

Exit Without saving the disk

Number g

Jump to the number line (skip to the end of the file if no number exists)

: Set number

Display the number of rows at the beginning of each line

Digit YY

How many rows to copy (when no number exists, copy the cursor row)

H

Move cursor left

Number dd

Number of rows to be deleted (delete the cursor row if no number exists)

J

Move cursor down

P

Paste it under the current row

K

Move cursor up

U

Undo the last command operation (multiple operations can be undone)

L

Move cursor right

D

Delete from the cursor to the end of the row

0

Move the cursor to the beginning of the line

X

Delete current character

$

Move the cursor to the end of the row

X

Delete the previous character

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.