2017年4月9日 星期日

0407linux上課心得

由於這週為期中考週之前兩週,故先來做個考前重點猜題與整理,以下為其內容:

1.          LINUX中,何謂Shell

shell是傳統的使用者和電腦的互動介面,就是可以接受使用者輸入命令的程式。BashLinux將其作為預設shell
必須要透過『 Shell 』將我們輸入的指令與 Kernel(核心) 溝通,好讓 Kernel 可以控制硬體來正確無誤的工作。
也就是說,只要能夠操作應用程式的介面都能夠稱為殼程式(shell)。狹義的殼程式指的是指令列方面的軟體。
Linux 使用的這一種版本就稱為『 Bourne Again SHell (簡稱 bash) 』,這個 Shell Bourne Shell 的增強版本,也是基準於 GNU 的架構下發展出來的。

2.          LINUX中,Shell提示字元為何?請舉例並簡述之。

在虛擬終端機我們可以看到user@debian404040339:~$」,此行為提示字元,通常由用戶名稱@機器名稱起頭, 再加上當前的目錄,以及錢號「$」。若最後的字元是「#」號, 則表示在超級使用者的權限下運作。

3.          請舉例這學期所學之指令,並簡述之。(當然還有很多)

cat - Concatenate files 連結文件
cat 命令讀取一個或多個文件,然後復制它們到標準輸出
sort - Sort lines of text 排序文字檔案的列
幫我們進行排序,而且可以依據不同的資料型態來排序
uniq - Report or omit repeated lines 報導或省略重複列
排序完成了,想要將重複的資料僅列出一個顯示
grep - Print lines matching a pattern 列出一樣、符合的列
wc - Print newline, word, and byte counts for each file 列印檔案中分行符號,字,和位元組個數
想知道這個檔案裡面有多少字?多少行?多少字元,可以利用 wc 這個指令來達成
head - Output the first part of a file 輸出文件第一部分
顯示出一個檔案的前幾行
tail - Output the last part of a file 輸出文件最後一部分
顯示的是後面幾行
tee - Read from standard input and write to standard output and files Stdin讀取資料,並同時輸出到Stdout和檔案
4.          指令的類型分為哪四種
(1)   可執行程式。
是一個可執行程式,就像我們所看到的位於目錄/usr/bin中的檔案一樣。屬於這一類的程式,可以編譯成二進位檔案,也可以是由指令碼語言寫成的程式。
(2)   內建於 shell 的命令。
是一個內建於shell自身的命令,bash支持若干種命令。內部命令叫做shell builtins
(3)   shell 的函數。
(4)   別名。
是一個命令別名。可以定義屬於自己的命令,建立在其它命令之上。
舉例:
1)                           user@debian404040339:~$ type date
date is /bin/date為可執行程式。
2)                           user@debian404040339:~$ type cal
cal is /usr/bin/cal為可執行程式。
3)                           user@debian404040339:~$ type df
df is /bin/df為可執行程式。
4)                           user@debian404040339:~$ type free
free is /usr/bin/free為可執行程式。
5)                           user@debian404040339:~$ type exit
exit is a shell builtin內建於 shell 的命令。
6)                           user@debian404040339:~$ type pwd
pwd is a shell builtin內建於 shell 的命令。
7)                           user@debian404040339:~$ type cd
cd is a shell builtin內建於 shell 的命令。
8)                           user@debian404040339:~$ type ls
ls is aliased to `ls --color=auto' 為最先使用之aliase
9)                           user@debian404040339:~$ type cd -
cd is a shell builtin內建於 shell 的命令。
bash: type: -:沒有找到
10)                        user@debian404040339:~$ type file
file is /usr/bin/file為可執行程式。
11)                        user@debian404040339:~$ type less
less is /usr/bin/less為可執行程式。
12)                        user@debian404040339:~$ type cp
cp is /bin/cp為可執行程式。
13)                        user@debian404040339:~$ type mv
mv is /bin/mv為可執行程式。
14)                        user@debian404040339:~$ type mkdir
mkdir is /bin/mkdir為可執行程式。
15)                        user@debian404040339:~$ type rm
rm is /bin/rm為可執行程式。
16)                        user@debian404040339:~$ type ln
ln is /bin/ln為可執行程式。
5.          linux中,請說出何謂標準輸入、輸出、與錯誤訊息Standard Input, Output, And Error

輸出分為兩個部份:執行程式的結果、 狀態與錯誤訊息。
預設情況下,標準輸出和標準錯誤都連接到屏幕,而標準輸入連接到鍵盤。
標準輸出0,標準輸入1,標準錯誤2[me@linuxbox ~]$ ls -l /bin/usr 2> ls-error.txt多了一個2,其稱之為檔案描述語(詞),012分別為stdinstdout stderr

6.          請簡述ASCLL?控制字元?

ASCLL是基於拉丁字母的一套電腦編碼系統。它主要用於顯示現代英語,而其擴展版本EASCII則可以部分支援其他西歐語言,並等同於國際標準ISO/IEC 646
ASCII第一次以規範標準的型態發表是在1967年,最後一次更新則是在1986年,至今為止共定義了128個字元;其中33個字元無法顯示(一些終端提供了擴充功能,使得這些字元可顯示為諸如笑臉、撲克牌花式等8-bit符號),且這33個字元多數都已是陳廢的控制字元。
控制字元的用途主要是用來操控已經處理過的文字。在33個字元之外的是95個可顯示的字元。用鍵盤敲下空白鍵所產生的空白字元也算1個可顯示字元(顯示為空白)。
控制字元有兩種表示法,分別為Unicode表示法與脫出字元表示法。
Unicode表示法:當我們想在畫面或紙張上表示這些控制字元時,就會顯示成這個樣子。過於老舊的系統或瀏覽器可能會看不到。文輸入法,輸入`U2400即可看到

,輸入`U2401可看到

 ,依此類推。



7.          進位轉換






















參考資料:
 1鳥歌的Linux私房菜。2017/04/09取自:http://linux.vbird.org/linux_basic/0320bash.php#bash
2.ASCLL。維基百科。2017/04/09取自:https://zh.wikipedia.org/wiki/ASCII


2017年4月6日 星期四

Linux桌面系統3/24

任何東西都是一個文件
以is為例,全稱為list。螢幕也是一個檔案。

第六章 Redirection 重新導向

cat - Concatenate files 連結文件
              cat 命令讀取一個或多個文件,然後復制它們到標準輸出
sort - Sort lines of text 排序文字檔案的列
                幫我們進行排序,而且可以依據不同的資料型態來排序
uniq - Report or omit repeated lines 報導或省略重複列
                 排序完成了,想要將重複的資料僅列出一個顯示
grep - Print lines matching a pattern 列出一樣、符合的列
                 
wc - Print newline, word, and byte counts for each file 列印檔案中分行符號,字,和位元組個數
                 想知道這個檔案裡面有多少字?多少行?多少字元,可以利用 wc 這個指令來達成
head - Output the first part of a file 輸出文件第一部分
                  顯示出一個檔案的前幾行
tail - Output the last part of a file 輸出文件最後一部分
                  顯示的是後面幾行
tee - Read from standard input and write to standard output and files 從Stdin讀取資料,並同時輸出到Stdout和檔案

Standard Input, Output, And Error 標準輸入,輸出,和錯誤

執行程式程序,會得到兩種結果:


        1First, we have the program's results; that is, the data the program is designed to produce
                             第一,程序運行結果;這是說,程序要完成的功能。
        2 we have status and error messages that tell us how the program is getting along.
                             第二,我們得到狀態和錯誤信息, 這些告訴我們程序進展。



stdin 標準輸入
stdout 標準輸出
stderr 標準錯誤

預設情況下,標準輸出和標準錯誤都連接到屏幕
預設情況下, 標準輸入連接到鍵盤。

[me@linuxbox ~]$ ls -l /usr/bin > ls-output.txt
          -把ls 命令的運行結果輸送到文件ls-output.txt 中去, 由文件代替屏幕。
            創建了一個長長的目錄/usr/bin 列表,並且輸送程序運行結果到文件ls-output.txt 中。
[me@linuxbox ~]$ ls -l /bin/usr > ls-output.txt
ls: cannot access /bin/usr: No such file or directory
          -收到一個錯誤信息。指定了一個不存在的目錄/bin/usr, 但是為什麼這條錯誤信息顯示在屏幕上而不是被重定向到文件ls-output.txt?答案是, ls 程序不把它的錯誤信息輸送到標準輸出。反而,ls 把錯誤信息送到標準錯誤。而我們只是重定向了標準輸出,而沒有重定向標準錯誤, 所以錯誤信息被送到屏幕。

標準輸出0,標準輸入1,標準錯誤2

[me@linuxbox ~]$ ls -l /bin/usr 2> ls-error.txt
多了一個2,其稱之為檔案描述語(詞),0,1,2分別為stdin,stdout ,stderr

重定向標準輸出和錯誤到同一個文件

[me@linuxbox ~]$ ls -l /bin/usr > ls-output.txt 2>&1
[me@linuxbox ~]$ ls -l /bin/usr &> ls-output.txt
ls -l /bin/usr &> ls-output.txt一個箭頭為新增
ls -l /bin/usr &>> ls-output.txt兩個箭頭為appended
cat – Concatenate Files
後面的參數可以是多個檔案,less後面只能有一個。cat並且能將檔案合為一個檔案。
若只輸入cat,不會有任何反應,但只要輸入任何文字,其將會顯示一模一樣的文字。
而ctrl +d告訴它已經輸入完畢。
command1 > file1 箭頭為送給檔案
command1 | command2面對檔案
sort為排序
unig為唯一
uniq通常會跟sort一起出現 ,意思是把重複者刪除
wc – Print Line, Word, And Byte Counts有幾行幾個自己的byte
grep – Print Lines Matching A Pattern去檔案之中去抓取符合檔案格式之檔案

 ls /bin /usr/bin | sort | uniq | grep zip-i忽略大小寫
 ls /bin /usr/bin | sort | uniq | grep zip-v不要zip這三個字母的檔案

tee – Read From Stdin And Output To Stdout And Files   從stdin讀取檔案,在輸出存取到檔案中。
tee 的工作流程示意圖


2017年3月23日 星期四

0317linux上課心得

今天仍然到5A進行linux的指令操作。而上課一開始,老師便教導我們,有哪些命令類型並如何觀看,根據The Linux Command Line,命令可分為四種類型,分別為:

  1. 可執行程式。An executable program like all those files we saw in /usr/bin. Within this category,programs can be compiled binaries such as programs written in C and C++, or programs written inscripting languages such as the shell, perl, python, ruby, etc是一個可執行程式,就像我們所看到的位於目錄/usr/bin 中的檔一樣。 屬於這一類的程式,可以編譯成二進位檔案,諸如用 C  C++語言寫成的程式也可以是由指令碼語言寫成的程式,比如說 shellperlpythonruby,等等。
  2.  內建於 shell 的命令。A command built into the shell itself. bash supports a number of commands internally called shell builtins. The cd command, for example, is a shell builtin.是一個內建於 shell 自身的命令。bash 支持若干命令,內部叫做 shell 內部命令 (builtins)。例如,cd 命令,就是一個 shell 內部命令。
  3. shell 的函數。A shell function. These are miniature shell scripts incorporated into the environment. We will cover configuring the environment and writing shell functions in later chapters, but for now, just be aware that they exist. 是一個 shell 函數。這些是小規模的 shell 腳本,它們混合到環境變數中。 在後續的章節裡,我們將討論配置環境變數以及書寫 shell 函數。但是現在, 僅僅意識到它們的存在就可以了。
  4. 別名。An alias. Commands that we can define ourselves, built from other commands.是一個命令別名。我們可以定義自己的命令,建立在其它命令之上。
將目前所學之指令前面加上"type",即可觀看其指令之類型。以下依序列出目前所學之指令並介紹其屬於哪種指令類型,共十六個:
(1)      user@debian404040339:~$ type date
date is /bin/date為可執行程式。
(2)      user@debian404040339:~$ type cal
cal is /usr/bin/cal為可執行程式。
(3)      user@debian404040339:~$ type df
df is /bin/df為可執行程式。
(4)      user@debian404040339:~$ type free
free is /usr/bin/free為可執行程式。
(5)      user@debian404040339:~$ type exit
exit is a shell builtin內建於 shell 的命令。
(6)      user@debian404040339:~$ type pwd
pwd is a shell builtin內建於 shell 的命令。
(7)      user@debian404040339:~$ type cd
cd is a shell builtin內建於 shell 的命令。
(8)      user@debian404040339:~$ type ls
ls is aliased to `ls --color=auto' 最先使用之aliase。(為別名)
(9)      user@debian404040339:~$ type cd -
cd is a shell builtin內建於 shell 的命令。
bash: type: -:沒有找到
(10) user@debian404040339:~$ type file
file is /usr/bin/file為可執行程式。
(11) user@debian404040339:~$ type less
less is /usr/bin/less為可執行程式。
(12) user@debian404040339:~$ type cp
cp is /bin/cp為可執行程式。
(13) user@debian404040339:~$ type mv
mv is /bin/mv為可執行程式。
(14) user@debian404040339:~$ type mkdir
mkdir is /bin/mkdir為可執行程式。
(15) user@debian404040339:~$ type rm
rm is /bin/rm為可執行程式。
(16) user@debian404040339:~$ type ln
ln is /bin/ln為可執行程式。

11個可執行程式,4個內建於 shell 的命令,0個為shell 的函數,1個別名。
以下為指令在終端機的呈現:




參考資料: