- 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
推薦閱讀
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- 零基礎(chǔ)PHP學(xué)習(xí)筆記
- Java入門經(jīng)典(第6版)
- Learning Apex Programming
- Visual C++數(shù)字圖像模式識別技術(shù)詳解
- Machine Learning with R Cookbook(Second Edition)
- HTML5+CSS3基礎(chǔ)開發(fā)教程(第2版)
- Web Application Development with R Using Shiny(Second Edition)
- iPhone應(yīng)用開發(fā)從入門到精通
- Illustrator CC平面設(shè)計實戰(zhàn)從入門到精通(視頻自學(xué)全彩版)
- 軟件體系結(jié)構(gòu)
- Instant jQuery Boilerplate for Plugins
- Python Programming for Arduino
- Python預(yù)測分析實戰(zhàn)
- Web開發(fā)的平民英雄:PHP+MySQL