官术网_书友最值得收藏!

How to do it...

Let's begin our activity as follows:

  1. Open a new terminal and start an editor of your choice and create a new script. The following is a code snippet from the script:
#!/bin/bash
FILE_TO_TEST=""

function permissions() {

echo -e "\nWhat are our permissions on this $2?\n"
if [ -r $1 ]; then
echo -e "[R] Read"
fi
if [ -w $1 ]; then
echo -e "[W] Write"
fi
if [ -x $1 ]; then
echo -e "[X] Exec"
fi
}

function file_attributes() {

if [ ! -s $1 ]; then
echo "\"$1\" is empty"
else
FSIZE=$(stat --printf="%s" $1 2> /dev/null)
RES=$?
if [ $RES -eq 1 ]; then
return
else
echo "\"$1\" file size is: ${FSIZE}\""
fi
fi

if [ ! -O $1 ]; then
echo -e "${USER} is not the owner of \"$1\"\n"
fi
if [ ! -G $1 ]; then
echo -e "${USER} is not among the owning group(s) for \"$1\"\n"
fi

permissions $1 "file"

}
  1. Execute the script and try to access the various files, including the directories and files that do not exist. What do you notice?
  2. Remove the folder now with this command:
$ sudo rm -rf fileops
主站蜘蛛池模板: 莲花县| 龙井市| 高碑店市| 嵩明县| 兴安盟| 苗栗市| 穆棱市| 开化县| 湘潭市| 资溪县| 湖州市| 庄河市| 平凉市| 松潘县| 天台县| 民勤县| 武强县| 剑河县| 兴安县| 福州市| 吉首市| 渭南市| 江西省| 霍城县| 沙洋县| 柞水县| 桑日县| 华亭县| 防城港市| 连云港市| 美姑县| 湘乡市| 江永县| 黎川县| 牡丹江市| 浮梁县| 左权县| 木兰县| 方正县| 揭东县| 阿尔山市|