地址操作
Code |
全称 |
作用 |
pwd |
print working directory |
定位当前directory的位置 |
ls |
listing |
显示当前directory中的文件 |
. |
|
当前位置 |
.. |
|
当前位置的上一级 |
~ |
|
当前用户主目录 |
文件操作
Code |
全称 |
作用 |
cp |
copy |
拷贝文件 |
mv |
|
* 移动文件 * 重命名文件 |
rm |
remove |
删除文件 |
rmdir |
|
删除directory |
mkdir |
|
创建directory |
数据操作
Code |
全称 |
作用 |
cat |
concatenate |
连接文件或标准输入并打印它们 |
more |
|
|
less |
|
one page is displayed at a time |
:n |
|
move to the next file |
:p |
|
go back to the previous file |
:q |
|
quit |
head |
|
print the first few lines of a file (where "a few" means 10) |
head -n 3 |
|
only display the first three lines of the file |
ls -R |
|
see everything underneath a directory, no matter how deeply nested it is |
ls -R |
|
prints a / after the name of every directory and a * after the name of every runnable program |
man |
manual |
help to find out what commands do |
cut |
|
|
history |
|
print a list of commands you have run recently |
!55 |
|
re-run the 55th command in your history |
- 按
tab
可以自动补全
head
and tail
select rows, cut
selects columns, and grep
selects lines according to what they contain, and grep
has the following command-line flags
-c
: print a count of matching lines rather than the lines themselves
-h
: do not print the names of files when searching multiple files
-i
: ignore case (e.g., treat "Regression" and "regression" as matches)
-l
: print the names of files that contain matches, not the matches
-n
: print line numbers for matching lines
-v
: invert the match, i.e., only show lines that don't match
Command-Line Flag
-n
: is meant to signal "number of lines"
-R
: means "recursive"
-f
: means "fields"
-d
: means "delimiter"
Combining Tools
Code |
全称 |
作用 |
> |
|
tell the shell to redirect the output to a file |
wc |
word count |
print the number of characters, words, and lines in a file |
sort |
|
put data in order |
uniq |
|
remove adjacent duplicated lines |
- The pipe symbol
|
tells the shell to use the output of the command on the left as the input to the command on the right.
Ctrl
+C
: 终止程序进程
Wildcard
*
: match zero or more characters
?
matches a single character, so 201?
.txt will match 2017.txt
or 2018.txt
, but not 2017-01.txt
.
[...]
matches any one of the characters inside the square brackets, so 201[78].txt
matches 2017.txt
or 2018.txt
, but not 2016.txt
.
{...}
matches any of the comma-separated patterns inside the curly brackets, so {*.txt, *.csv}
matches any file whose name ends with .txt
or .csv
, but not files whose names end with .pdf
.
[singh,johel]{*.pdf, *.txt}
the expression in square brackets matches only one character, not entire words.
{singh.pdf, j*.txt}
is ok.
Batch Processing
Code |
全称 |
作用 |
set |
|
get a complete list of the environment variables |
echo |
|
prints a variable's value's arguments |
- To get the variable's value, you must put a dollar sign
$
in front of it.
Loop
for
…variable… in
…list… ; do
…body… ; done
Creating New Tools
How to edit a file
Ctrl
+ K
: delete a line.
Ctrl
+ U
: un-delete a line.
Ctrl
+ O
: save the file (O
stands for 'output'). You will also need to press Enter to confirm the filename!
Ctrl
+ X
: exit the editor.
留言