Linux systems sometimes need to detect whether a certain condition is set up, then use the Test command, Linux under the use of test has a lot of, the following small set together to learn how to use the Linux System Test command.
1. Judge the result of a command using test, which returns 0, or an integer. Returns 0 to True, returning an integer representing the error code
2. Get the return result of the previous command using $?
3. For example
There is a/home/www folder on my server, so ls/home/www The return result of this command is 0;
That is, echo $? Returns a value of 0
There is no such folder as/HOME/KKK on my server, so ls/home/kkk The return result of this command is the error code after the execution of the command;
The return result of Echo $ is 2. This 2 indicates that the file or folder does not exist.
4. Commonly used file-testing characters
-E Indicates whether this file name exists
-F Indicates whether this file name is a file
-D Indicates if this file name is a folder
-R Indicates whether this file name is readable
-W Indicates whether this file can be written
-X Indicates whether this file is executable
-S Indicates whether this file asks the socket
4.1/home/www as a folder on my server
So the result of Test-e/home/www is 0, that is true, this file name exists
So the result of Test-f/home/www is not 0, that is, false, this file name is not a file
So the result of Test-d/home/www is 0, that is true, this file name is a folder
4.2 On my server/home/kkk this file name does not exist
So the result of Test-e/home/kkk is not 0, that is, false, this file name does not exist
So the result of test-d/home/kkk is not 0, that is, false, this file name does not ask a folder.
The above is the Linux logical command of the test command to use the method introduced, if you want to determine whether a condition is set up, you will use the command, you have learned?