Linux Command Line Basics (closed)

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.

Linux Command Line Basics (closed)_第1张图片
lc1.png-138.9kB

如果你输入python或其它什么奇怪的命令,进入了某个程序,可以用quit或Ctrl+C退出该程序,回到shell。

1.2 Commands That Work

Linux Command Line Basics (closed)_第2张图片
lm2.png-456kB
Linux Command Line Basics (closed)_第3张图片
lm3.png-461.4kB

运行后的结果,在Udacity/Shell/文件夹下多了一个things.zip的文件

1.3 What can you do in the terminal?

Linux Command Line Basics (closed)_第4张图片
lm4.png-316.1kB

1.4 The Terminal Interface

Linux Command Line Basics (closed)_第5张图片
lm5.png-397.8kB

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

Linux Command Line Basics (closed)_第6张图片
lm6.png-363.4kB

host udacity.com 给出了Udacity的IP地址,并告诉我们它的mail是Gmail负责的。

Linux Command Line Basics (closed)_第7张图片
lm7.png-525.1kB
Linux Command Line Basics (closed)_第8张图片
lm8.png-621.3kB
Linux Command Line Basics (closed)_第9张图片
lm9.png-199.4kB

1.7 Reading the Output of a Command

Linux Command Line Basics (closed)_第10张图片
lm10.png-442.4kB

1.8 Identify User Input

Linux Command Line Basics (closed)_第11张图片
lm11.png-406.1kB

Lesson 2: Shell Commands

2.1 Filenames and Contents

Linux Command Line Basics (closed)_第12张图片
lm12.png-366.7kB

2.2 Command History

有三种方法来找到之前输入过的命令。

  1. 这个方向键, up arrow key.
  2. use the commend history
  3. Ctrl + R, 能用来搜索之前输入的命令,适合久远的命令。

2.3 Some Common Commands

unzip things.zip来解压之前curl来的文件things.zip.

cat file_name.txt,会return文档里的内容。

Tab来自动补全。

用来分析文件的命令:

  1. wc bivalves.txt, wc is a word count program. return the lines, words, bytes.
  2. diff gastropods.txt gastropods_draft.txt, 返回两个文档不同的地方。这个在git教程里也讲到了。
Linux Command Line Basics (closed)_第13张图片
lm13.png-870.9kB

2.4 Manual Pages

man command 来查询文档

Linux Command Line Basics (closed)_第14张图片
lm14.png-211.2kB

在synopsis里,像[-e eye_string]这样的表示有可选项的命令。必须在-e后添加一个eye_string来改变cowsay的眼睛形状。

Linux Command Line Basics (closed)_第15张图片
lm15.png-603kB

2.5 Using the Manual for Serious Purpose

比如在unzip things.zip的时候,发现extracting .secret的字样,但是用ls看不到。所以用man ls来查看用什么命令能看到隐藏文件。

答案是ls -als --all.

2.6 Options to ls

Linux Command Line Basics (closed)_第16张图片
lm16.png-362.7kB

从右到左,filename, modification time, file size(byte),


Linux Command Line Basics (closed)_第17张图片
lm17.png-552.3kB

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终止进程。

Linux Command Line Basics (closed)_第18张图片
lm18.png-390.1kB

但另外一些programs有不同的behavior。

Linux Command Line Basics (closed)_第19张图片
lm19.png-163.8kB

比如输入sort,回车。这个命令会进入下一行,每输完一个单词回车后就会另起一行,无法停止。此时必须用Ctrl+D来告诉shell”输入完毕“,然后就会得到按字母排好序的单词。

Linux Command Line Basics (closed)_第20张图片
lm20.png-20.6kB

2.9 Waiting for Input

输入bc可以进入一个basic calculator, 你可以输入数字,回车,但是怎样才能退出呢?

  1. 输入quit
  2. Ctrl + D
Linux Command Line Basics (closed)_第21张图片
lm21.png-315.6kB
Linux Command Line Basics (closed)_第22张图片
lm22.png-229.3kB

2.10 Full Screen Interactive Programs: less

其实在用man command的时候,就是用的less的语法。比如用Q退出,就是less的功能。

less thewind.txt

这个less就像是vim里的命令模式,只能看和编辑,不能输入。

Cheatsheet of less's Keyboard

Introduction to Regular Expressions

2.11 Editing Files in nano

Linux Command Line Basics (closed)_第23张图片
lm23.png-504.8kB

Lesson 3:The Linux Filesystem

3.1 The Filesystem Tree

Linux Command Line Basics (closed)_第24张图片
lm24.png-213.4kB
Linux Command Line Basics (closed)_第25张图片
lm25.png-316.3kB

文件路径。Linux中用/(slash)来表示路径,和https://一样,和1/2 = 0.5 只有windows用backslash.

Linux Command Line Basics (closed)_第26张图片
lm26.png-222.2kB

3.2 The Working Directory

pwd显示 Present Working Directory。
cd来改变Directory:

  1. cd /var/log 给出整个path
  2. cd three 进入当前Directory中的某个名为three的Directory
  3. cd .. 返回上一级
Linux Command Line Basics (closed)_第27张图片
lm27.png-386.6kB

可以下载一个叫tree的program,能显示文件目录的树状结构。

3.3 Absolute and Relative Paths

lm28.png-1024.8kB

../mountain:表示cwd(当前目录)的parent directory下的另一个directory mountain. 也就是说这个mountain和当前目录是同一层级的。
.:一个dot表示cwd。
cd ~: 回到home directory. 其中代表home,我的home directory就是xu.

Linux Command Line Basics (closed)_第28张图片
lm29.png-457kB
Linux Command Line Basics (closed)_第29张图片
lm30.png-34.5kB
Linux Command Line Basics (closed)_第30张图片
lm31.png-72.4kB

`cd without arguments is a shortcut to take you home.

As long as your home directory exists, you can always go home.

Linux Command Line Basics (closed)_第31张图片
lm32.png-431.8kB

3.4 Tab Completion

在输入目录path的时候用Tab补全。

3.5 Moving and Copying Files

Linux Command Line Basics (closed)_第32张图片
lm33.png-194.6kB

3.6 Making and Removing Directories

mkdir notes:在当前directory创建一个新的叫notes的directory
mkdir /tmp/cache : 给出absolute path, 创建叫cache的directory,和cwd无关。

Linux Command Line Basics (closed)_第33张图片
lm34.png-176.2kB

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

Linux Command Line Basics (closed)_第34张图片
lm35.png-293kB
Linux Command Line Basics (closed)_第35张图片
lm36.png-374.8kB

3.8 Globbing (通配符)

Linux Command Line Basics (closed)_第36张图片
lm37.png-558.8kB

*:代表多个character
{css,html} : css或html
:代表一个character
[aeiou] : 只要这五个字符中的一个出现即可
要注意,这些是大小写敏感的

Linux Command Line Basics (closed)_第37张图片
lm38.png-264.9kB
Linux Command Line Basics (closed)_第38张图片
lm39.png-290.1kB

3.9 Applying Globbing

Linux Command Line Basics (closed)_第39张图片
lm40.png-394.8kB
Linux Command Line Basics (closed)_第40张图片
lm41.png-29.3kB

你可能感兴趣的:(Linux Command Line Basics (closed))