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個別名。
以下為指令在終端機的呈現:




參考資料:

2017年3月12日 星期日

0310LINUX上課心得

首先,先來介紹長板格式輸出,指令為"ls -l",ls為瀏覽違建之指令,輸入後能看見該檔案之文件目錄,而後面加" -l"可使輸出變為長板格式輸出,以下舉例說明:

user@debian404040339:~$ ls -l oo-welcome.odt

輸出結果可能看到:

-rw-r--r-- 1 root root 453764 2017-03-10 09:05 oo-welcome.odt

  • -rw-r--r--為近用權限,依序為: 檔案類型、檔案擁有者(3 位元組)、 群組、 其他人。開頭"-"說明它是一個普通文件
  • l  為硬式連結號,說明其連接之數目
  • root為擁有者名稱
  • 第二個root為擁有者群組名稱
  • 453764為文件長度(檔案大小)
  • 2017-03-10 09:05為最近一次修改時間
  • oo-welcome.odt檔案名稱

再者,介紹ASCLL。


ASCLL是基於拉丁字母的一套電腦編碼系統。它主要用於顯示現代英語,而其擴展版本EASCII則可以部分支援其他西歐語言,並等同於國際標準ISO/IEC 646。



ASCII第一次以規範標準的型態發表是在1967年,最後一次更新則是在1986年,至今為止共定義了128個字元;其中33個字元無法顯示(一些終端提供了擴充功能,使得這些字元可顯示為諸如笑臉、撲克牌花式等8-bit符號),且這33個字元多數都已是陳廢的控制字元。

控制字元的用途主要是用來操控已經處理過的文字。在33個字元之外的是95個可顯示的字元。用鍵盤敲下空白鍵所產生的空白字元也算1個可顯示字元(顯示為空白)。

控制字元有兩種表示法,分別為Unicode表示法與脫出字元表示法:

1.Unicode表示法:
當我們想在畫面或紙張上表示這些控制字元時,就會顯示成這個樣子。過於老舊的系統或瀏覽器可能會看不到。

2.脫出字元表示法:
通常用於終端機連線(例如Telnet通訊協定),以脫出字元^開頭,再接一個符號,用來讓這些控制字元得以在畫面上顯現。雖然看起來是兩個字元,但在終端機上實際只有一個字元。在絕大部分的終端機系統中,包括Windows的命令提示字元(cmd.exe)、Linux和FreeBSD,都可用Ctrl代表脫出字元,輸入想要的ASCII控制字元。例如想輸入空字元,就要輸入Ctrl+2,而非^@,後者會顯示成兩字元,前者只會顯示成一字元。