- 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入門經典(第6版)
- C語言程序設計
- 3D少兒游戲編程(原書第2版)
- Spring+Spring MVC+MyBatis整合開發實戰
- Mastering React
- Regression Analysis with Python
- 大學計算機基礎實驗指導
- 從程序員角度學習數據庫技術(藍橋杯軟件大賽培訓教材-Java方向)
- 玩轉.NET Micro Framework移植:基于STM32F10x處理器
- Python Deep Learning
- Drupal Search Engine Optimization
- 深入理解Kafka:核心設計與實踐原理
- 前端架構設計
- Developer,Advocate!
- JavaScript高級程序設計(第4版)