19 Common commands in CentOS

Source: Internet
Author: User

Anyone who has ever played Linux knows that there are indeed many Linux commands, but those who have ever played Linux have never been troubled by so many Linux commands, because we only need to master the most common 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. cd command

This is a very basic and frequently used command. 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:

  • Cd/root/Docements # Switch to the directory/root/Docements

  • Cd./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, and ".." indicates the directory on the upper layer.

2. ls command

This is a very useful command for viewing files and directories. The meaning of list is that it has many parameters. Here are some of my frequently used parameters, as shown below:

  • -L: Lists long data strings, including object attributes and permission data.

  • -A: List all files, together with hidden files (Files starting)

  • -D: only list the directory itself, not the file data of the directory.

  • -H: lists the file capacity in a readable manner (GB, kB, etc.).

  • -R: It is listed together with the sub-directory content (recursively listed). It means that all files in the directory will be displayed.

  • Note: These parameters can also be used in combination. The following are two examples:

  • Ls-l # list data files and directories in the current directory in the form of long data strings

  • Ls-lR # list all files in the current directory as long data strings

3. grep command

This command is often used to analyze the information of a row. If there is any information we need, this line is displayed. This command is usually used with pipeline commands, it is used to filter and process the output of some commands. Its simple syntax is

Grep [-acinv] [-- color = auto] 'query string' filename

Its common parameters are as follows:

  • -A: query the data of binary files as text files.

  • -C: calculates the number of times a 'query string' is found.

  • -I: Ignore the case sensitivity difference, that is, consider the case as the same

  • -V: reverse selection, that is, the row without the 'search string' content is displayed.

For 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 # output ls-l content containing the letter file (Case Insensitive) to ls-l | grep-I file

4. find command

Find is a very powerful search-based command. It is relatively complex to use and has many parameters. Therefore, we will list them by category here, its basic syntax is as follows:

Find [PATH] [option] [action]

Time-related parameters:

  • -Mtime n: n is a number, which indicates a file that has been changed within one day before n days;

  • -Mtime + n: lists the file names that have been changed before n days (excluding n days;

  • -Mtime-n: lists the file names that have been changed within n days (including n days;

  • -Newer file: list file names that are newer than file

For example:

Find/root-mtime 0 # search for files modified today in the current directory

Parameters related to the user or user group name:

  • -User name: List objects whose owner is name.

  • -Group name: List objects whose user group is name.

  • -Uid n: List objects whose owner is user ID n.

  • -Gid n: List objects whose user group ID is n.

For 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 named filename.

  • -Size [+-] SIZE: Find a file larger (+) or smaller (-) than the SIZE.

  • -Tpye TYPE: Find the TYPE file of the file. The TYPE value mainly includes: general file (f), device file (B, c), and directory (d), connection file (l), socket (s), FIFO pipeline file (p );

  • -Perm mode: searches for files with the File Permission equal to the mode. The mode is represented by a number, for example, 0755;

  • -Perm-mode: The file search permission must contain all files with the mode permission, and the mode is represented by a number.

  • -Perm + mode: Find the file with the permission of any mode. The mode is represented by a number.

For example:

Find/-name passwd # find the file named passwd. -perm 0755 # find the 0755 file with the file permission in the current directory. -size + 12 k # search for files larger than 12 kb in the current directory. Note that c Indicates byte.

5. cp command

This command is used to copy a file. It also copies multiple files to a directory at a time. Its common parameters are as follows:

  • -A: copy the file features together.

  • -P: copies together with file attributes, instead of using the default method. Similar to-A, it is often used for backup.

  • -I: If the target file already exists, the system will first ask for operations during overwriting.

  • -R: recursive continuous replication for directory Replication

  • -U: the object will be copied only when there is a difference between the target file and the source file.

For example:

Cp-a file1 file2 # copy file file1 to file file2 cp file1 file2 file3 dir # copy file file1, file2, and file3 to the directory dir

6. mv command

This command is used to move a file, directory, or rename a file. Its common parameters are as follows:

  • -F: force indicates that if the target file already exists, it is overwritten without asking.

  • -I: If the target file already exists, you will be asked if it is overwritten.

  • -U: 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:

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 directories. Common parameters are as follows:

  • -F: indicates force. Ignore nonexistent files and no warning message appears.

  • -I: interactive mode. Before deletion, you will be asked if you want to perform the operation.

  • -R: recursive deletion, which is most commonly used for directory deletion. It is a very dangerous parameter.

For example:

Rm-I file # delete the file. before deleting the file, you will be asked whether 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 a process at a certain time point. The common parameters of process are as follows:

  • -A: all processes are displayed.

  • -A: All processes not related to terminal

  • -U: Processes of Valid users

  • -X: generally used together with parameter a. Complete information can be listed.

  • -L: long, detailed list of PID Information

In fact, we only need to remember that the command parameters commonly used by ps can be combined. There are not many of them, as shown below:

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 the status of some process trees

9. kill command

This command is used to send a signal to a job (% jobnumber) or a PID (number). It is usually used together with the ps and jobs commands. Its basic syntax is as follows:

Kill-signal PID

Common Parameters of signal are as follows (note: the first digit is the signal code, which can be used to replace the corresponding signal ):

  • View plaincopyprint?

  • 1: SIGHUP, start the terminated Process

  • 2: SIGINT, equivalent to entering ctrl + c to interrupt the execution of a program

  • 9: SIGKILL, force a process to be interrupted

  • 15: SIGTERM, terminate the process in the normal way of ending the process

  • 17: SIGSTOP, equivalent to entering ctrl + z to pause a process

For example:

# The first background work is finally finished in a normal way. Run the jobs command to view the first working process kill-SIGTERM % 1 in the background # re-change the process ID to PID, you can use the ps command to filter the PID by adding the grep command to the pipeline command to obtain the kill-sighup pid.

10. killall command

This command is used to send a signal to a process started by a command. Its syntax is as follows:

Killall [-iIe] [command name]

Its parameters are as follows:

  • -I: indicates the interaction. If you need to delete the notebook, you will be asked

  • -E: indicates that the names of the subsequent commands 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, this command is very useful for us, its usage is very simple. The basic syntax is as follows:

View plaincopyprint?

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) compression and decompression. Its common parameters are as follows:

  • -C: Create a packaging File

  • -T: view the file names contained in the package.

  • -X: The unpackage or decompress function can be used with-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: supports gzip compression and decompression.

  • -V: displays the file name being processed during compression/decompression.

  • -F filename: filename indicates the file to be processed.

  • -C dir: Specify the directory dir for compression/Decompression

The above explanation may have fainted you, but we usually only need to remember the following three commands:

  • Compression: name of the file or directory to be processed by tar-jcv filename.tar.bz2

  • Query: tar-jtv-f filename.tar.bz2

  • Decompress: tar-jxv-f filename.tar.bz2-C directory to be decompressed

Note: The file name must end with the suffix tar.bz2, which is mainly used to indicate that the compression program is bzip2.

13. cat command

This command is used to view the content of a text file, followed by the file name to be viewed. Generally, pipelines can be used with more and less to view data on one page.

Example: cat text | less # view the content in the text file

# Note: This command can also be replaced by less text.

14. chgrp command

This command is used to change the user group to which the file belongs. It is easy to use and its basic usage is as follows:

Chgrp [-R] dirname/filename

-R: recursively changes all files and subdirectories.

For example, chgrp users-R./dir # recursively change the user group of all files in the dir directory and all files in the subdirectories to users.

15. chown command

This command is used to change the file owner. It is used in the same way as the chgrp command, but the modified file attributes are different and will not be detailed.

16. chmod command

This command is used to change the File Permission. The general usage is as follows:

Chmod [-R] xyz file or directory

-R: recursive continuous change, that is, all files under the subdirectory will be changed.

At the same time, chmod can also use u (user), g (group), o (other), a (all) and + (join),-(delete), = (SET) used with rwx to change the file permissions.

For example:

Chmod 0755 file # change the file Permission to-rxwr-xr-x chmod g + w file # Add the user group writable permission to the file Permission.

17. vim commands

This command is mainly 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, it is used to create a file with the file name. Vim is a very easy-to-use text editor, which contains many very useful commands. You can download detailed descriptions of common vim operations from here.

18. gcc commands

For a person who develops C Programs in Linux, this command is very important. It is used to compile C source program files into executable programs, since many g ++ parameters are very similar to those of gcc, only gcc parameters are introduced here. The common parameters are as follows:

  • -O: indicates the output file name used to generate an executable file.

  • -C: used to generate the source file (. o) and prevent the compiler from creating a complete program.

  • -I: adds the path to search for header files during compilation.

  • -L: adds the path for searching static connection databases during compilation.

  • -S: generate an assembly code file from the source file.

  • -Lm: indicates the library named libm. a In the standard library directory.

  • -Lpthread: connect to the NPTL thread Library

  • -Std =: Specifies the C language version used.

For 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 # test the source file. c to the corresponding assembler source file test. s gcc-S test. c

19. time Command

This command is used to measure the execution time of a command (a program. It is very simple to use, just like entering a command at ordinary times, but just add a time before the command, for example:

Time./process

Time ps aux

After the program or command is run, three times are output at the end, which are:

  • User: the user's CPU time, the user's CPU time spent on command execution completion, that is, the total execution time of commands in user State;

  • System: system CPU time, which is the total execution time of a command in the core state;

  • Real: the actual time, from the execution of the command line to the elapsed time of running termination;

Note: The sum of the user's CPU time and system CPU time is the sum of CPU time used by the command. 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.


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.