Linux command tutorial

Listing files and directories
ls
ls -a 列出包含隐藏文件

Making Directories
mkdir
mkdir cc

Changing to a different directory
cd
cd cc

The directories . and ..
.  the current directory
.. the parrent directory

cd ..  change to the parent directory

Pathnames
pwd print wording directory
the top-level root directory called " / "
your home directory called "~" 当前用户的根目录

Copying Files
cp
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.

Moving files
mv
mv file1 file2 moves (or renames) file1 to file2

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

Displaying the contents of a file on the screen
clear (clear screen)

cat (concatenate)
The command cat can be used to display the contents of a file on the screen.
% cat science.txt

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

head
The head command writes the first ten lines of a file to the screen.
% head science.txt
% head -5 science.txt

tail
The tail command writes the last ten lines of a file to the screen.
% tail science.txt

Searching the contents of a file
Simple searching using less
% 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 highlights the keyword. Type [n] to search for the next occurrence of the word.

grep
% grep science science.txt
The grep command is case sensitive
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 匹配个数

wc (word count)
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

Redirecting the Output
>
% cat > list1
输入cat,不输人参数,然后回车,会将用户输入回显,这个命令是将用户输入重定向到list1

Appending to a file
% cat >> list1
% cat list1 list2 > biglist   join two file to biglist
% cat list1 list2 > biglist

Redirecting the Input
<
% sort < biglist 从biglist中读入数据进行排序
% sort < biglist > slist 从biglist中读入数据进行排序,结果输出到slist

Pipes
% who > names.txt
% sort < names.txt
% who | sort who的输出作为sort的输入

Wildcards
The * wildcard
% ls list*
% ls *list
*表示任意个
The ? wildcard
% ls ?list
?表示一个字符

Filename conventions
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.小写字母开头,后缀文件类型

你可能感兴趣的:(command)