2.4《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——小结

下Table 3本章重要命令小结

命令 描述 示例
> 将输出内容重定向到指定文件中 $ echo foo > foo.txt
>> 将输出内容添加到指定问价中 $ echo bar >> foo.txt
cat <file> 在屏幕上输出文件内容 $ cat hello.txt
diff <f1> <f2> 比较文件1和2的差异 $ diff foo.txt bar.txt
ls 列出文件或目录 $ ls hello.txt
ls -l 以长列表形式列出文件或目录 $ ls -l hello.txt
ls -rtl 根据修改时间反转并以长表形式列出文件或目录 $ ls -rtl
ls -a 列出所有文件(包括隐藏文件) $ ls -a
touch <file> 创建空文件 $ touch foo
mv <old> <new> 给文件重命名 $ mv foo bar
cp <old> <new> 复制文件到 $ cp foo bar
rm <file> 移除(删除)文件 $ rm foo
rm -f <file> 强制移除文件 $ rm -f bar
Table3: 第二章重要命令

练习

FRom faireſt creatures we deſire increaſe,
That thereby beauties Roſe might neuer die,
But as the riper ſhould by time deceaſe,
His tender heire might beare his memory:
But thou contracted to thine owne bright eyes,
Feed’ſt thy lights flame with ſelfe ſubſtantiall fewell,
Making a famine where aboundance lies,
Thy ſelfe thy foe,to thy ſweet ſelfe too cruell:
Thou that art now the worlds freſh ornament,
And only herauld to the gaudy ſpring,
Within thine owne bud burieſt thy content,
And tender chorle makſt waſt in niggarding:
Pitty the world,or elſe this glutton be,
To eate the worlds due,by the graue and thee.

*插图17: 莎士比亚十四行诗复制版本*
1.通过复制粘贴插图17的HTML 版本,使用`echo`创建一个名叫`sonnet_1_complete.txt`的文件,文件内容要包含莎士比亚十四行诗。注意:但你使用`echo`时可能会遇到一个未匹配的双引号([第1.2章和Box 4](http://www.cnblogs.com/AliceX-J/p/8482826.html)中),如`echo "`,但是这样允许你输入多行文本。记住在最后输入关闭引号,并且将内容重定向到一个适合的文件中,并为它取个适合的名字。用`cat`验证内容是否输入正确。([图14](http://www.cnblogs.com/AliceX-J/p/8521666.html)). 2.输入适合的命令,创建一个名为`foo`的文件,再将它重新命名为`bar`,最后复制它到`baz`文件中。 3.什么命令能只列出以字母`b`开始的文件?注意:使用通配符。 4.只使用一次`rm`命令同时删除`bar`和`baz`文件。备注:如果当前目录只有两个文件以字母`b`开始,你可以像之前的练习那样使用通配符。
原文地址:https://www.cnblogs.com/AliceX-J/p/8556886.html