Linux command tutorial

[color=red][b]Listing files and directories[/b][/color]
[b][color=green]ls[/color][/b]
ls -a 列出包含隱藏文件

[color=red][b]Making Directories[/b][/color]
[color=green][b]mkdir[/b][/color]
mkdir cc

[color=red][b]Changing to a different directory[/b][/color]
[color=green][b]cd[/b][/color]
cd cc

[color=red][b]The directories . and ..[/b][/color]
[color=green][b]. the current directory
.. the parrent directory[/b][/color]
cd .. change to the parent directory

[color=red][b]Pathnames[/b][/color]
[b][color=green]pwd print wording directory[/color][/b]
the top-level root directory called " / "
your home directory called "~" 當前用戶的根目錄

[color=red][b]Copying Files[/b][/color]
[b][color=green]cp[/color][/b]
cp file1 file2 is the command which makes a copy of file1 in the current working directory and calls it file2
cp /vol/examples/tutorial/science.txt .
The above command means copy the file science.txt to the current directory, keeping the name the same.

[color=red][b]Moving files[/b][/color]
[color=green][b]mv[/b][/color]
mv file1 file2 moves (or renames) file1 to file2

[color=green][b][color=red][b]Removing files and directories[/b][/color]
rm (remove), rmdir (remove directory)[/b][/color]

[color=red][b]Displaying the contents of a file on the screen[/b][/color]
[color=green][b]clear (clear screen)[/b][/color]

[color=green][b]cat (concatenate)[/b][/color]
The command cat can be used to display the contents of a file on the screen.
% cat science.txt

[color=green][b]less[/b][/color]
The command less writes the contents of a file onto the screen a page at a time.
% less science.txt
Press the [color=green][b][space-bar][/b][/color] if you want to see another page, and type [color=green][b][q][/b][/color] if you want to quit reading. As you can see, less is used in preference to cat for long files.

[b][color=green]head[/color][/b]
The head command writes the first ten lines of a file to the screen.
% head science.txt
% head -5 science.txt

[color=green][b]tail[/b][/color]
The tail command writes the last ten lines of a file to the screen.
% tail science.txt

[color=red][b]Searching the contents of a file[/b][/color]
[color=green][b]Simple searching using less[/b][/color]
% less science.txt
then, still in less, type a forward slash [/] followed by the word to search
/science
As you can see, less finds and [color=blue]highlights[/color] the keyword. Type [n] to search for the next occurrence of the word.

[color=green][b]grep[/b][/color]
% grep science science.txt
[b][color=blue]The grep command is case sensitive[/color][/b]
To ignore upper/lower case distinctions, use the -i option, i.e. type
% grep -i science science.txt
To search for a phrase or pattern, you must enclose it in single quotes (the apostrophe symbol). For example to search for spinning top, type
% grep -i 'spinning top' science.txt
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 匹配個數

[color=green][b]wc (word count)[/b][/color]
A handy little utility is the wc command, short for word count. To do a word count on science.txt, type
% wc -w science.txt
To find out how many lines the file has, type
% wc -l science.txt

[color=red][b]Redirecting the Output [/b][/color]
[color=green][b]>[/b][/color]
% cat > list1
輸入cat,不輸人蔘數,然後回車,會將用戶輸入回顯,這個命令是將用戶輸入重定向到list1

[color=green][b]Appending to a file[/b][/color]
% cat >> list1
% cat list1 list2 > biglist join two file to biglist
% cat list1 list2 > biglist

[color=red][b]Redirecting the Input[/b][/color]
[color=green][b]<[/b][/color]
% sort < biglist 從biglist中讀入數據進行排序
% sort < biglist > slist 從biglist中讀入數據進行排序,結果輸出到slist

[color=red][b]Pipes[/b][/color]
% who > names.txt
% sort < names.txt
% who | sort who的輸出作爲sort的輸入

[color=red][b]Wildcards[/b][/color]
[color=green][b]The * wildcard[/b][/color]
% ls list*
% ls *list
*表示任意個
[color=green][b]The ? wildcard[/b][/color]
% ls ?list
?表示一個字符

[color=red][b]Filename conventions[/b][/color]
In naming files, characters with special meanings such as / * & % , should be avoided.避免特殊字符
File names conventionally start with a lower-case letter, and may end with a dot followed by a group of letters indicating the contents of the file.小寫字母開頭,後綴文件類型
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章