20 Linux commands commonly used by testers (with Linux video tutorials) __linux

Source: Internet
Author: User

These days I have been to see a fan to my Linux learning tutorials, this is not today for everyone to find. Students need to see the end of the article to get the way oh.


Mastering and using the following commands will improve the efficiency of your testing efforts.

1. Command: Find

Searches for files in the specified directory, starting at the parent directory, and then searching subdirectories.

Note: The-name ' option is search case sensitive. You can use the-iname ' option so that you can ignore case in search. (* is a wildcard, you can search all the files; Sh ' You can use a filename or part of the file name to make the output)

Note: The above command looks for all files containing ' tar.gz ' under the root directory and all folders and the subdirectories of the loaded device.

For more details on the ' find ' command please refer to the Find command examples in Linux


2. Command: grep

The ' grep ' command searches for a line in the specified file that contains the given string or Word. Search for examples of ' tecmint ' in '/etc/passwd ' files

Using the '-I ' option ignores case.

Use the '-r ' option to recursively search all the rows that contain the string "127.0.0.1" from the directory.

Note: You can also use the following options:

-W Search for Words (egrep-w ' word1|word2 '/path/to/file).

-C is used to count the rows that meet the requirements (i.e., total number of the matched) (grep-c ' word '/path/to/file).

–color Color Output (Grep–color server/etc/passwd).


3. Command: Man

' Man ' is the system help page. Man provides online documentation that commands all options and usage. Almost all commands have their help pages, such as:

The above is the System help page for the Man command, similar to the help page for cat and LS.

Note: The system help page is designed for use and learning of commands.


4. Command: PS

The PS command gives the state of a running process in which each process has a specific ID to become a PID.

Use the '-A ' option to list all processes and their PID.

NOTE: PS commands are useful when you want to know which processes are running or need to know the process PID you want to kill. You can query the specified output by combining it with ' grep ', for example:

The PS command and grep command are separated by a pipe line to get the results we want.


5. Command: Kill

Maybe you've guessed what you've done with the name of the order, kill is used for killing a process that is irrelevant or unresponsive. It is a very useful command, not very very useful. You may be familiar with it. Windows to kill a process may need to restart the machine frequently because a running process cannot be killed in most cases, even if the process is killed, the operating system needs to be restarted to take effect. But in a Linux environment, That's not the way it is. You can kill a process and restart it instead of restarting the entire operating system.

Killing a process requires knowing the PID of the process.

Suppose you want to kill the ' apache2 ' process that has not responded, run the following command:

Search the ' apache2 ' process, find the PID and kill it. For example: In this example, the PID for the ' apache2 ' process is 1285.

Note: Each time you rerun a process or start the system, each process generates a new PID. You can use the PS command to get the PID of the current running process.

Another way to kill a process is to:

Note: Kill requires PID as a parameter, Pkill can choose the way to apply, such as the owner of the specified process.


6. Order: Whereis

The Whereis function is used to locate the binary file \ Resource \ or help page for the command. For example, get the binaries/resources and help pages for the LS and kill commands:

Note: Useful when you need to know where to save a binary file.


7. Command: Service

The ' Service ' command controls the start, stop, and restart of the service, allowing you to have the configuration take effect without restarting the entire system to turn on, stop, or restart a service.

Start Apache2 server on Ubuntu:

Restart Apache2 server:

Stop Apache2 Server:

Note: To use the service command, the script for the process must be placed '/ETC/INIT.D ', and the path must be in the specified location.

If you want to run service apache2 start, you actually perform "service/etc/init.d/apache2 start."


8. Command: Alias

The alias is a system-built shell command that allows you to assign aliases to commands that are long or often used by names.

I often use the ' ls-l ' command, which has five characters (including spaces). So I created an alias ' L ' for it.

Try whether it can be used:

Remove the ' l ' alias to use the Unalias command:

Try again:

To make a joke, designate an alias for an important command as another important command:

Think about how interesting it is now if your friend typed the ' CD ' command, when he sees a list of directory files instead of changing directories; when he tries to use the ' su ' command, he goes into the current directory. You can then remove the alias and explain the situation to him.


9. Command: DF

Reports the disk usage of the system. Useful for regular users and system administrators in tracking disk usage. ' DF ' works by checking the size of the directory, but this value is only updated when the file is closed.

For more examples of the ' DF ' command, see the DF command examples in Linux.


10. Order: Du

Estimate the space footprint of the file. Tier-by-layer statistical files (for example, recursively) and output summaries.

Note: ' DF ' only displays the usage statistics of the file system, but the ' du ' statistic directory contents. For more detailed information on the ' du ' command, see Commands (Disk Usage).


11. Command: RM

' RM ' standard removal command. RM can be used to delete files and directories.

An error occurs when you delete a directory directly:

' RM ' cannot delete the directory directly, you need to add the corresponding '-rf ' parameter.

Warning: the "rm-rf" command is a destructive command if you accidentally delete a wrong directory. Once you use ' rm-rf ' to delete a directory, all files in the directory including the directory itself will be permanently deleted, so use this command very carefully.


12. Command: Echo

Echo's function, like its name, is to print a piece of text based on standard output. It has nothing to do with the shell, nor does the shell read what is printed through the echo command. In an interactive script, however, Echo passes information to the user through the terminal. It is a frequently used command in scripting languages, interactive scripting languages.

Create a small section of interactive scripts

1. Create a new file on the desktop named ' interactive_shell.sh ' (remember to have the '. Sh ' extension).

2. Copy and paste the following script code to ensure consistency with the following.

Next, set execute permissions and run the script.

Note: ' #!/bin/bash ' tells the shell that this is a script, and it's a good habit to write this sentence on the first line of the script. ' read ' reads the given output.


13. Order: passwd

This is an important command to use in the terminal to change your password is useful. Obviously, you need to know the current password for security reasons.


14. Order: LPR

This command is used to print the specified file on the command line on the specified printer.

Note: the "lpq" command lets you see the status of the printer (whether it is turned on or off) and the status of the work (file) waiting to be printed.


15. Command: CMP

Compares two files of any type and outputs the results to standard output. If two files are the same, ' CMP ' returns 0 by default, and if different, the number of bytes is displayed and the first location is different.

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.