20 most common Linux commands to explain __linux

Source: Internet
Author: User
Tags file permissions
20 most common Linux commands to explain

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 # Switches to the path directory under the current directory, "." Represents the current directory
Cd.. /PATH # Switch to the path directory in the upper directory, "..." Represents the previous level of a directory


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, including attributes and permission data for files, etc.
-A: Lists all files, together with hidden files (files with the beginning of.) (Common)
-D: Only the directory itself, not the file data that lists the directory
-H: List the file capacity in a more readable manner (GB,KB, etc.)
-R: Listed together with the contents of the subdirectory (recursively listed), equal to all the files in the directory will be displayed


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

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


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: Find data in text file as binary file
-C: Calculates the number of find ' Find string '
-I: Ignore case difference, that is, the case is treated as the same
-V: Reverse selection, which shows the line with no ' find string ' content
e.g.
# Remove the Manpath line from the file/etc/man.config and add color to the Found keyword
grep--color=auto ' Manpath '/etc/man.config
# The output of the ls-l contains the letter file (case-insensitive) content output
Ls-l | Grep-i file


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]

# Parameters related to time:
-mtime N:n is a number, meaning a file that has been changed in "One Day" before n days;
-mtime +n: Lists the file names that were changed before n days (excluding n days themselves);
-mtime-n: Lists the file names that have been changed within n days (including n days themselves);
-newer file: Lists file names that are newer than file
e.g.
Find/root-mtime 0 # Find files in the current directory that have changed today

# parameters related to user or user group name:
-user Name: Lists files with file owner name
-group Name: Lists files for which the user group belongs to name
-uid N: Lists files where the owner of the file is a user ID n
-gid N: Lists files that belong to a user group with a user group ID of n
e.g.
Find/home/ljianhui-user Ljianhui # Find the owner Ljianhui file in the directory/home/ljianhui

# Parameters related to file permissions and names:
-name FileName: Find the file named filename
-size [+-]size: Find a file larger than size (+) or small (-)
-tpye Type: A file that finds the type of a file, 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 files with a file right equal to mode, mode is represented by numbers, such as 0755;
-perm-mode: Find file permissions must all include mode permission files, mode is represented by numbers
-perm +mode: A file that finds file permissions that contain permissions for either mode, mode is represented by a number
e.g.
Find/-name passwd # Look for files with file name passwd
Find. -perm 0755 # 0755 files to find file permissions in the current directory
Find. -size +12k # Find files larger than 12KB in the current directory, note that C indicates byte


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
-P: Copy with the properties of the file instead of using the default method, similar to-a, often used for backup
-I: If the target file already exists, it will ask for the operation before overwriting
-R: Recursive continuous Replication for directory replication behavior
-U: The destination file is copied when it differs from the source file


For example:

Cp-a file1 file2 #连同文件的所有特性把文件file1复制成文件file2
CP file1 file2 file3 dir #把文件file1, File2, file3 replicated to directory dir


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, do not ask and directly overwrite
-I: If the target file already exists, it asks if the overwrite
-U: If the target file already exists and is 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 # moving files file1, file2, file3 to directory dir
MV file1 file2 # Rename file file1 to File2


7. RM command

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

-F: That means force, ignoring files that do not exist, and no warning messages appear
-I: interactive mode, before deleting will ask the user whether to operate
-R: Recursive deletion, most commonly used in directory deletion, it is a very dangerous parameter


For example:

Rm-i file # Deletes files and asks for the action before deleting
RM-FR dir # force all files in directory dir to be deleted


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 effective users
-X: Typically used with a parameter to list more complete information
-L: A longer, more detailed list of the PID 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 all process data for the system
PS Ax # View all processes not related to terminal
Ps-la # View all process data for the system
PS AXJF # View together with a portion of the process tree state


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:

Kill-signal PID


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, starting the terminated process
2:sigint, the equivalent of input CTRL + C, interrupt a program to proceed
9:sigkill, forcing a process to be interrupted
15:sigterm, terminating the process in a normal ending process
17:sigstop, equivalent to input ctrl+z, suspend a 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 first work process in the background
Kill-sigterm%1
# re-change process ID PID process, PID can be used with the PS command through the pipeline command plus grep command to filter for
Kill-sighup PID


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]

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.