Logical test of Linux basic commands one

Source: Internet
Author: User

1. Determine the result of a command using test, which returns 0, or an integer. Returns 0 for true, returns an integer indicating the error code

2. Get the return result of the previous command using $?

3. For example

My server has/home/www such a folder, so ls/home/www The return result of this command is 0;

That is, echo $? Returns a value of 0

My server does not exist/home/kkk such a folder, so ls/home/kkk the return of this command is the command after the execution of the error code;

That is, echo $? Returns a result of 2. This 2 indicates that the file or folder does not exist.

4. Commonly used file test characters

-E Indicates whether this file name exists

-F Indicates whether this filename is a file

-D Indicates whether this file name is a folder

-R Indicates whether this file name is readable

-W Indicates whether this file is writable

-X Indicates whether this file is executable

-S Indicates whether this file asks the socket

4.1/home/www to a folder on my server

So the result of Test-e/home/www is 0, which is true, this file name exists

So the result of Test-f/home/www is not 0, which is false, this filename is not a file

So the result of Test-d/home/www is 0, which is true, this file is named folder

4.2/HOME/KKK This file name does not exist on my server

So the result of Test-e/home/kkk is not 0, which is false, this file name does not exist

So the result of test-d/home/kkk is not 0, which is false, this file name does not ask the folder.

Logical test of Linux basic commands one

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.