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

  • Bash Cookbook
  • Ron Brash Ganesh Naik
  • 196字
  • 2021-07-23 19:17:40

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
主站蜘蛛池模板: 本溪| 尚义县| 崇阳县| 赣州市| 昭觉县| 右玉县| 北流市| 天全县| 维西| 阿拉善左旗| 江油市| 合阳县| 青铜峡市| 故城县| 日照市| 祥云县| 通榆县| 克什克腾旗| 永福县| 广饶县| 封丘县| 绩溪县| 四子王旗| 旅游| 曲麻莱县| 绵竹市| 肥城市| 哈尔滨市| 门头沟区| 和平县| 建宁县| 通渭县| 丰顺县| 枞阳县| 新闻| 周至县| 镇江市| 抚顺县| 行唐县| 四会市| 都安|