Build and use a Linux development environment -- Use of common Linux commands

Source: Internet
Author: User
Tags time 0

Build and use a Linux development environment -- Use of common Linux commands
Overview

Many people may have seen similar scenes on television or movies. Hackers face a black screen with dense characters on it. After a click, they have completed the data theft task.


At the beginning of Linux, there was no graphic interface. All the operations were completed by commands, just like hackers on TV, and they were full of mysteries and mysteries.


In recent years, despite the rapid development of Linux and the increasingly friendly graphical interface, Linux Command Line applications still occupy a very important role in the real development process.It can be said that there is no command line, it is not a Linux.


Linux provides a large number of commands that can effectively perform a large amount of work, such as disk operations, file access, directory operations, process management, and file permission settings. There are also more than 200 commands with the least version in Linux. Here we will only describe the most important and frequently used commands.


Command usage

Linux Command Format:
Command [-options] [parameter1]…
Note:
Command: The command name. It is an abbreviation of an English word or word.
[-Options]: option, which can be used to control the command or omitted.
Parameter1... : The parameters passed to the command, which can be zero or multiple

Example: ls-a/home



How to view the help documentation:

1) -- help

It is usually the help information provided by Linux commands. Not all commands contain this option.


For example, we want to view the command ls usage: ls -- help



2) man (find a man with a problem)

Man is a manual provided by Linux. It contains a vast majority of command and function instructions. This manual is divided into many sections. You can specify different sections to view different contents when using man.


The sections in man have the following meanings:
1. Standard commands (Standard command)
2. System CILS (System Call, such as open and write)
3. Library functions (Library functions, such as printf and fopen)
4. Special devices (Device File description, various devices under/dev)
5. File formats (File format, such as passwd)
6. Games and toys (Games and entertainment)
7. Miscellaneous (Miscellaneous, conventions and protocols, such as Linux file system, network protocol, ASCII code, and environ global variable)
8. Administrative Commands (Administrator command, such as ifconfig)


For example, we want to view the ls usage: man 1 ls (1: The number "1", representing 1st sections, Standard Commands)



In fact, we do not need to specify the first few chapters to view them, for example, man ls. However, in this case, if the command name and function name are exactly the same (for example, printf), it is both a command and a library function. If, we do not specify the chapter number, man printf. It only views the command usage and does not query the function usage, because man searches according to the order of the chapter number in the manual.



Therefore, when using the man manual, it is best to specify the chapter number:



Tips

Automatic completion:

When you press the tab key while typing out the first few letters of the command, the system will automatically complete the command.


History commands:
After the system executes some commands, you can press the up or down key to view the previous commands. history lists the executed commands.


Redirection (> ):

The content displayed on the terminal is saved to the specified file.

For example: ls> test.txt (if test.txt does not exist, it is created. If yes, it overwrites its content)



Pipeline (l ):

When we search for a file or folder containing a keyword, pipelines are often used in combination with grep (SEARCH Command.


We can understand the pipe in real life. One end of the pipe is stuffed with something, and the other end is taken out. Here, the left and right sides of the pipe are divided into two ends, the left end is stuffed with something, and the right end is taken.


For example: ls | grep g. ls is originally displayed on the screen and inserted to the left end of the MPs queue. Then, the content is extracted from the right end and the text with the keyword "g" is searched in the content.



Common commands File and disk management:

Ls: displays directory content
-L: list display
-A: displays all files (hidden files start)
-H: in combination with-l, the file size is displayed in a user-friendly manner.


Clear: clear the display on the terminal. You can also use the shortcut key Ctrl + l ("l" is a letter)

Cd: Switch DirectoriesCd/mnt can enter the mnt (specified) Directory
Cd .. you can enter the directory on the previous Layer
Cd-enter the previous directory
Cd ~ You can access the user's home directory (~ : Refers to the home directory. The home directory refers to the user directory in/home, not the pure/home directory)

Pwd: displays the absolute path of the current working directory



Note: If the path starts from the root path, add "/", such as "/mnt", before the path to the folder in a directory, do not add "/" before.


Mkdir: create a directory
-P recursively creates a folder in the specified path



Cat: displays the content of a text file.



Rm: delete a file or directory

-R: This parameter must be added when deleting a folder.
-F: forcibly delete an object



Cp: copy an object

-R: copy a folder
-I: Indicates whether to overwrite duplicate files.
-V: displays the copy progress.


Cp vim_configure/code/-ivr: copy the vim_configure folder to the code directory.



Mv: Move a file or change the file name
-V: displays the movement progress.

Mv file1 file2 file1 renamed file2
Mv vim_configure/code/vim_configure/move to the code directory



Which: view the directory where the command is located



Tar: compression and decompression command

Gzip format (compressed package suffixed with .tar.gz ):

Compression usage: tar cvzf compressed package name file 1 file 2...

C: create, create

V: displays the compression progress.

Z: the format of the specified compressed package is gzip. file.tar.gz

The order of the three parameters is arbitrary. "-" can be added before the parameter, for example,-zcf.

F: file, file,F must be followed by a compressed package file. Therefore, when these four options are used together, f must be placed at the end, such as zxvf.


Example: tar zcvf test.tar.gz 1.c 2.c 3.c 4. c compress 1.c 2.c 3.c 4.c into zcvf test.tar.gz



The above operation can also be written as follows: tar zcvf other.tar.gz *. c (*. c Represents all. c)



Decommission usage: tar zxvf compressed package name

X: Indicates decompression.

Z: the format of the compressed package to be decompressed is gzip format. file.tar.gz

The option sequence is the same as that for creating a compressed package.


Example: extract new.tar.gz from tar zxvf new.tar.gz


In fact, the "z" parameter can be omitted. In this case, extract the compressed package in any format:



Decompress the package to the specified directory:-C (uppercase letter "C ")
Example: tar-xvf new.tar.gz-C./test/decompress new.tar.gz to the test directory in the current directory.



Bz2 format (the zip package suffix is .tar.bz2 ):

The difference is the same as that in gzip format: The bz2 format is specified with the parameter "j ".


Compression usage: tar jcvf compressed package name file 1 file 2...
Example: tar jcvf bk.tar.bz2 *. c

Decommission usage: name of the tar jxvf compressed package
Example: tar jxvf bk.tar.bz2

Decompress the package to the specified directory:-C
Example: tar jxvf bk.tar.bz2-C ./


User and permission management:

If you do not know the file permissions, click "Brief description of Linux File Permissions".


Chmod: Change File Permissions
Two chmod formats are available (letter and number)


Letter method:

Chmod u/g/o/a +/-/= rwx File

[U/g/o/a] Description
U: user indicates the owner of the file.
G: group indicates that the object owner belongs to the same group, that is, the user group.
O: other indicates other persons
A: all indicates that all three are


[+-=] Description
+: Add permissions
-: Revoke permissions.
=: Set permissions

[Rwx] Description
R: read indicates that data can be read.
W: write indicates that data can be written.
X: excute indicates executable


Example:

Chmod o + w file: Add write permissions to other users in the file.



Chmod u-r file: Give the file owner the read permission.



Chmod g = x file: sets the permissions of users in the same group of file files to be executable, while removing the read and write permissions.



Number method:

"Rwx" can also be replaced by numbers.

R: Read Permission, number code: "4"
W: Write Permission, number code: "2"
X: execute or switch the permission. The number is "1"
-: You do not have any permission. The digit code is "0"


For example, run chmod u = rwx, g = rx, o = r filename.
It is equivalent to: chmod u = 7, g = 5, o = 4 filename


Example:

Chmod 751 file
File owner: read, write, and execute permissions
Users in the same group: read and execute permissions
Other users: Execution permission



Chmod 777 file

All users have read, write, and execute permissions



Note: If you want to recursively Add the same permissions to all directories, you need to add the parameter "-R ".

Example: chmod 777 test-R
Apply the 777 permission to all files in the recursive test directory.


System Management

Ps: View System Processes



Ps-a: view all processes of the current user



Ps-e: view all processes in the system



Kill: kill the process with the specified process number and use it with ps.

Kill 9133 9133 is the process number corresponding to the application



Some processes cannot be killed directly. In this case, we need to add a parameter "-9" and "-9" to indicate that the process is forced to end.



Ifconfig: view or configure Nic Information

If we only press "ifconfig", it will display the information of all NICs:


View the information of the specified NIC: ifconfig eth0 ("0" is a number)



Set ip: sudo ifconfig eth0 192.168.31.165

Sudo is a tool that allows system administrators to allow common users to execute some or all of the root commands, reducing the login and management time of root users and improving security.



Ping: test network connectivity

Ping 10.221.0.24 does not stop automatically. Press Ctrl + c to stop.

Ping 10.221.0.24-c 4 "-c" indicates the number of packets sent. Here it is four



Who: view the login user information of the current system
The first column shows the Login User Name
The second column displays the terminal name
The third column shows the logon time.



Exit:
If the graphic interface is used, exit the current terminal.
Log out of your account if you use ssh for remote logon.


Shutdown
Shutdown-h now shut down immediately, where now is equivalent to the status with time 0
Shutdown-h system shutdown at today
Shutdown-h + 10 the system will automatically shut down in 10 minutes


Reboot: restart your computer


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.