- 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/C++算法從菜鳥到達人
- PostgreSQL技術內幕:事務處理深度探索
- Raspberry Pi 2 Server Essentials
- Apex Design Patterns
- Android 應用案例開發大全(第3版)
- Learning Python Data Visualization
- 監控的藝術:云原生時代的監控框架
- Python機器學習與量化投資
- Yii2 By Example
- 深入淺出 HTTPS:從原理到實戰
- Kotlin語言實例精解
- Kohana 3.0 Beginner's Guide
- Effective C++:改善程序與設計的55個具體做法(第三版)中文版(雙色)
- 打造流暢的Android App
- Scratch 3.0少兒積木式編程(6~10歲)