Summary of Meaning of linux-test test mark

Source: Internet
Author: User

Flag of the test Representative meaning
1. Determine the "file type" for a file name, such as TEST-E filename indicates that there is no
-E Does the "file name" exist? Common
-F Does the "file name" exist and is a file? Common
-D Does the "file name" exist and are directories (directory)? Common
-B Does the "file name" exist and is a block device device?
-C Does the "file name" exist and is a character device unit?
-S Does the "file name" exist and is a Socket file?
-P Does the "file name" exist and is a FIFO (pipe) file?
-L Does the "file name" exist and is a link file?
2. Permission detection for files, such as Test-r filename indicates readable no (with the exception of root privileges)
-R Detects if the file name exists and has a "readable" permission?
-W Detects if the file name exists and has a "writable" permission?
-X Detect if the file name exists and have "can run" permissions?
-U Detects if the file name exists and has a "SUID" attribute?
-G Detects if the file name exists and has a "SGID" attribute?
-K Detects if the file name exists and has the attribute "Sticky bit"?
-S Detects if the file name exists and is "not a blank file"?
3. Comparison between two files, such as: Test file1-nt file2
-nt (newer than) to determine whether File1 is newer than file2
-ot (older than) to determine whether File1 is older than file2
-ef Determine whether File1 and File2 are the same file and can be used to judge hard Link's judgment. The main significance in determining whether two files are all pointing to the same inode!
4. A decision between two integers, such as test n1-eq N2
-eq Two values equal (equal)
-ne Two values unequal (not equal)
-gt N1 greater than N2 (greater than)
-lt N1 smaller than N2 (less than)
-ge N1 greater than N2 (greater than or equal)
-le N1 smaller than N2 (less than or equal)
5. Determining the data of a string
Test-z string Is the decision string 0? True if string is an empty string
Test-n string Is the decision string not 0? False if string is an empty string.
Note:-n can also be omitted
Test str1 = str2 Determines whether the str1 is equal to str2, and if so, the callback true
Test STR1! = str2 Determine if the str1 is not equal to str2, and if so, the callback is False
6. Multiple criteria determination, for example: Test-r filename-a-x filename
-A Both conditions are set up at the same time! For example Test-r file-a-x file, the file will return true if it has both R and X permissions.
-O (or) any one of the two conditions is established! For example Test-r file-o-x file, the file can return true if it has R or X permissions.
! Inverting state, such as test! -x file, which callbacks true when file does not have X

First, judge, let the user enter a file name, we judge:

1. If this file exists, give a "Filename does not exist" information and interrupt the program if it does not exist;
2. If the file exists, it is determined that he is a file or directory, the result output "filename is regular file" or "FileName is directory"
3. Determine the user's identity to the file or directory to have permissions, and output permission data!






The use of brackets is almost exactly the same as test. It's just that the brackets are more commonly used in conditional-judging if ... then ... fi. Well, then we also use the square brackets to make a small case of judgment. OK, the case configuration is as follows:

1. When running a program, this program will let the user choose Y or N,
2. If the user enters Y or y, the "OK, continue" is displayed
3. If the user enters n or n, it displays "Oh, Interrupt!" 』
4. If it is not the other byte within the y/y/n/n, it shows "I don t know what your choice is"





Default variable for Shell script ($ ...)

Run the script file named "$" variable, the first parameter is $ ~ ~ So, as long as we use in script, we can easily release some command function immediately! In addition to the variables of these numbers, we have a few more special variables that can be used within a script to call these parameters Oh!

$#: On behalf of the following parameters "number", the above table as an example shown here as "4";
[Email protected]: for "$" "" $ "" $ "" $ "" $4 "meaning, each variable is independent (enclosed in double quotation marks);
$*: Represents "$1c$2c$3c$4" ", where c is a delimited byte and the default is a blank key, so this example represents" $ $ $4 ".

That [email protected] and $* are basically different! However, the general use of the situation can be directly memory [email protected] can! All right, let's do an example. Let's say I'm going to run a script that can carry parameters, and the screen will display the following data when I run it:

What is the file name of the program?
How many parameters are there?
If the number of parameters is less than 2, it tells the user that the number of parameters is too low
What are all the parameters?
What is the first parameter?
Why the second parameter





Shift: Causes parameter variable number offset




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Summary of Meaning of linux-test test mark

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