Linux identifier []

Source: Internet
Author: User

A Brief Introduction to the use of Linux Operators

In Linux, the identifier can help us simplify a lot of unnecessary work and greatly improve our work efficiency. Here we will introduce the commonly used identifier in shell.

Linux identifier1. Detect (whether or not) the "type" of a file name, such as test-e filename
-E does this file name exist? (Common)
-F is this file name )? (Common)
-D is the "file name" a directory )? (Common)
-B. is the "file name" A block device?
-C is the "file name" A character device?
-S is this file name a socket file?
-P: Is this file name a FIFO (PIPE) file?
-L is this file name a link?

Linux identifier2. File Permission detection, such as test-r filename
-R checks whether the file name has the "readable" attribute?
-W: Does the file name have the "writable" attribute?
-X checks whether the file name has the "executable" attribute?
-U checks whether the file name has the "SUID" attribute?
-G: Does the file name have the "SGID" attribute?
-K checks whether the file name has the "Sticky Bit" attribute?
-S: Is this file named "non-blank file 』?

Linux identifier3. Comparison between two files, such as test file1-nt file2
-NT (newer than) determines whether file1 is newer than file2
-Ot (older than) determines whether file1 is older than file2
-Ef determines whether file2 and file2 are the same file and can be used to determine hard link. The main significance is to determine whether both files point to the same inode!

Linux identifier4. Determine between two integers, such as test N1-EQ N2
-Equal (equal)
-The ne two values are not equal)
-GT N1 is greater than N2 (greater)
-Lt N1 less than N2 (less)
-Ge N1 is greater than or equal to N2 (greater than or equal)
-Le N1 is less than or equal to N2 (less than or equal)

Linux identifier5. Identify string data
Test-Z string determines whether the string is 0? True if string is a Null String
Test-N string determines whether the string is not 0? If string is a null string, it is false.
Note:-N can also be omitted.
Test str1 = str2 determine whether str1 is equal to str2. If it is equal, return true
Test str1! = Str2 determines whether str1 is not equal to str2. If it is equal, return false.

Linux identifier6. Multiple condition determination, for example, test-r filename-a-x filename
-Both A (and) conditions are true! For example, if test-r file-a-X file has both R and X permissions, true is returned.
-O (OR! For example, if test-r file-o-x file has the R or X permission, true can be returned.
! Reverse state, such as test! -X file: returns true if file does not have X.

 

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.