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

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
主站蜘蛛池模板: 泗阳县| 修武县| 安庆市| 靖西县| 房山区| 观塘区| 四川省| 时尚| 永和县| 丰城市| 阿拉善盟| 内丘县| 当阳市| 清涧县| 清镇市| 彭水| 伊通| 平果县| 乌审旗| 来凤县| 凌云县| 额济纳旗| 区。| 迭部县| 贵定县| 贡觉县| 延安市| 清远市| 板桥市| 绥滨县| 阳东县| 泸水县| 政和县| 邛崃市| 中西区| 获嘉县| 新乡市| 台中市| 明光市| 乌恰县| 桂阳县|