- Bash Cookbook
- Ron Brash Ganesh Naik
- 196字
- 2021-07-23 19:17:40
How to do it...
Let's begin our activity as follows:
- 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"
}
- Execute the script and try to access the various files, including the directories and files that do not exist. What do you notice?
- Remove the folder now with this command:
$ sudo rm -rf fileops
推薦閱讀
- C++面向對象程序設計(第三版)
- Learning Neo4j
- OpenStack Cloud Computing Cookbook(Fourth Edition)
- JavaScript 程序設計案例教程
- QGIS Python Programming Cookbook(Second Edition)
- Python機器學習算法與應用
- Swift語言實戰(zhàn)晉級
- Troubleshooting Citrix XenApp?
- JavaScript+jQuery網頁特效設計任務驅動教程
- Python函數(shù)式編程(第2版)
- jQuery技術內幕:深入解析jQuery架構設計與實現(xiàn)原理
- 視窗軟件設計和開發(fā)自動化:可視化D++語言
- 程序員的成長課
- Greenplum構建實時數(shù)據(jù)倉庫實踐
- Laravel Design Patterns and Best Practices