linux脚本练习1

Posted So istes immer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux脚本练习1相关的知识,希望对你有一定的参考价值。

用linux指令实现下列功能,所有指令放在一个脚本文件中,并验证能够正确执行。
验证方法是使用bash hw0_1.sh,观察结果是否输出正确,这里假设你的脚本文件名称是hw0_1.sh。功能需求如下(共10个需求):
    1.  You want to create a one-line file without having to use an editor.
    2.  You want to create a new directory by using the Terminal.
    3.  You want to delete a file or directory using the Terminal.
    4.  You need to change the permissions of a file.
    5.  You want to find a file that you know is on the system somewhere.
    6.  You want to quickly create a file with some text or record a directory listing into a file.
    7.  You have a number of text files, and you want to join them into one big file.
    8.  You want to use the output of one Linux command as the input to another command.
    9. You want to run a command, but you don’t want the output filling up your screen.
    10. You want to create aliases (shortcuts) to commands that you use frequently.

我们来翻译翻译需求

1. 不用文本编辑器,向一个文件写入单行文本
2. 使用终端创建一个新目录
3. 使用终端删除一个文件或目录
4. 更改文件的权限
5. 查找系统某个位置上的文件
6. 快速创建一些带有文本的文件或者将一个目录列表记录到一个文件中
7. 将许多文本文件合并成一个大文件
8. 用一个linux指令的输出成为另一个指令的输入
9. 运行一个命令,避免让输出占满整个屏幕
10. 为经常使用的快捷键创建别名(快捷方式)

文件可以本地写好,命名为test.txt,传到l再inux服务器上,但考虑到windows系统的换行是\\r\\n,linux系统的换行是\\n,所以要处理一下test.txt,如下
sed -e "s/\\r//g" test.txt > hw0_1.sh

以上是关于linux脚本练习1的主要内容,如果未能解决你的问题,请参考以下文章

Linux下shell脚本中信号捕获和函数练习脚本之ping一个网段

Linux运维---shell脚本练习串烧1

Linux下shell脚本中信号捕获和函数练习脚本之ping一个网段

linux脚本练习1

linux脚本练习2

linux 学习基础7之脚本的练习