Linux Common Command Daquan

Source: Internet
Author: User

people who have played Linux will know that there are really a lot of commands in Linux, but people who have played Linux have never bothered by the fact that Linux commands are so many, because we only need to master the commands we use most often. Of course you can also use to find the man, he will help you solve a lot of problems. However, everyone's purpose of playing Linux is different, so the commands they often use are very big, and I mainly use Linux for C + + and shell programs, so common commands can be different from a person who manages Linux systems. Because do not want in use is always East search, so summarize here, convenient for later view. Not much, let's talk about my most commonly used Linux commands.  1. cd commandThis is a very basic, is also a common need to use the command, it is used to switch the current directory, its parameters are to switch to the path of the directory, can be an absolute path, can also be a relative path. such as: 
Cd/root/docements # Switch to directory/ROOT/DOCEMENTSCD./path          # Switch to the path directory in the current directory, "." Represents the current directory  CD: /path         # Switch to the path directory in the upper directory, "..." Represents a previous level of directory

2. ls commandThis is a very useful view of the file and directory commands, 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, including file attributes and permission data-A: Lists all the files, together with hidden files (files that begin with.)-D: Lists only the directory itself, not the file data of the directory-H: List the file capacity in a more readable manner (GB,KB, etc.)-R : Listed with the contents of the subdirectory (recursively listed), equal to all the files in that directory will be displayed

Note: These parameters can also be used in combination, the following two examples:

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

 3. grep commandThis command is often used to parse a row of information, if there is information we need, the row is displayed, the command is usually used with the pipeline command, for the output of some commands to filter processing, etc., its simple syntax is [plain] view plaincopyprint?
grep [-ACINV] [--color=auto] ' Find string ' filename

its common parameters are as follows:
-A: Find the binary file as a text file-C: Count the number of occurrences of ' find string '-I: ignore the case difference, that is, the case is the same-V: Reverse selection, that is, the display of the "Find string" content of the line # for example: # Remove the file/etc/ Man.config contains the MANPATH line and adds the found keyword to the color grep--color=auto ' MANPATH '/etc/man.config# the output of Ls-l contains the letter file (case-insensitive) content output ls-l | Grep-i file

4. Find commandFind is a very powerful search-based command, relatively speaking, its use is relatively complex, parameters are also more, so here will be to classify them, its basic syntax is as follows:  
find [PATH] [option] [action]# time-related parameters:-mtime N: = n is a number, meaning a file that has been changed in "One Day" before the nth Day;-mtime +n: Lists the filenames that were changed before n days (without the N-day itself),-mtime-n the name of the file that was changed within n days (including the N-day itself);-newer file: List than fi Le also want a new file name # For example: Find/root-mtime 0 # in the current directory look for files that have changed within today # Parameters related to user or user group name:-user Name: List file owner name for file-group name: List the files to which the user group belongs Name file-uid N: List file owner as User ID n file-gid N: List file belongs to user group for user group ID n File # For example: Find/home/ljianhui-user Ljianhui # in Directory/home/ljianhui Find the file owner for Ljianhui # Parameters related to file permissions and names:-name filename: Find the file named filename-size [+-]size: Find the file that is larger than size (+) or small (-)-tpye TYPE : Find files of type types, the value of type is mainly: General file (f), device file (b, c), directory (d), connection file (L), socket (s), FIFO pipeline file (p);-perm mode: Find file permissions just equal to the text of mode , mode is represented by numbers, such as 0755;-perm-mode: Find file permissions must all include the mode permission of the file, mode with the number of-perm +mode: Find file permissions to contain any mode of the file, mode with the number of # for example: Find /-name passwd # Find file named passwd files find. -perm 0755 # Find file permissions in the current directory of 0755 files found. -size +12k # Find files larger than 12KB in the current directory, note that C represents a byte  

5. CP CommandThis command is used to copy the file, copy the meaning, it can also copy multiple files to a directory at one time, its common parameters are as follows: 
-A: Copy the attributes of a file together with the properties of a file, rather than using the default, similar to-a, commonly used for backup-I: If the destination file already exists, the action is queried for the-R: Recursive continuous replication, for the replication behavior of the directory-U : The destination file does not replicate when it differs from the source file

For example: 
Cp-a file1 file2 #连同文件的所有特性把文件file1复制成文件file2cp file1 file2 file3 dir #把文件file1, file2, file3 copy to directory dir

6. MV CommandThis command is used to move a file, directory, or rename, and its common parameters are as follows: 
-f:force mandatory Meaning, if the target file already exists, will not ask and directly overwrite-I: If the target file already exists, you will be asked whether to overwrite-u: If the target file already exists, and newer than the target file, it will be updated

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 # move the file file1, File2, file3 to the directory dir in MV file1 file2 # Rename the file file1 to File2

7. RM CommandThis command is used to delete files or directories, between remove, and its common parameters are as follows: 
-F: Force means, ignoring nonexistent files, no warning message-I: interactive mode, before the deletion will ask the user whether to operate-r: Recursive delete, most commonly used in directory deletion, it is a very dangerous parameter

For example:
Rm-i File # To delete files, ask if you want to do this before deleting rm-fr dir # forces all files in directory dir to be deleted

8. PS CommandThis command is used to select and output the process run at a point in time, and its common parameters are as follows: 
-A: All processes are displayed as-a: all processes not related to terminal-U: Related processes for active users-x: Typically used with A parameter to list more complete information-L: Longer, more detailed list of PID information

in fact, we just need to remember the general use of PS command parameter collocation can be, 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 system All process data PS AXJF # View together with part of the process tree status

9. Kill commandThis command is used to send a signal to a job (%jobnumber) or to a PID (number), which is typically used with the PS and jobs commands, with the following basic syntax:
Kill-signal PID

the common parameters of signal are as follows:Note: The first number is the signal code, use can be used to replace the corresponding signal code.  
1:sighup, start the terminated process 2:sigint, equivalent to input CTRL + C, interrupt the 9:sigkill of a program, force a process to break the 15:sigterm, to the normal end process to terminate the process 17:sigstop, Equivalent to input CTRL + Z, suspending the progress of a process

For example:
# at the end of the normal process to finally the first background work, the jobs command can be used to view the background of the first worker process kill-sigterm%1 # re-change process ID for the PID process, PID can use the PS command by the pipeline command plus grep command filter to get kill- SIGHUP PID

10. Killall CommandThis command is used to send a signal to a process initiated by a command whose general syntax is as follows:
Killall [-iie] [command name]

it has the following parameters:
-I: interactive meaning, if need to delete, will ask the user-E: to indicate that the command name is consistent, but command name cannot exceed 15 characters-I: Command names ignore case # For example: Killall-sighup syslogd # Restart SYSLOGD

11. File CommandThis command is used to determine the basic data of files after the file command, because the type of the file under Linux is not the suffix of the future, so this command is very useful for us, its usage is very simple, the basic syntax is as follows: 
File filename# For example: file./test

12. Tar commandThis command is used to package the file, which is not compressed by default and, if specified, it also invokes the appropriate compression program (such as Gzip and bzip) for compression and decompression. Its common parameters are as follows:
-C: New packaging file-T: View the contents of the packaged file contains which file name-X: Unpack or unzip the function, you can specify the extracted directory with-C (uppercase), note that-c,-t,-x cannot appear simultaneously in the same command-j: Compression/Decompression with BZIP2 support-Z : Compression/Decompression with GZIP Support-V: During the compression/decompression process, the file name being processed is displayed as-F filename:filename for the files to be processed-C dir: Specify the Compressed/uncompressed directory Dir

The above commentary may have knocked you out of the way, but usually we just need to remember the following three commands:
Compression: tar-jcv-f filename.tar.bz2 file or directory name to be processed query: Tar-jtv-f filename.tar.bz2 extract: Tar-jxv-f filename.tar.bz2-c directory to extract

Note: The file name is not set to end in the suffix tar.bz2, this is mainly to illustrate the use of the compression program for BZIP2 13. Cat CommandsThis command is used to view the contents of a text file, followed by the name of the file to be viewed, and is typically used in conjunction with more and less to allow you to view the data one page at a time. For example: 
Cat text | Less # view content in text file # Note: This command can also use less text instead of

14. Chgrp CommandThis command is used to change the user group to which the file belongs, it is very simple to use, its basic usage is as follows: 
CHGRP [-R] Dirname/filename-r: Persistent changes to all files and subdirectories for example: Chgrp users-r./dir # Recursively change the user group for all files and subdirectories under Dir directory to users

15. Chown Commandthe command is used to change the owner of the file, using the same method as the CHGRP command, except that the modified file attributes are different and are no longer detailed.  16. chmod commandThis command is used to change the permissions of a file, as follows: 
chmod [-r] XYZ file or directory-r: Continuous change with recursion, i.e. all files under subdirectories will change

at the same time, chmod can also use the U (user), G (group), O (Other), a (all) and + (join),-(delete), = (set) with the rwx to make changes to the permissions of the file.  
# For example: chmod 0755 file # To change files permissions to-rxwr-xr-xchmod g+w file # To add user group writable permissions to files ' permissions

18. Vim CommandThis command is primarily used for text editing, which takes one or more file names as parameters, opens if the file exists, and creates a file with the file name if it does not exist. Vim is a very useful text editor, it has a lot of very useful commands, here no longer say. You can download a detailed description of VIM's common operations from here.  19. GCC Commandfor a person who developed a C program with Linux, this command is very important, it is used to compile the C language source program files, compiled into an executable program, because many parameters of g++ and it very similar, so here only the parameters of the GCC, its common parameters are as follows: 
-o:output, used to specify the file name to generate an executable file-C: Used to generate the source file (. o), and to prevent the compiler from creating a complete program-I: Increase the path of the search header file at compile time-l: Increase the path of the compile-time search static connection library-S : Generate assembly code file for source file-lm: A function library named LIBM.A in the directory of the standard library-lpthread: line libraries-std= for connection NPTL implementation: Used to specify the version of the C language to use # for example: # Compile the source file test.c into executable program according to C99 standard Testgcc-o test test.c-lm-std=c99# convert the source file test.c to the corresponding assembler source file Test.sgcc-s test.c

20. Time CommandThis command is used to measure the execution time of a command (that is, a program). It's very simple to use, just like you would normally enter a command, but add a time to the front of the command, for example:
time./processtime PS aux

after the program or command has finished running, it outputs three times at the end, respectively:User : CPU time, the user CPU time that the command executes, that is, the command executes the sum of time in the user state;System : CPU time, the system CPU time that the command executes, that is, the command executes the sum of time in the kernel mentality;Real : The actual time, from the command line to start execution to the end of the elapsed time; Note: The sum of CPU time and system CPU time is CPU time, that is, the total amount of time the command consumes CPU execution. The actual time is greater than the CPU time, because Linux is a multitasking operating system, often when executing a command, the system also handles other tasks. Another problem to be aware of is that even though the same command is executed every time, the time spent is not the same, and the time spent is related to the operation of the system.   http://blog.csdn.net/ljianhui/article/details/11100625 

Linux Common Command Daquan

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.