The Linux shell script determines if the TTYUSB device node exists __linux

Source: Internet
Author: User
Tags readable

Using a shell to determine whether a device node exists, such as inserting a 4G Modem Sierra module into a Linux system, generates a series of TTY devices, typically with a command to send and receive at. For example, a device node is a/DEV/TTYUSB2 character device.


The judgment script is as follows:


WAIT_FOR_TTYUSB2 () {
While True
Todo
echo "dev= $TTY 2"
If [-C "$TTY 2"]; Then
echo "$TTY 2 is exist"
Break
Fi
echo "Wait for $TTY 2 ready, and check again after 1s"
Sleep 1s
Done
}


The following is a list of judgment conditions that correspond to the type of file or device type.

*-B FILE = True If the file exists and is block special file. If the file exists and is a block special file.
*-c File = True If the file exists and is character special file. If it exists and is a character special file
*-D file = True If the file exists and is directory. If the file exists and is a directory.
*-E File = True If the file exists. If the file exists
*-F file = True If the file exists and is a regular files if it exists and is a normal file
*-G File = True If the file exists and the Set-group-id bit is set. If the file exists and a group ID bit is set.
*-K File = True if the files ' sticky ' bit is set. If the sticky "sticky" bits of the file are set.
*-L FILE = True If the file exists and is a symbolic link. The file exists and is a symbolic link.
*-P file = True If the file exists and is a named pipe. The file exists and is a named pipe.
*-R file = True If the file exists and is readable. The file exists and is readable
*-S File = True If the file exists and its size is greater than zero. File exists, its size is greater than 0
*-S File = True If the file exists and is a socket. File exists and is a socket
*-t FD = True If the file descriptor is opened on a terminal. The file descriptor is opened on a terminal
*-U File = True If the file exists and its Set-user-id bit is set. File exists, its set user ID bit is set
*-W File = True If the file exists and is writable. File exists and can be written
*-X File = True If the file exists and is executable. The file exists and is executable
*-o file = True If the file exists and is owned by the effective user ID. File exists and is a valid user ID
*-G File = True If the file exists and is owned by the effective group ID. The file exists and has a valid GRUOP ID.

Referring to the instructions above, we have to judge that a file exists regardless of its type, so you can use-e, and if you want to check its type at the same time, then we can use the corresponding judgment criteria.

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.