- 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
推薦閱讀
- Java Web程序設計
- Hands-On Automation Testing with Java for Beginners
- Python時間序列預測
- Procedural Content Generation for C++ Game Development
- Java Web開發就該這樣學
- App Inventor 2 Essentials
- SQL Server 入門很輕松(微課超值版)
- Simulation for Data Science with R
- 進入IT企業必讀的324個Java面試題
- Java程序設計實用教程(第2版)
- 安卓工程師教你玩轉Android
- Java 7 Concurrency Cookbook
- Java EE 7 Development with WildFly
- 優化驅動的設計方法
- Moodle 3.x Developer's Guide