2020-2021-1学期 20192428《THE LINUX COMMAND LINE 》读数笔记二

2020-2021-1学期 20192428《THE LINUX COMMAND LINE 》读数笔记二

首先请看我的脑图


④ MANIPULATINGFILES AND DIRECTORIES

本章将介绍五个最常用的Linux系统命令行指令:cd、mv、mkdir、rm、ln。实际上在图形化界面中我们对文件的操作非常容易,而Linux系统大多数也具有图形化界面,那么我们为什么还要去学这些command line呢?稍安勿躁,通过这一章的深层学习,我们就会明白命令行操作的简洁与强大。

书中举了一个例子:The answer is power and flexibility. While it is easy to perform simple file manipulations with a graphical file manager, complicated tasks can be easier with the command-line programs. For example, how could we copy all the HTML files from one directory to another—but only those that do not exist in the destination directory or are newer than the versions in the destination directory? Pretty hard with a file manager. Pretty easy with the command line:
cp -u *.html destination
是不是看不太明白?不明白就对啦,这里运用了wildcard(通配符),我们罗列几个表给诸位。

Before we begin using our commands, we need to talk about the shell feature that makes these commands so powerful. Because the shell uses filenames so much, it provides special characters to help you rapidly specify groups of filenames. These special characters are called wildcards. Using wildcards (also known as globbing) allows you to select filenames based on patterns of characters.

表一

wildcard Matches
* Any characters
? Any single character
[ ] Any character that is a member of the set characters
[! ] Any character that is not a member of the set characters
[[:class:]] Any character that is a member of the specified class

表二

Character Class Matches
[:alnum:] Any alphanumeric character
[:alpha:] Any alphabetic character
[:digit:] Any numeral
[:lower:] Any lowercase letter
[:upper:] Any uppercase letter

实际上表内的这种规范化,是对文件的相对精密的查找,或者说对文件的范围的规定,书中还举了几个例子来帮助我们消化理解:

Pattern Matches
g* Any file beginning with g
b*.txt Any file beginning with b followed by any characters and ending with .txt
Data??? characters and ending with .txt Data??? Any file beginning with Data followed by exactly three characters
[abc]* Any file beginning with either a, b, or c
BACKUP.[0-9][0-9][0-9] Any file beginning with BACKUP. followed by exactly three numerals
[[:upper:]]* Any file beginning with an uppercase letter
[![:digit:]]* Any file not beginning with a numeral
*[[:lower:]123] Any file ending with a lowercase letter or the numerals 1, 2, or 3

同时通配符对GUI界面也依然适用,如下图所说:

通配符将会在第七章中详细为大家解释,我们继续往下走。

mkdir操作

即简单的创建目录操作,操作指令如下:
输入:[me@linuxbox ~]$ mkdir test01 test02
验证:[me@linuxbox ~]$ ls
输出:test01 test02

cp操作

The cp command copies files or directories. It can be used two different ways:cp item1 item2 to copy the single file or directory item1 to file or directory item2 and: cp item... directory


上表是对cp操作的一些细化描述 (表二是重点,可以详细参阅)

mv操作

The mv command performs both file moving and file renaming, depending on how it is used. In either case, the original filename no longer exists after the operation. mv is used in much the same way as cp: mv item1 item2 to move or rename file or directory item1 to item2 or mv item... directory


同理,上表则是对mv操作的一些细化描述 (表二是重点,可以详细参阅)

rm操作

The rm command is used to remove (delete) files and directories, like this: rm item...


依然是对rm操作的细化描述,同时关于rm操作,书中特别举了个例子:

TIP:Whenever you use wildcards with rm (besides carefully checking your typing!), test the wildcard first with ls. This will let you see the files that will be deleted. Then press the up arrow key to recall the command and replace the ls with rm.
因为Linux太过信任你了,所以你的rm操作是不可恢复的,所以书中建议在rm操作时先将rm更换为ls操作,这样可以先勘察到你所选中的文件,在确定所选择范围正确后再进行rm操作。

ln操作

The ln command is used to create either hard or symbolic links. It is used in one of two ways: ln file link to create a hard link and ln -s item link to create a symbolic link where item is either a file or a directory.

第四章的最后,书主要是对以上五条命令操作的联系与运用,各位如果感兴趣可以多花一些功夫去攻读一下!

posted @ 2020-10-08 13:19  岁岁敲代码  阅读(160)  评论(1编辑  收藏  举报