Usage of the test command in Unix

Source: Internet
Author: User
Function of the test Command: check files and compare values. 1. determine the expression iftest (the expression is true) iftest! (Expression is false) test expression 1-a expression 2 both are true test expression 1-o expression 2 two expressions have one true 2, test-n character... function of the test Command: check files and compare values.
 
 
1. judgment expression
 
If test (expression true)
 
If test! (Expression is false)
 
Test expression 1-
Expression 2: both expressions are true.
 
Test expression 1-o
Expression 2: either of the two expressions is true.
 
 
2,
 
The length of the test-n string is non-zero.
 
The length of the test-z string is zero.
 
Test string 1 = String 2
Equal strings
 
Test string 1! = String 2
Character string
 
 
3. judge integer
 
Test integer 1-ep integer 2 integer equal
 
Test integer 1-ge integer 2 integer 1 is greater than or equal to integer 2
 
Test integer 1-gt integer 2 integer 1 is greater than integer 2
 
Test integer 1-le integer 2 integer 1 less than or equal to integer 2
 
Test integer 1-lt integer 2 integer 1 less than integer 2
 
Test integer 1-ne integer 2 integer 1 is not equal to integer 2
 
 
4. file judgment
 
Test File1-ef File2 two files have the same device number and node number
 
Test File1-nt File2 file 1 is newer than file 2
 
Test File1-ot File2 file 1 is older than file 2
 
The test-B File exists and is a block device File.
 
The test-c File exists and is a character device File.
 
The test-d File exists and is a directory.
 
The test-e File exists.
 
The test-f File exists and is a regular File.
 
The test-g File exists and the group ID is set.
 
The test-G File exists and belongs to the valid group ID.
 
The test-h File exists and is a symbolic link (same as-L)
 
The test-k File exists and the sticky bit is set.
 
The test-B File exists and is a block device File.
 
The test-L File exists and is a symbolic link (same as-h)
 
The test-o File exists and is a valid user ID.
 
The test-p File exists and is a named pipe.
 
The test-r File exists and is readable.
 
The test-s File exists and is a socket.
 
The test-t FD file descriptor is opened on a terminal.
 
The test-u File exists and its set-user-id bit is set.
 
The test-w File exists and can be written.
 
The tes-x File exists and can be executed.
Z
From song_0521
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.