In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to use the test command of Linux". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Linux common commands the test command is a utility for testing conditional expressions in the shell environment.
Grammar
Test (option) option
-b: true if the file is a block special file;-c: true if the file is a character special file;-d: true if the file is a directory;-e: true if the file exists;-f: true if the file is an ordinary file;-g: true if the SGID bit of the file is set;-G: true if the file exists and belongs to the group -k: true if the adhesion bit of the file is set;-O: true if the file exists and belongs to the user;-p: true if the file is a named pipe;-r: true if the file is readable;-s: true if the length of the file is not zero;-S: true if the file is a special socket file;-u: true if the SUID bit of the file is set -w: true if the file is writable;-x: true if the file is executable. Example
Common uses of test in shell programming in linux:
Judgment expression
If test # expression is true if test! # expression is false test expression 1-an expression 2 # both expressions are true test expression 1-o expression 2 # one of the two expressions is true test expression 1! Expression 2 # conditional inverse judgment string
Test-n string # the length of the string is non-zero test-z string whether the length of the string is zero test string 1 = string 2 # string is equal, if equal returns truetest string 1equal = string 2 # string is unequal, if it is not equal, false judges the integer
Test Integer 1-eq Integer 2 # Integer Equal test Integer 1-ge Integer 2 # Integer 1 greater than or equal to Integer 2test Integer 1-gt Integer 2 # Integer 1 greater than Integer 2test Integer 1-le Integer 2 # Integer 1 less than Integer 2test Integer 1-lt Integer 2 # Integer 1 less than Integer 2test Integer 1-ne Integer 2 # Integer 1 is not equal to Integer 2
Test File1-ef File2 whether the two files are the same file, can be used for hard connection. Mainly determine whether two files point to the same inode. Test File1-nt File2 determines whether file 1 is newer than file 2 test File1-ot File2 determines whether file 1 is older than file 2 whether old test-b file # file is block device file test-c File # file and is character device file test-d File # file and directory test-e File # file exists (commonly used) test-f File # file is regular file (commonly used) Whether the test-g File # file is set to a group idtest-G File # file belongs to a valid group IDtest-h File # file is a symbolic link (same as-L) test-k File # file is set Sticky bit bit test-b File # file exists and is a block device file test-L File # file is a symbolic link (same as-h) test-o File # file is valid User IDtest-p File # file is a named pipe test-r File # file readable test-s File # file is a non-blank file test-t FD # file descriptor is opened on a terminal test-u File # file exists and sets its set-user-id bit test-w File # file exists and writable test-x File # file exists and executable This is the end of the content of "how to use Linux's test command". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.