Prep-UNIX Tutorial-1

UNIX Introduction

System Characters:

  • stable穩(wěn)定性
  • multi-user多用戶
  • multi-tasking多任務(wù)處理

Operating System

  • The kernel
  • The shell
  • The programs

The kernel

The kernel of UNIX is the hub of the operating system: it allocate time and memory to programs and handles the filestore and communications in response to system calls.

The kernel and the shell work together. For example, when a user types rm myfile:

  1. The shell wil searches the filestore for the file containing the program rm. /shell搜索該文件八酒。
  2. Then the shell will request the kernel, through system calls, to execute the program rm on myfile. /shell請(qǐng)求kernel執(zhí)行該請(qǐng)求。
  3. When finished, the shell then returns the UNIX prompt % to the user, indicating that is it waiting for further commands. /shell返回UNIX提示給用戶拴念,表明它現(xiàn)在正等待用戶做下一步操作您没。

The shell

The shell helps the user to interact with the kernel. It will interprets the commands the user types in and arranges for them to be carried out, so the shell is a command line interperter(CLI)(命令行解釋者). Using the shell will request user's adept skills, but we can use tcsh shell to help our inputting commands:

  1. Filename Competion - 自動(dòng)補(bǔ)全
  2. History - 歷史命令

Files and processes

Everything in UNIX is either a file or a process
UNIX里的所有東西都是以文件或進(jìn)程的形式存在。

  1. 一個(gè)進(jìn)程是指執(zhí)行中的一個(gè)程序墅拭,每個(gè)進(jìn)程用一個(gè)單獨(dú)的PID(process identifier)進(jìn)行標(biāo)識(shí)。
  2. 一個(gè)文件是指一個(gè)數(shù)據(jù)的集合,通常是用戶用文本編輯器盈简、運(yùn)行編譯器等方式創(chuàng)建的數(shù)據(jù)集合。

Examples of files:
a document (report, essay etc.)
the text of a program written in some high-level programming language
instructions comprehensible directly to the machine and incomprehensible to a casual user, for example, a collection of binary digits (an executable or binary file);
a directory, containing information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files.

Simple Command

List

$ ls
The ls command lists the contents of your current working directory.
However, there may be some files are hidden whose name begins with a dot(.)They are hidden because you should not change them unless you are very famillar with UNIX.
ls操作實(shí)際上不會(huì)把這個(gè)目錄下的所有文件都顯示出來太示,而只是打開那些不是以點(diǎn)(.)開頭的文件柠贤,因?yàn)橐渣c(diǎn)開頭的文件是隱藏文件,在不熟悉UNIX操作的情況下类缤,最好不要去對(duì)它們做改動(dòng)臼勉。

$ ls -a
Using this command can help you to list files that are nomally hidden.
這一個(gè)命令,可以打開那些正常情況下被隱藏的文件餐弱。

這里展示了一個(gè)命令的例子宴霸,ls是一個(gè)命令,它可以伴隨一些選項(xiàng)岸裙,例如 -a就是一個(gè)選項(xiàng)(所有all)猖败。選項(xiàng)不同,命令的執(zhí)行方式就會(huì)不同降允。具體執(zhí)行命令的方式可以參考一些在線使用手冊(cè)恩闻。

Making Directories

$ mkdir unixlearning
Using this command, you will make a subdirectory in your home directory to hold the files. 這樣就創(chuàng)建了一個(gè)新的子目錄在你的主目錄下。

Changing to a different directory

$ cd unixlearning
Typing this command, you can change to the directory you have just made.

Pathnames

$ pwd
This will print the absolute pathname of your home directory.
輸出當(dāng)前的路徑名剧董。

$ ls ~/Desktop
When we use home directories, we can also replace it wit tilt ~ character. It can be used to specity paths starting at your home directory.
列出相對(duì)路徑下的內(nèi)容幢尚,~符號(hào)代表省略主目錄。

Copy Files

$ cp ~/Desktop/Demo/file.txt .
This command means to copy the file.txt to the current directory. The dot means the current directory.You will have the effect that two files left.
復(fù)制一個(gè)文件(夾)到某處翅楼。

Move Files

$ mv ~/Desktop/Demo/file.txt .
This command means to directly move the file.txt to the current directory. This will end up with only one file. You can also use this command to rename your file by moving the file into the same directory'file with a new name.
移動(dòng)一個(gè)文件(夾)到某處尉剩,或重命名該文件(夾)。

Remove files and directories

$ rm file.txt
This command deletes the file.txt.
刪除文件
You can also remove a directory:
$ rmdir toberm
This will remove the directory "toberm". When remove the directory, please make sure it is empty first.
這個(gè)命令可以用來刪除目錄毅臊,在刪除之前請(qǐng)確保它是空的理茎。

Clear(clear screen)

$ clear
This will clear the terminal window of the previous commands.
清屏。

Concatenate

$cat file.txt
This will display the contents of a file on the screen.

Head & Tail

$ head file.txt
To write the first 10 lines of a file to the screen
顯示文件的前十行
$ head -5 file.txt
顯示前五行

$ tail file.txt
To write the last 10 lines of a file to the screen
顯示后十行

Search using less

First type :
$ less file.txt
then use slash [/] followed by the word to search:
/demo
Now you can see less finds and highlights the keyword, and you can type [n] to search for the next occurrence of the word.
用less顯示文件內(nèi)容管嬉,然后用反斜杠直接進(jìn)行關(guān)鍵詞搜索皂林。

Search using grep

$ grep demo file.txt
This will find the keyword demo in file.txt, grep will print out each line containing the word demo.
用grep在文件中搜索關(guān)鍵詞。并利用gerp的選項(xiàng)蚯撩,進(jìn)行其他功能的操作如下:

To ignore the lower/upper case distinctions, use -i option:
$ grep -i Demo file.txt

This can also search the demo keyword.

Some of the other options of grep are:
-v display those lines that do NOT match
-n precede each matching line with the line number
-c print only the total count of matched lines

Word count

$ wc -w file.txt
To do a word cound on file.txt.
統(tǒng)計(jì)文件的字?jǐn)?shù)础倍。

$ wc -l file.txt
To find out how many lines the file has.
統(tǒng)計(jì)文件的行數(shù)。

Quotes

UNIX Tutorial for Beginners

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末胎挎,一起剝皮案震驚了整個(gè)濱河市沟启,隨后出現(xiàn)的幾起案子忆家,更是在濱河造成了極大的恐慌,老刑警劉巖德迹,帶你破解...
    沈念sama閱讀 206,968評(píng)論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件芽卿,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡浦辨,警方通過查閱死者的電腦和手機(jī)蹬竖,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門沼沈,熙熙樓的掌柜王于貴愁眉苦臉地迎上來流酬,“玉大人,你說我怎么就攤上這事列另⊙刻冢” “怎么了?”我有些...
    開封第一講書人閱讀 153,220評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵页衙,是天一觀的道長(zhǎng)摊滔。 經(jīng)常有香客問我,道長(zhǎng)店乐,這世上最難降的妖魔是什么艰躺? 我笑而不...
    開封第一講書人閱讀 55,416評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮眨八,結(jié)果婚禮上腺兴,老公的妹妹穿的比我還像新娘。我一直安慰自己廉侧,他們只是感情好页响,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,425評(píng)論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著段誊,像睡著了一般闰蚕。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上辛藻,一...
    開封第一講書人閱讀 49,144評(píng)論 1 285
  • 那天辅搬,我揣著相機(jī)與錄音梦染,去河邊找鬼。 笑死盼玄,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的参滴。 我是一名探鬼主播强岸,決...
    沈念sama閱讀 38,432評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼砾赔!你這毒婦竟也來了蝌箍?” 一聲冷哼從身側(cè)響起青灼,我...
    開封第一講書人閱讀 37,088評(píng)論 0 261
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎妓盲,沒想到半個(gè)月后杂拨,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,586評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡悯衬,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,028評(píng)論 2 325
  • 正文 我和宋清朗相戀三年弹沽,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片筋粗。...
    茶點(diǎn)故事閱讀 38,137評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡策橘,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出娜亿,到底是詐尸還是另有隱情丽已,我是刑警寧澤,帶...
    沈念sama閱讀 33,783評(píng)論 4 324
  • 正文 年R本政府宣布买决,位于F島的核電站沛婴,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏督赤。R本人自食惡果不足惜嘁灯,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,343評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望躲舌。 院中可真熱鬧丑婿,春花似錦、人聲如沸孽糖。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽办悟。三九已至尘奏,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間病蛉,已是汗流浹背炫加。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評(píng)論 1 262
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留铺然,地道東北人俗孝。 一個(gè)月前我還...
    沈念sama閱讀 45,595評(píng)論 2 355
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像魄健,于是被迫代替她去往敵國和親赋铝。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,901評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容