First glimpse of Linux my most commonly used 20 command summary _linux

Source: Internet
Author: User
Tags bz2 chmod

People who have played Linux will know that there are many commands in Linux, but people who have played Linux never bother because Linux commands are so much, because we only need to master the commands we use most often. Of course, you can also use to find a man, he will help you solve a lot of problems. However, everyone is playing Linux for different purposes, so they often use the command is very big difference, and I mainly use Linux for C/s + + and Shell program written, so the command can be used to be different from a person who manages the Linux system. Because do not want to use is always East search west, so in this summary, to facilitate the future view. Not much, let's talk about my most popular Linux commands.

1. CD command

This is a very basic, but also often need to use the command, it is used to switch the current directory, its parameters are to switch to the directory path, can be absolute path, can also be a relative path. Such as:

Cd/root/docements # Switch to directory/root/docements 
CD./path     # Switch to the path directory in the current directory, "." Represents the current directory  
CD. /path     

2, ls command

This is a very useful view of the file and directory of the command, the list of meaning, it has a lot of parameters, the following list some of my commonly used parameters, as follows:

-L: Lists Long data strings containing file attributes and permission data-a 
: Lists all of the files, together with the hidden file (the file at the beginning of.)- 
D: Lists only the directory itself, not the file data for the directory- 
H : Document capacity is listed in a more readable manner (GB,KB, etc.) 

Note: These parameters can also be used in combination, and here are two examples:

Ls-l #以长数据串的形式列出当前目录下的数据文件和目录 

3. grep command

This command is often used to parse a line of information, if it has the information we need, to display the line, which is usually used with the pipe command, to filter the output of some commands, and so on, its simple syntax is

grep [-ACINV] [--color=auto] ' Find string ' filename

Its common parameters are as follows:

-A: To find the binary file as a text file- 
c: Calculate the number of "find string"-I 
: Ignore case difference, that is, the case is the same as 
 # for example: 
# Remove the Manpath line from the file/etc/man.config and add color to the Found keyword 
grep--color=auto ' Manpath '/etc/man.config 
# put LS The output of-L contains the letter file (case-insensitive) content output 

4. Find command

Find is a very powerful command based on lookup, which is relatively complex and has a lot of parameters, so here's a list of them, and its basic syntax is as follows:

Find [PATH] [option] [action]  

 

5, CP command

This command is used to copy files, copy, and it can copy multiple files to a directory at once, and its common parameters are as follows:

-A: Copying the attributes of a file, together with the 
attributes of a file, instead of using the default method, similar to-a, is commonly used for backup-I 
: If the target file already exists, it will ask for the action when it is overwritten- 
R: Recursive continuous Replication for directory replication behavior 

For example:

Cp-a file1 file2 #连同文件的所有特性把文件file1复制成文件file2 

6, MV Command

This command is used to move a file, directory, or name change, and its common parameters are as follows:

-f:force the meaning of coercion, if the target file already exists, will not ask and directly overwrite- 
I: If the target file already exists, it will ask if the overwrite 

Note: This command can move a file or multiple files one folder at a time, but the last target file must be "directory".

For example:

MV File1 file2 file3 dir # moving files file1, file2, file3 to directory dir 

7. RM command

This command is used to delete files or directories, and the common parameters of the Remove are as follows:

-F: That's what force means, ignoring files that don't exist, no warning messages.-I 
: interactive mode, asking the user for action before deleting 

For example:

Rm-i file # Deletes files and asks for the action before deleting 

8. PS command

This command is used to select and output the process running at a point in time, and its common parameters are as follows:

-A: All processes are displayed.- 
A: All processes not related to terminal- 
u: Related processes for valid users- 
x: Typically used with A parameter to list more complete information 

In fact, we just remember that PS commonly used in the command parameters to match, they are not many, as follows:

PS aux # View system All process data 
PS Ax # View all processes not related to terminal 
Ps-la # View all process data for the system 

9. Kill command

This command is used to send a signal to a work (%jobnumber) or to a PID (number), which is usually used in conjunction with the PS and Jobs commands, and its basic syntax is as follows:

 
 

The common parameters of signal are as follows:

Note: The first number is the signal code, the use of the code can be used to replace the corresponding signal.

1:sighup, start the terminated process 
2:sigint, equivalent to input CTRL + C, interrupt the 9:sigkill of a program 
, force the interruption of a process 
15:sigterm, terminate the process in the normal way to end the process 

For example:

# in the normal end of the process to finally the first background work, you can use the Jobs command to view the background of the first worker process 
kill-sigterm%1  
# re-change process ID PID process, PID can be filtered using the PS command via pipeline command plus grep command 

10, Killall command

The command is used to send a signal to a process that is started by a command, and its general syntax is as follows:

Killall [-iie] [command name]

Its parameters are as follows:

-I: interactive meaning, if you need to delete, ask the user- 
e: Indicates that the command name to be followed is consistent, but command name cannot exceed 15 characters 
# For example: 
killall-sighup syslogd # reboot SYSLOGD 

11. File command

This command is used to determine the basic data for files that are connected to the file command, because the type of file under Linux is not a suffix later, so this command is useful for us, its usage is very simple, the basic syntax is as follows:

File filename

#例如: 

12. Tar command

This command is used to package files, the default is not compressed, and if the appropriate parameters are specified, it also invokes the corresponding compression program (such as Gzip and bzip, etc.) for compression and reconciliation. Its common parameters are as follows:

-C: New package file 
-T: View the contents of the packaged file contains which filename- 
x: Unpack or decompress, you can specify the extracted directory with-C (uppercase), note that-c,-t,-x cannot appear in the same command simultaneously 
-J : Compression/Decompression via BZIP2 support- 
Z: Compression/decompression via gzip- 
V: In the compression/decompression process, the file name being processed is displayed------ 
F Filename:filename 

The above explanation can already make you faint, but usually we just need to remember the following three commands:

Compression: tar-jcv-f filename.tar.bz2 file or directory name query to be processed 
: Tar-jtv-f filename.tar.bz2 

Note: The filename is not set to end with the suffix tar.bz2, this is mainly to illustrate the use of the compression program for BZIP2

13, Cat command

This command is used to view the contents of a text file, followed by the name of the file you want to view, and is usually used in conjunction with more and less, allowing you to view the data page by page. For example:

Cat text | Less # View the contents of the text file 

14, Chgrp command

This command is used to change the group of users to which the file belongs, and its use is simple, and its basic usage is as follows:

CHGRP [-R] Dirname/filename

 
 
e.g. 

15, Chown command

This command is used to change the owner of the file, the same way as the CHGRP command, except that the modified file attributes are different and are no longer detailed.

16, chmod command

This command is used to change the permissions of a file, generally as follows:

chmod [-r] XYZ file or directory

 
 

At the same time, chmod can make changes to the permissions of a file using U (user), G (group), O (Other), a (all), and + (join),-(delete), = (set) with rwx.

# For example: 
chmod 0755 File # changes files permission to-rxwr-xr-x 

18, Vim command

This command is used primarily for text editing, with one or more file names as arguments, and if the file exists, create a file with that file name if it does not exist. Vim is a very useful text editor, it has a lot of very useful commands, there is no more to say here. You can download the detailed instructions for VIM's common operations here.

19. GCC command

For a person using Linux to develop C programs, this command is very important, it is used to the C language source program files, compiled into an executable program, because many of the parameters of g++ is very similar to it, so here only the parameters of GCC, its common parameters are as follows:

-o:output, used to specify the filename to generate an executable file- 
c: Used to generate the source file (. o) and prevent the compiler from creating a complete program-I 
: increase the path to the compile-time search header file- 
l : Increase the path of the compile-time search static connection library- 
s: Generate the source file assembly code file 
-LM: Represents a library of libraries in the directory named LIBM.A function libraries 
-lpthread: Connection NPTL Implementation of the line threading 
# for example: 
# The source file test.c is compiled according to the C99 standard to executable program test 
gcc-o test test.c-lm-std=c99 
#把源文件test. C Convert to the appropriate assembler source file Test.s 

20. Time command

This command is used to measure the execution time of a command (that is, a program). It's very simple to use, just like the input command, but add a time before the command, for example:

Time./process 

After the program or command is run, the final output is three time, respectively:

User: CPU time, the user CPU time for the execution of the command, that is, the total execution time of the command in the user state;

System: CPU time, command execution to complete the cost of the system CPU time, that is, the command in the nuclear mentality of the total execution time;

Real: Actual time, from the command line to start execution to the end of the elapsed time;

Note: The sum of the user's CPU time and system CPU time is CPU time, that is, the total time that the command takes CPU execution. The actual time is greater than the CPU time, because Linux is a multitasking operating system, and often the system handles other tasks while executing a command. Another issue to note is that even though the same command is executed each time, the time spent is different, and the time spent is related to system operation.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.