1. 程式人生 > 實用技巧 >2020-2021-1學期 20192428《THE LINUX COMMAND LINE 》讀數筆記二

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