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

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
主站蜘蛛池模板: 义马市| 任丘市| 台东市| 拉萨市| 朔州市| 元氏县| 五寨县| 内乡县| 垫江县| 永嘉县| 宜州市| 阳西县| 古浪县| 石柱| 和政县| 宜良县| 临沧市| 阿鲁科尔沁旗| 隆昌县| 常宁市| 桦甸市| 连云港市| 佛学| 普兰店市| 屯留县| 临颍县| 西和县| 武定县| 富锦市| 金沙县| 孟州市| 延长县| 景东| 临夏县| 年辖:市辖区| 河东区| 合川市| 同江市| 崇阳县| 锦州市| 阿坝县|