My first glimpse of Linux's 20 most common commands

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 command This 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. Example: [plain] View plain copy print?
    1. Cd/root/docements # Switch to directory/root/docements
    2. cd./path # Switch to the path directory in the current directory, "." Represents the current directory
    3. Cd.. /PATH # Switch to the path directory in the upper directory, "..." Represents a previous level of directory
2, ls command This is a very useful view of the file and directory commands, list of the meaning, it has a lot of parameters, the following list some of my usual parameters, as follows: [plain] View plain copy print?
    1. -L: Lists Long data strings, including file attributes and permission data, etc.
    2. -A: Lists all the files, together with hidden files (files that begin with.) (common)
    3. -D: Lists only the directory itself, not the file data for the directory
    4. -H: List the file capacity in a more readable way (GB,KB, etc.)
    5. -R: Listed along with the contents of the subdirectory (recursively listed), equal to all files in that directory will be displayed
Note: These parameters can also be combined, with two examples: [plain] View plain copy print?
    1. Ls-l #以长数据串的形式列出当前目录下的数据文件和目录
    2. LS-LR #以长数据串的形式列出当前目录下的所有文件
3, grep command This command is often used to analyze a row of information, if there is information we need, the line is displayed, the command is usually used with the pipeline command, for the output of some commands to filter processing and so on, its simple syntax for [plain] view plain copy print ?
    1. grep [-ACINV] [--color=auto] ' Find string ' filename
Its common parameters are as follows: [plain] View plain copy print?
    1. -A: Find data in a binary file as a text file
    2. -C: Calculate the number of times to find ' find string '
    3. -I: Ignore case differences, that is, case is considered the same
    4. -V: Reverse selection, which shows the line without the ' Find string ' content
    5. For example
    6. # Remove the line containing Manpath in the file/etc/man.config and add color to the Found keyword
    7. grep--color=auto ' MANPATH '/etc/man.config
    8. # put the output of ls-l with the letter file (case-insensitive) content output
    9. Ls-l | Grep-i file
4, Find command find 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: [plain] View plain copy print?
  1. Find [PATH] [option] [action]
  2. # time-related parameters:
  3. -mtime N: = n is a number, meaning a file that has been changed in "One Day" before the nth day;
  4. -mtime +n: Lists the file names that were changed before n days (excluding the N-day itself);
  5. -mtime-n: Lists filenames that have been changed within n days (including n days themselves);
  6. -newer file: List file names that are newer than file
  7. For example
  8. Find/root-mtime 0 # Find files that have changed within the current directory today
  9. # parameters related to user or user group name:
  10. -user Name: List files with file owner name
  11. -group Name: List files that belong to the user group named name
  12. -uid N: List file owner as User ID n
  13. -gid N: Lists files that belong to the user group whose user group ID is n
  14. For example
  15. Find/home/ljianhui-user Ljianhui # Find the owner-Ljianhui file in the directory/home/ljianhui
  16. # Parameters related to file permissions and names:
  17. -name FileName: Find the file named filename
  18. -size [+-]size: Find a file larger than size (+) or small (-)
  19. -tpye Type: Find file of type of file, the value of type is mainly: General file (f), device file (b, C),
  20. Directory (d), connection file (L), socket (s), FIFO pipeline file (p);
  21. -perm mode: Find file permissions just equal to the mode file, mode is represented by a number, such as 0755;
  22. -perm-mode: Find file permissions must all include the mode permission of the file, mode is represented by a number
  23. -perm +mode: Find file Permissions file that contains the permissions of either mode, mode is represented by a number
  24. For example
  25. Find/-name passwd # Finding files with file name passwd
  26. Find. -perm 0755 # 0755 file to find file permissions in the current directory
  27. Find. -size +12k # Find files larger than 12KB in the current directory, note that C means byte
5, CP Command This command is used to copy the file, copy of the meaning, it can also be a single copy of multiple files to a directory, its common parameters are as follows: [plain] View plain copy print?
    1. -A: Copy the attributes of the file together
    2. -P: Copied along with the properties of the file, not by default, similar to-a, often used for backup
    3. -I: If the target file already exists, the action will be asked before overwriting
    4. -R: Recursive continuous Replication for directory replication behavior
    5. -U: The destination file is copied when it differs from the source file
For example: [plain] View plain copy print?
    1. Cp-a file1 file2 #连同文件的所有特性把文件file1复制成文件file2
    2. CP file1 file2 file3 dir #把文件file1, file2, file3 copy to directory dir
6. MV Command This command is used to move files, directories, or rename, move the meaning, its common parameters are as follows: [plain] View plain copy print?
    1. -f:force mandatory Meaning, if the target file already exists, will not ask and directly overwrite
    2. -I: If the target file already exists, you will be asked to overwrite
    3. -U: Updates if the target file already exists and is newer than the target file
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: [plain] View plain copy print?
    1. MV File1 file2 file3 dir # move the file file1, File2, file3 to the directory dir
    2. MV File1 file2 # Rename the file file1 to File2
7, RM command This command is used to delete files or directories, between remove, its common parameters are as follows: [plain] View plain copy print?
    1. -F: Force means ignoring files that do not exist and warning messages are not present
    2. -I: Interactive mode, ask the user whether to operate before deleting
    3. -R: Recursive delete, most commonly used for directory deletion, it is a very dangerous parameter
For example: [plain] View plain copy print?
    1. Rm-i File # To delete files, ask for the action before deleting
    2. RM-FR dir # force removal of all files in directory dir
8. PS Command This command is used to select and output the process operation at a certain point in time, and its common parameters are as follows: [plain] View plain copy print?
    1. -A: All processes are displayed
    2. -A: All processes not related to terminal
    3. -U: Related processes for effective users
    4. -X: Generally used in conjunction with a parameter to list more complete information
    5. -L: Longer, the PID information is listed in more detail
In fact, we just need to remember the general use of PS command parameter collocation, they are not many, as follows: [plain] View plain copy print?
    1. PS aux # View all process data for the system
    2. PS Ax # View all processes not related to terminal
    3. Ps-la # View all process data for the system
    4. PS AXJF # View together with a subset of process tree states
9. Kill command This command is used to transmit a signal to a job (%jobnumber) or to a PID (number), which is usually used with the PS and jobs commands, with the following basic syntax: [plain] View plain copy print?
    1. Kill-signal PID
The commonly used parameters of signal are as follows: Note: The first number is the signal code, the use of the code can be replaced by the corresponding signal. [Plain] View plain copy print?
    1. 1:sighup, start the terminated process
    2. 2:sigint, equivalent to input CTRL + C, interrupts the process of a program
    3. 9:sigkill, forcing the interruption of a process
    4. 15:sigterm to terminate the process with normal end-of-process mode
    5. 17:sigstop, which is equivalent to input CTRL + Z, pauses a process
For example: [plain] View plain copy print?
    1. # at the end of the normal process to finally the first background work, you can use the Jobs command to view the background of the first worker process
    2. Kill-sigterm%1
    3. # re-change process ID to PID process, PID can be filtered using the PS command with the command of the command plus grep
    4. Kill-sighup PID
10. Killall command This command is used to send a signal to a command-initiated process with the following general syntax: [plain] View plain copy print?
    1. Killall [-iie] [command name]
It has the following parameters: [plain] View plain copy print?
    1. -I: interactive meaning, if need to delete, will ask the user
    2. -E: Indicates that command name is followed by the same, but command name cannot exceed 15 characters
    3. -I: Command name ignores case
    4. For example
    5. Killall-sighup syslogd # reboot SYSLOGD
11. The file command is used to determine the basic data of files that are connected to the document after the file command, because the type of the files under Linux is not a suffix, so this command is very useful for us, it is very simple to use, the basic syntax is as follows: [Plain] View plain Copy print?
    1. File filename
    2. #例如:
    3. File./test
12. Tar command This command is used to package the file, the default is not compressed, and if the corresponding parameters are specified, it will also call the appropriate compression programs (such as Gzip and bzip) for compression and decompression. Its common parameters are as follows: [plain] View plain copy print?
    1. -C: New package file
    2. -T: See what file names are included in the contents of the packaged files
    3. -X: Unpacking or decompression function, can be used with-C (uppercase) to specify the extracted directory, note-c,-t,-x cannot appear in the same command
    4. -J: Compression/decompression via BZIP2 support
    5. -Z: Compression/decompression with GZIP support
    6. -V: Displays the file name being processed during the compression/decompression process
    7. -F filename:filename for files to be processed
    8. -C dir: Specify a directory for compression/decompression dir
The above commentary can already make you dizzy, but usually we just need to remember the following three commands: [plain] View plain copy print?
    1. Compression: Tar-jcv-f filename.tar.bz2 The name of the file or directory to be processed
    2. Enquiry: Tar-jtv-f filename.tar.bz2
    3. Unzip: Tar-jxv-f filename.tar.bz2-c to extract the directory
Note: The file name is not determined to end the suffix tar.bz2, here is mainly to illustrate the use of the compression program for BZIP2 13, the Cat command to view the contents of a text file, followed by the file name to view, usually available pipelines with more and less to use, so that you can view the data page. For example: [plain] View plain copy print?
    1. Cat text | Less # View the contents of the text file
    2. # Note: This command can also use less text instead
14, chgrp Command This command to change the file belongs to the user group, its use is very simple, its basic usage is as follows: [plain] View plain copy print?
    1. CHGRP [-R] Dirname/filename
    2. -R: Recursive persistent changes to all files and subdirectories
    3. For example
    4. Chgrp users-r./dir # Recursively modifies the user group for all files and subdirectories under the Dir directory to users
15, chown Command This command is used to change the owner of the file, and the CHGRP command is used the same way, just modify the file attributes are different, no longer detailed. 16, chmod command This command to change the permissions of the file, the general usage is as follows: [plain] View plain copy print?
    1. chmod [-r] XYZ file or directory
    2. -R: Continuous change of recursion, that is, all files under subdirectories are changed
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. [Plain] View plain copy print?
    1. For example
    2. chmod 0755 File # Changes files permissions to-rxwr-xr-x
    3. chmod g+w File # Adds a user group writable permission to files ' permissions
18. Vim command This command is primarily used for text editing, which takes one or more file names as parameters and 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 command for a Linux development C program, this command is very important, it is used to C language source program files, compiled into an executable program, because many parameters of g++ and it very similar, so here only to introduce the parameters of GCC, its common parameters are as follows: [Plain] View Plain copy print?
    1. -o:output, used to specify the file name to generate an executable file
    2. -C: Used to generate a target file (. o) from the source file and prevent the compiler from creating a complete program
    3. -I: Increase the path of the search header file at compile time
    4. -L: Increase the path of the search static connection library at compile time
    5. -S: Generate assembly code files for source files
    6. -LM: A library of libraries named LIBM.A in the directory that represents the standard library
    7. -lpthread: Connecting NPTL-Implemented lines libraries
    8. -std=: Used to specify the version of the C language to use
    9. For example
    10. # Compile the source file test.c into executable program test according to C99 standard
    11. Gcc-o Test Test.c-lm-std=c99
    12. #把源文件test. c conversion to the appropriate assembler source file Test.s
    13. Gcc-s test.c
20. Time command This command is used to measure the execution times 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: [plain] View plain copy print?
    1. Time./process
    2. Time PS aux
After the execution of the program or command, at the last three time, they are: 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, System CPU time of the command execution, That is, the execution time sum of the command in the nuclear mentality; Real: The actual time, from the command line start execution to the elapsed time of the end of the run; 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.

My first glimpse of Linux's 20 most common commands

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: 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.