编程实现一个简单的迷你型操作系统文件管理功能模块,基本功能包括:
(1) 显示系统当前用户,当前工作目录。
(2) 显示指定文本文件的内容,文件名称由键盘输入。
(功能类似命令 cat aa.txt )
(3) 显示指定文件的名称,大小,权限等信息,文件名称由键盘输入。
(功能类似命令 ls –l aa.txt )
(4) 文件复制功能,源文件,目标文件名均由键盘输入
(功能类似命令cp aa.txt bb.txt )
(5)创建文件功能(文本文件),文件名由键盘输入,要求判断是否有重名文件存在,如有给出提示,是覆盖原有文件,还是以另外的名字创建。
(功能类似命令touch aa.txt )
个人是用shell实现
menu()
{
echo "Please choose the number for the function you need!"
echo "Input 1 : Display file contents!"
echo "Input 2 : Display file information!"
echo "Input 3 : File copy!"
echo "Input 4 : Create a file!"
echo ""
}
branch()
{
read -p "Please input your choice: " num
case $num in
"1")
read -p "Please input the file's name you want to know the content:" file1
cat $file1
echo "success!"
;;
"2")
read -p "Please input the file's name you want to know the information:" file2
stat $file2
ls -l $file2
;;
"3")
read -p "Please input the file's name you want to copy:" file3
read -p "Please enter the file's name to you want to copied:" file4
echo "files to copy"
cat $file3
echo "files to copied:"
cat $file4
cp $file3 $file4
echo "files to copy"
cat $file3
echo "files to copied:"
cat $file4
;;
"4")
read -p "Please input the file's name you want to create:" dir
if [ -f "$dir" ]; then
echo "it is exists $dir file"
else
echo "the file not exist"
read -p "是否要创建此文件啊?Y/N" answer
case $answer in
[yY][eE][sS]|[yY])
echo "establish the file"
touch "$dir"
echo "created sucessfull"
;;
[nN][oO]|[nN])
echo "stop creating"
;;
*)
echo "Invalid input"
;;
esac
fi
;;
*)
echo "error"
;;
esac
}
echo "user name = ${USER}" //显示系统当前用户
workdir=$(cd $(dirname $0); pwd) //当前工作目录
echo $workdir
for i in $( seq 1 10) //循环
do
menu
branch
if [ $i -eq 10 ]; then
echo "error"
fi
done
如果要用可以直接把上面的代码写在同一个**.sh**文件里,即可实现.