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:
- The shell wil searches the filestore for the file containing the program rm. /shell搜索該文件八酒。
- Then the shell will request the kernel, through system calls, to execute the program rm on myfile. /shell請(qǐng)求kernel執(zhí)行該請(qǐng)求。
- 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:
- Filename Competion - 自動(dòng)補(bǔ)全
- History - 歷史命令
Files and processes
Everything in UNIX is either a file or a process
UNIX里的所有東西都是以文件或進(jìn)程的形式存在。
- 一個(gè)進(jìn)程是指執(zhí)行中的一個(gè)程序墅拭,每個(gè)進(jìn)程用一個(gè)單獨(dú)的PID(process identifier)進(jìn)行標(biāo)識(shí)。
- 一個(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ù)。