My 20 most common commands in Linux

Source: Internet
Author: User
People who are familiar with Linux's 20 most commonly used commands will know that there are indeed many commands in Linux, however, users who have ever played Linux have never been troubled by so many Linux commands, because we only need to master the most commonly used commands. Of course, you can also make... people who are familiar with Linux's 20 most commonly used commands will know that there are indeed many commands in Linux, however, users who have ever played Linux have never been troubled by so many Linux commands, because we only need to master the most commonly used commands. Of course, you can also find man for use, which will help you solve a lot of problems. However, each person has different purposes in playing Linux, so their commonly used commands are very different. I mainly use Linux to write C/C ++ and shell programs, therefore, the commonly used commands may be different from one who manages Linux systems. Because I don't want to use it all the time, I would like to summarize it here for your convenience. Let's talk about the most common Linux commands. 1. the cd command is very basic and frequently used. it is used to switch the current directory. its parameter is the path of the directory to be switched, which can be an absolute path, it can also be a relative path. For example, [plain] cd/root/Docements # switch to the/root/Docements cd directory. /path # switch to the path directory under the current directory, "indicates the current directory cd .. /path # switch to the path directory in the upper Directory, "indicates the directory 2 and ls commands on the top. this is a very useful command for viewing files and directories. the meaning of list is that there are many parameters. Here are some of my frequently used parameters, [plain]-l: lists long data strings, including object attributes and permission data.-a: lists all objects, together with hidden files (beginning. -d: only list the directory itself, rather than list the file data of the Directory-h: The file capacity is more readable (GB, kB, etc) column-R: it is listed together with the sub-directory content (recursively listed), which means that all files in the directory are displayed. note: these parameters can also be used in combination. the following two examples are as follows: [plain] ls-l # long data string form List the data files in the current directory and the Directory ls-lR # List all files in the current directory in the form of long data strings 3. grep command this command is often used to analyze the information of a row, if there is information we need, this line is displayed. This command is usually used together with the pipeline command to filter and process the output of some commands, its simple syntax is [plain] grep [-acinv] [-- color = auto] '. the common parameters for finding the string 'filename' are as follows: [plain]-: search for data in a text file in binary file-c: count the number of times The 'query String' is found-I: ignore the case difference, that is, the case is treated as the same-v: reverse selection, that is, the line without 'search String' is displayed. # Example: # retrieve the file/etc/man. config contains the MANPATH row, and adds the keyword to the color grep -- color = auto 'manpath'/etc/man. config # set The ls-l output contains the letter file (case insensitive) ls-l | grep-I file 4. the find command find is a very powerful search-based command, which is relatively complicated to use, there are also many parameters, so here we will list them by category. its basic syntax is as follows: [plain] find [PATH] [option] [action] # time-related parameter:-mtime n: n is a number, indicates the files that have been changed within one day before n days.-mtime + n: lists the files that have been changed before n days (excluding n days; -mtime-n: to list the file names that have been changed within n days (including n days).-newer file: to list file names that are newer than file # Example: find/root-mtime 0 # search for files modified today in the current directory # parameters related to user or user group names:-user name: List FILE-group name with file owner name: list files whose user group is name-uid n: list files whose owner is user id n-gid n: list objects whose user group is user group ID n # Example: find/home/ljianhui-user ljianhui # find the file whose owner is ljianhui in the/home/ljianhui Directory # parameters related to file permissions and names:-name filename: find the file-size [+-] SIZE with the file name filename: find the file-tpye TYPE that is larger (+) or smaller (-) than the SIZE: find a file of TYPE. The value of TYPE mainly includes: General File (f), device file (B, c), Directory (d), and connection File (l), socket (s), FIFO pipeline File (p);-perm mode: find the file with the same permission as the mode, the mode is used Number, for example, 0755;-perm-mode: the file with all the mode permissions must be queried. mode indicates-perm + mode with a number: find a file with the permission of any mode. the mode is represented by a number. # for example, find/-name passwd # find a file with the file name passwd. -perm 0755 # find the 0755 file permission of the current directory. -size + 12 k # search for files larger than 12 kb in the current directory. Note that c indicates byte 5 and cp command. This command is used to copy files, it can also copy multiple files to a directory at a time. its common parameters are as follows: [plain]-a: Copy the features of the file together-p: copy together with the file attributes, instead of using the default method. similar to-a, it is often used for backup-I: if the target file already exists, during overwriting, you will first ask for the operation-r: recursive Continuous Replication, used for Directory Replication behavior-u: The target file will be copied only when there is a difference between the source file and the target file. for example: [plain] cp-a file1 file2 # Copy file file1 to file file2 cp file1 file2 file3 dir # Copy file file1, file2, and file3 to directory dir 6, mv command this command is used to move files, directories, or rename, move: The common parameters are as follows: [plain]-f: force. if the target file already exists, overwrite-I without asking. if the target file already exists, if the target file already exists and is newer than the target file, it will be updated. note: this command can move one or more files to one folder at a time, but the last target file must be a "directory ". For example: [plain] mv file1 file2 file3 dir # Move the files file1, file2, and file3 to the directory dir mv file1 file2 # rename the file file1 to file2 7, rm command this command is used to delete files or directory, remove, the common parameters are as follows: [plain]-f: indicates force. ignore non-existing files and no warning message is displayed-I: interactive mode, before deletion, you will be asked whether to operate-r: recursive deletion, which is most commonly used in directory deletion. it is a very dangerous parameter, for example: [plain] rm-I file # delete a file, before deletion, you will be asked if you want to perform this operation rm-fr dir # force delete all files in the dir Directory 8. ps command this command is used to select and output the running status of processes at a certain time point., the common parameters of process are as follows: [plain]-A: all processes are displayed-a: not with terminal All related processes-u: related processes of valid users-x: generally used together with the parameter. more complete information can be listed-l: longer, to list PID information in detail, we only need to remember that the command parameters used by ps are not many, as shown below: [plain] ps aux # View all process data of the system ps ax # View all processes not related to terminal ps-lA # View all process data of the system ps axjf # View together with some processes tree status 9. kill command this command is used to send a job (% jobnumber) or a PID (number) transmits a signal, which is usually used with the ps and jobs commands. its basic syntax is as follows: [plain] common parameters of kill-signal PID signal are as follows: note: The first digit is the signal code. you can use the code to replace the corresponding signal. [Plain] 1: SIGHUP, start the terminated process 2: SIGINT, equivalent to entering ctrl + c, interrupt a program for 9: SIGKILL, force interrupt a process for 15: SIGTERM is used to terminate the process 17: SIGSTOP in the normal way of ending the process. it is equivalent to entering ctrl + z to pause a process, for example: [plain] # It is the first backend job to end the process normally, run the jobs command to view the first working process kill-SIGTERM % 1 # Re-modify the process whose ID is PID, PID can use the ps command to filter by adding the grep command to the pipeline command to obtain the kill-sighup pid 10 and killall commands. This command is used to send a signal to a process started by a command. its general syntax is as follows: [plain] killall [-iIe] [command name] its parameters are as follows: [plain]-I: interactive meaning. if you need to delete the parameters, you will be asked-e: Indicates that the command names followed by the command name must be consistent, but the command name cannot exceed 15 characters-I: the command name is case-insensitive # Example: killall-SIGHUP syslogd # restart syslogd 11, file command this command is used to determine the basic data of the file connected to the file command, because the file type in Linux is not based on the suffix, therefore, this command is very useful for us. its usage is very simple. the basic syntax is as follows: [plain] file filename # Example: file. /test 12, tar command. This command is used to package files. by default, files are not compressed. if the corresponding parameters are specified, it also calls the corresponding compression program (such as gzip and bzip) for compression and decompression. Its common parameters are as follows: [plain]-c: create a package file-t: check which file names are contained in the package file-x: The function of unpackaging or decompression, you can use-C (uppercase) to specify the decompressed Directory. Note that-c,-t, and-x cannot appear in the same command at the same time.-j: use bzip2 to compress/decompress-z: use gzip to compress/decompress-v: Display the file name being processed-f filename: filename is the file to be processed-C dir: specifies the compressed/decompressed directory dir. the above explanation can make you dizzy, but usually we only need to remember the following three commands: [plain] compression: the directory name of the file to be processed by tar-jcv filename.tar.bz2 can be queried: tar-jtv-f filename.tar.bz2 Unzip: tar-jxv-f filename.tar.bz2-C directory to be decompressed note: the file name is not fixed To end with the suffix tar.bz2, the compression program is bzip2 13. the cat command is used to view the content of the text file, and then the file name to be viewed, you can use pipelines with more and less to view data on one page. For example: [plain] cat text | less # view the content in the text file 14. the chgrp command is used to change the user group to which the file belongs. it is very easy to use and its basic usage is as follows: [plain] chgrp [-R] dirname/filename-R: recursively changes all files and subdirectories. # Example: chgrp users-R. /dir # recursively change the user group of all files and sub-directories in the dir directory to users 15 and chown. This command is used to change the file owner, the usage of the chgrp command is the same as that of the chgrp command, but the attributes of the modified file are different. 16. the chmod command is used to change the file permissions. the general usage is as follows: [plain] chmod [-R] xyz file or directory-R: perform recursive continuous changes, that is, all files under the same subdirectory will be changed. at the same time, chmod can also use u (user), g (group), o (other), a (all), and + (add) ,-(delete), = (set), and rwx are used together to change the object ACL. [Plain] # Example: chmod 0755 file # Change the file permission to-rxwr-xr-x chmod g + w file # add the user group write permission to the file permission. 18. vim command: the main command used for text editing, it takes one or more file names as parameters. if the file exists, it is opened. if the file does not exist, a file is created with the file name. Vim is a very easy-to-use text editor, which contains many very useful commands. 19. the gcc command is very important for a person who develops C programs in Linux. it is used to compile the C language source program file into executable programs, many g ++ parameters are very similar to those of gcc, so here we only introduce the gcc parameters. the common parameters are as follows: [plain]-o: output, specifies the file name to generate an executable file-c: used to generate the target file for the source file (. o), and prevent the compiler from creating a complete program-I: add the path of the header file to be searched during compilation-L: add the path to the static connection library to be searched during compilation-S: generate the source file assembly code file-lm: indicates the name of libm in the standard library directory. function library a-lpthread: connects to the NPTL thread library-std =: Used to specify the version of the C language used [plain] # Example: # test the source file. c is compiled into an executable program test gcc-o test according to the c99 standard. c-lm-std = c99 20, time command this command is used to calculate The execution time of commands (programs. It is very simple to use, just like entering a command at ordinary times, but just add a time before the command, for example: [plain] time. /process time ps aux after the program or command is run, three time periods are output at the end, which are: user CPU time, the user CPU time spent for command execution completion, that is, the total execution time of commands in the user state; system: system CPU time; the total execution time of the command in the core state; real: the actual time, the duration from the execution of the command line to the termination of running. note: the sum of the user's CPU time and system CPU time is the CPU time, that is, the sum of the time that the command occupies CPU execution. The actual time is later than the CPU time, because Linux is a multi-task operating system, and the system usually needs to process other tasks when executing a command. Another issue that needs to be noted is that even if the same command is executed each time, the time consumed is different. the time consumed is related to system running.
Related Article

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.