Linux Command Line Basics (closed)
标签(空格分隔): Udacity
Lesson 1: Get Into the Shell
Lesson 2: Shell Commands
Lesson 3:The Linux Filesystem
[TOC]
Lesson 1: Get Into the Shell
1.1 Log In and Break Stuff
log in:
cd Udacity/Shell/文件夹下:(有一个Vagrantfile的文件,有这个文件才能用vagrant up配置所需要的环境
vagrant up
vagrant ssh
ok, it's done. 现在可以试一试,在command line里随便输入一些东西。
你会发现大部分的命令都是无效的,但是出现'
单引号的时候,shell会提示你继续输入,因为在没有见到第二个'
之前,它认为现在输入的命令还没有写完。
除此之外用exit
可以log out.
如果你输入python
或其它什么奇怪的命令,进入了某个程序,可以用quit
或Ctrl+C退出该程序,回到shell。
1.2 Commands That Work
运行后的结果,在Udacity/Shell/文件夹下多了一个things.zip的文件
1.3 What can you do in the terminal?
1.4 The Terminal Interface
1.5 The Terminal vs The Shell
Terminal 只是一个终端而已,他负责接受input,但不会处理,所以把这些input传给shell来运行,shell把得到的结果返回给terminal,terminal再展示给我们。所以说terminal就是个窗口而已。
Different shells
Unix and Linux programmers over the years have written many different shell programs. You can read more about them on Wikipedia: the original Bourne shell or sh; the C shell or csh; the Korn shell or ksh; the Z shell or zsh; as well as the bash shell that this course uses.
Different systems may have different shells installed by default. Most Linux systems, and Mac OS X, default to bash for interactive shells. However, the most common default shell for scripting (shell programming) is classic sh. BSD Unix systems usually default to sh or ksh.
Almost everything in this course will work the same in any of these shell programs. The exception is one of the file matching (globbing) syntaxes at the end of Lesson 3.
1.6 Try More Commands
host udacity.com
给出了Udacity的IP地址,并告诉我们它的mail是Gmail负责的。
1.7 Reading the Output of a Command
1.8 Identify User Input
Lesson 2: Shell Commands
2.1 Filenames and Contents
2.2 Command History
有三种方法来找到之前输入过的命令。
- 用↑这个方向键, up arrow key.
- use the commend
history
- Ctrl + R, 能用来搜索之前输入的命令,适合久远的命令。
2.3 Some Common Commands
用unzip things.zip
来解压之前curl
来的文件things.zip
.
用cat file_name.txt
,会return文档里的内容。
用Tab来自动补全。
用来分析文件的命令:
-
wc bivalves.txt
, wc is a word count program. return the lines, words, bytes. -
diff gastropods.txt gastropods_draft.txt
, 返回两个文档不同的地方。这个在git教程里也讲到了。
2.4 Manual Pages
用man
command 来查询文档
在synopsis里,像[-e eye_string]
这样的表示有可选项的命令。必须在-e
后添加一个eye_string
来改变cowsay的眼睛形状。
2.5 Using the Manual for Serious Purpose
比如在unzip things.zip
的时候,发现extracting .secret
的字样,但是用ls
看不到。所以用man ls
来查看用什么命令能看到隐藏文件。
答案是ls -a
或ls --all
.
2.6 Options to ls
从右到左,filename, modification time, file size(byte),
2.7 Researching Commands
运行不确定的command前先google,别手贱……
比如rm -rf/
:
-r
is for recursive, and -f
is for force.
Just to be clear: This command is not good for your system. Don't run it. Keep watching ...
2.8 Line Based Programs
一些交互式的命令,一旦运行后就会占据terminal,一直运行。比如ping
,检测某个域名是否alive. 这个命令会一直返回echo。除非你用Ctrl+C终止进程。
但另外一些programs有不同的behavior。
比如输入sort
,回车。这个命令会进入下一行,每输完一个单词回车后就会另起一行,无法停止。此时必须用Ctrl+D来告诉shell”输入完毕“,然后就会得到按字母排好序的单词。
2.9 Waiting for Input
输入bc
可以进入一个basic calculator, 你可以输入数字,回车,但是怎样才能退出呢?
- 输入
quit
- Ctrl + D
2.10 Full Screen Interactive Programs: less
其实在用man
command的时候,就是用的less的语法。比如用Q退出,就是less的功能。
less thewind.txt
这个less就像是vim里的命令模式,只能看和编辑,不能输入。
Introduction to Regular Expressions
2.11 Editing Files in nano
Lesson 3:The Linux Filesystem
3.1 The Filesystem Tree
文件路径。Linux中用/
(slash)来表示路径,和https://
一样,和1/2 = 0.5
只有windows用backslash.
3.2 The Working Directory
用pwd
显示 Present Working Directory。
用cd
来改变Directory:
-
cd /var/log
给出整个path -
cd three
进入当前Directory中的某个名为three的Directory -
cd ..
返回上一级
可以下载一个叫tree的program,能显示文件目录的树状结构。
3.3 Absolute and Relative Paths
../mountain
:表示cwd(当前目录)的parent directory下的另一个directory mountain. 也就是说这个mountain和当前目录是同一层级的。
.
:一个dot表示cwd。
cd ~
: 回到home directory. 其中~
代表home,我的home directory就是xu.
`cd without arguments is a shortcut to take you home.
As long as your home directory exists, you can always go home.
3.4 Tab Completion
在输入目录path的时候用Tab补全。
3.5 Moving and Copying Files
3.6 Making and Removing Directories
mkdir notes
:在当前directory创建一个新的叫notes的directory
mkdir /tmp/cache
: 给出absolute path, 创建叫cache的directory,和cwd无关。
rmdir notes
:只能移除空文件夹
rm -rf junk
: 递归并强制删除
You might remember looking up rm -rf
before. Well, it can be used for good as well as evil. Here, you don't need the -f option; just rm -r
junk will do what you need.
3.7 mv and directories
3.8 Globbing (通配符)
*
:代表多个character
{css,html}
: css或html
?
:代表一个character
[aeiou]
: 只要这五个字符中的一个出现即可
要注意,这些是大小写敏感的