[Shell] determine the directory Read and Write Permissions

Source: Internet
Author: User

Learn shell exercises

Check whether the/tmp/lzz directory has the read/write permission. If not, add the permission.


#!/bin/bash#name: testdir.sh#authro: orangleliu#date: 2014-08-03#version: v1.0#===================TestDir="/tmp/lzz"#===================#function -> Chenck_Dir()#===================Check_Dir(){if [ -d "$TestDir" ]then    TW=`ls -ld /tmp/lzz/|awk '{print $1}'|sed 's/d//g'|grep 'w'|wc -l`    TR=`ls -ld /tmp/lzz/|awk '{print $1}'|sed 's/d//g'|grep 'r'|wc -l`    if [ "$TW" -ne 0 -a "$TR" -ne 0 ]    then        echo "$TestDir can writted and readed !"    else        echo "$TestDir can not writted and readed !"        echo -n "Do you add write and rend authority [Y|N]"        read tt        case $tt in            Y|y)            chmod 755 $TestDir                if [ $? -eq 0 ]                then                    echo "add write and read authority ok ...."                else                    echo "add write add read authority fail...."                    return 1                fi            ;;            N|n)                return 1            ;;            *)                echo "error"                return 1            ;;        esac    fielse    echo "not have this dir"    return 1fi}#======================#function -> Main()#=====================Main(){Check_Dir    if [ $? -eq 1 ]    then    exit 1    fi}Main

This article is from the "orangleliu notebook" blog, please be sure to keep this http://blog.csdn.net/orangleliu/article/details/38367237

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.