linux综合编程:文件管理功能模块

编程实现一个简单的迷你型操作系统文件管理功能模块,基本功能包括:
(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**文件里,即可实现.

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值