ADM-201 dump PMP dumps pdf SSCP exam materials CBAP exam sample questions

《胡须Linux教程》#4 基础命令1 – 译学馆
未登录,请登录后再发表信息
最新评论 (0)
播放视频

《胡须Linux教程》#4 基础命令1

Linux Sysadmin Basics 02 -- Basic Commands

大家好
Well, hello there.
我刚刚在看目前最好的视频游戏
I was just looking at the greatest video game ever made,
那是今天为你们推荐的内容
that’s your recommendation for today.
这是第一个将会涉及到Linux本身的视频
This is the first video where I’m going to cover Linux itself.
你们要坚持下去 虽然这不是最令人振奋的部分
Stick with this, it’s not the most exciting stuff,
但是你可以探索到文件系统的奥秘
but we’re going to get you moving around the file system.
首先
Right from the beginning,
我们会从命令行开始
we’re going to start in the command line,
因为我希望你们能够习惯(命令行的使用)
because that’s all I want you to get used to.
没错 这是Ubuntu 并且我们安装的是特别版
Yes, Ubuntu, and specifically the version we’ve installed,
它是带有图形界面的桌面版
which is the desktop version with a graphical environment.
使用非常简单
It is very easy to use,
有些人觉得它比Windows还要简单
some would say easier than Windows,
当然和OS X是不相上下
certainly on par with OS X.
但是 我们不会用到那些
But, we’re not going to use any of that,
我们不会利用那些
we’re not going to take advantage of it.
因为
Because,
快速掌握Linux的关键之一
one of the keys to becoming good at Linux quickly,
是使用命令行来完成所有操作
is to use the command line for everything.
我也会给你们演示如何用命令行做些好玩的事情
I’m going to show you how to do some fun things with the command line as well,
比如说…… 它甚至可以浏览网页
like, even just browsing the internet,
这是一个很酷的小型浏览器 你完全可以使用它
there’s a cool little browser you can use.
当然这并不完全实用
Now, this isn’t entirely practical.
因为作为一个系统管理员
As a system administrator,
你不是要把时间花费在……
you’re not going to be spending all of your time,
我是说 如果你是要
I mean, if you’re like
上网查找一些问题的答案
searching the web for some kind of answer to a question,
你就不会在Linux里把命令行用作浏览器了
you’re not going to be using Linux in, as a browser in the command line.
但是
But,
习惯Linux这种奇怪的新环境的最好方法
and the best way to just acclimatise yourself to this weird new environment, Linux,
就是要一直使用它
is to just use it all the time,
尽可能的在命令行上多花时间
and spend as much time as possible in the command line.
你就会觉得这些东西变得很自然了
This stuff will start to feel natural.
好了
Ok, so,
我们要做的第一件事是打开终端
the very first thing we’ll do, is just open the Terminal,
你可以通过点击这里
which you can do by…clicking here and just,
并且搜索”Terminal”来打开
start searching for ‘Terminal’.
你应该这样做
And you will do this.
对不起 这些来自亚马逊的广告
I’m sorry, this is really annoying,
非常令人讨厌
the advertisements from, coming from Amazon.
这就像虚拟机一样 我什么也没做
This is like, a virtual machine, I haven’t done anything.
这些只是来自亚马逊的广告
These are just ads coming from Amazon, man!
你已经打开终端了
So, you’ve opened the Terminal,
我们要看的第一条命令是
and the very first command were going to look at,
是”ls”
is list, ‘ls’,
“ls”命令会显示出目录中的内容
‘ls’ shows you what’s in your directory.
该命令有几个标识符
There’s a couple of flags for it,
标识符就是
and flags are basically, arguments,
加在命令之后使它更明确的参数
or things that you add to the command to make it more specific.
例如说 如果”ls”命令
So for example, if I ‘ls’,
加上 “-a” 这就是A标识符
with ‘-a’, so it would be the A flag,
通常用”-“来指出标识符或者说可选项
the flags, or options, are generally indicated with a ‘-‘.
它会列出所有文件
That’ll show us all files.
包括隐藏文件和未隐藏文件
So hidden files and non-hidden files,
正如我们看到的 我运行了同样的命令两次
as we can see, I just, the same command, I’ve done it twice,
但是这次比以前多了一些文件和文件夹
and now we suddenly see way more files and folders than before.
是哪些呢?
Now what’s going on here?
你可以看到
You can see,
我们上次没看到的文件和文件夹
The ones that we didn’t see before,
这次似乎都有一个小点
all seem to have a little dot,
就是在开头的句号字符
so the period character at the beginning.
在Linux中这些都是隐藏文件
In Linux those are hidden files.
所有名字最开始是点的文件
So anything that you name with a dot at the very beginning,
都是隐藏文件
becomes hidden.
这只是……
And that’s just to,
通常就是为了不让别人看到
generally just keep it out of the way,
你真的不需要看这些隐藏文件
like, you don’t really need to see all these hidden files.
它们大多数都和你无关
A lot of them are, like for example here,
比如说 浏览主目录时
it’s irrelevant to you when you’re browsing your home folder,
你并不需要查看你在终端的输入历史
to see the history of what you’ve typed into the Terminal.
好了
Ok, so,
我把终端清空一下
we can, let me just clear this,
我们可以使用”ls”命令列出文件
and again, we can ‘ls’,
但是无法知道我们所处的位置
and, but we have no idea where we are.
文件系统有点像一棵树
So the file system is kind of like a tree,
其他的文件系统也类似
it’s like any other file system, like,
如果把你用过的操作系统看作文件系统的话
every, every operating system you’ve used as a file system,
它们也和这差不多
it’s a lot like this.
树有一个根
You have a tree that has a root,
在那里分出枝干
and then from there, branches.
在Windows下也一样
So in Windows, it’s the same, I mean,
只是在Linux下被称作根目录
it’s just in Linux it’s called root.
它的符号就是”/”
And root it just a ‘/’.
文件系统的“根”是根目录 即”/”
So at the very base of our file system we have root, or this ‘/’.
要想列出根目录下的文件
So if we list that,
可以给”ls”一个参数
we can give ‘ls’ an argument that’s just,
用来指定路径
some kind of path.
所以不是只用”ls”
So instead of just ‘ls’,
“ls”只会列出当前目录的内容
which will list the directory that we’re sitting in.
我们可以用”ls”列出指定文件夹的内容
We could ‘ls’ some folders,
比如说 在当前目录下
so for example, oh, we’re sitting in this directory,
有一个”Downloads”文件夹
and there’s a ‘Downloads’ folder.
我们可以用”ls”列出”Downloads”文件夹内容
So we can just ‘ls’ the ‘Downloads’ folder,
我们来看一下它里面有什么吧
and that’ll let us see what’s in there.
里面什么也没有 我还没下载任何东西
There’s noting in there now, I didn’t download anything yet.
可以看到 如果使用”ls /”命令……
We can see if we ‘ls /’,
“/”是文件系统的根目录
it’s the very base of the file system,
没有什么是在它之外的 它包含所有东西
there’s nothing beyond that, that’s everything.
我们现在是在根目录的一个子目录中
And we’re sitting in a subdirectory of root somewhere,
也就是说我们在这棵树的一个分枝上
so we’re in a branch somewhere down the tree.
我们可以通过shell
And we can see where we are,
看出我们所处位置
in our shell.
通过shell的提示符……
So at the shell prompt,
提示符就是shell中你输入内容的地方前面的东西
prompt is the thing right before you start typing at the shell.
这就是shell的提示符 我们用的是bash
It’s this shell prompt, we’re in Bash, so,
就是说这个shell的名字是bash
it’s just the name of the shell, Bash.
其他还有例如C shell、Korn shell
There’s like C shell, Korn shell,
以及目前人们所知最好的shell:Z shell等
Z shell, which is the greatest shell known to man, etc.
但是我们会从bash开始
But we’re going to start with Bash,
很明显它也只是一个shell
obviously there’s also just shell,
我都快要忘记了
which I’m forgetting about, sh.
bash是大多数系统中的默认shell
Bash is a default shell that you’ll find on most systems,
它的提示符
And the prompt there,
是美元符号
is this dollar sign.
这就是提示符
So that’s your prompt.
它前面就是你在文件系统中所处的位置
And right before the prompt is where you are in the file system.
所以你总是能知道你在文件系统的位置
So you can always know where you are in the file system,
只要你知道
by knowing,
这是什么意思
what this means.
我保证 这是唯一的神秘之处
And this is the only mysterious thing, I promise.
要打出这个波浪线符号
The tilde,
你可以按住”shift”键
which is the key that you get if you hit ‘Shift’,
在美式键盘布局中
and then, on an American style keyboard layout,
再按左上角的键
it’s the top left key,
它在尖括号的上方
it’s above the angle bracket.
尖括号
Angle bracket!
我刚说了什么啊?
What am I smugging?
不是尖括号 是反引号`
It’s not about the angle bracket, it’s the back tick.
在键盘的左上角 ESC键的下面
So, top left of your keyboard, under the escape key,
数字”1″键的左面
and to the left of the ‘1’,
在美式键盘上是这样的
on the American keyboard, that’s this.
波浪线符号是你的家目录的简写
A tilde is short for your home.
是当前用户的家目录
So the user you are, that users’ home folder.
还有另外一个命令
So, there’s another command,
是为了防止你忘记自己的路径
just in case you lose track of where you are,
就是”pwd”命令
‘pwd’,
它是“打印工作目录”的缩写
print working directory.
输入”pwd”
If you hit ‘pwd’,
再点击回车键
and then hit ‘Enter’,
就可以显示出你在文件系统中的位置
It’ll show you where you are in the file system.
你刚看到了 这条命令会在下一行打印出位置
And you just can see it just prints that on the next line,
然后会显示出shell的提示符
and then gives your shell prompt back, like,
等待下次输入
waiting for your next input.
好了
Ok, so,
现在我们在自己的家目录
we are in our own home folder,
因为我们的用户名是dave 所以我们在”/home/dave”文件夹
which is, our username’s dave, so we’re in ‘/home/dave’.
可以看到 我们已经得到了想要的结果
And you can see, we’ve got our things.
我们已经看到了
So we could already see,
前面我们使用了”ls /”命令
we ‘ls /’ before,
你可以在这看到
you can see that up here.
我们可以看到自己在哪 对吧
So we kind of see where we are in that, right?
再执行一次”ls /”命令 我们找一下home文件夹
So, if we ‘ls /’ again, let’s look for the ‘home’ folder
它在这
Yeah, we can see it there.
这是home文件夹
So it’s ‘home’.
显然……
You can obviously just,
用”/”符号要更简单
we could, there’s easier ways to do this,
但是现在我还是要写的明确些
but I’m just being explicit right now.
执行”ls home”命令
So, ok, let’s ‘ls home’,
就可以看到我们所处的目录了
ok, and we can see that directory that we’re in,
“/home/dave”
‘/home/dave’.
这是当前目录里面唯一的一个文件夹
It’s the only directory in there.
所以……
So,
没错 这就是我们所处的位置
Yep, that’s where we’re sitting.
如果……
So if we do,
顺便一提 如果你按向上箭头
by the way, if you hit the ‘up’ arrow,
就会出现你上次输入的命令 并且可以不停的上翻
it will you your last command, and you can scroll through.
最近的命令
Ah, your last,
大概会有一千条吧
I think it’s like a thousand commands, like that.
这里有个”dave”目录
Ok, so there’s like a ‘dave’ directory here,
我们可以列出它里面的内容
and we can list that.
这个嘛……
Well, this,
我们已经做过了
is really just, what we’ve already done.
我们正在”dave”目录内
Because we are in here,
所以如果使用”ls”命令
so if we ‘ls’,
就会得到当前目录下的文件列表
and get a listing of the stuff that’s where we are.
这和明确的给出路径是完全一样的
It’s the exact same as giving this path explicitly.
所以全称路径
So the full path,
它就是这种叫法
which that’s called,
总是以”/”开头
is, it always starts with a ‘/’.
所以首先是”/”
So that would be ‘/’,
然后是”home”目录
and then the ‘home’ directory in there,
然后是”dave”目录
and then in there, the ‘dave’ directory.
我们继续 然后是”Downloads”目录
And we can keep going, we can go, it’s in ‘Downloads’,
或者是”Desktop”目录
or it’s in ‘Desktop’.
你可以看到我做了什么
You can see what I’m doing here is,
我使用了自动补全功能
I’m starting to use autocompletion.
在你输入命令的时候
So when you start typing characters,
它能根据字典中的内容
if it can narrow down the options,
缩小选项的范围
based on what’s in that directory,
如果你按”Tab”键
if you hit ‘Tab’,
按两次就会显示出以该字母开头的选项
click twice, it’ll show you your options that start with that letter.
所以如果我们输入”Do”
So we can say, ‘ah, yeah, it’s Do’,
然后再按下”Tab”键
and then we hit ‘Tab’ again.
就可以看到可选范围缩小了很多
You can see, that narrows it down some more,
然后我们就可以说
and then we finally say,
我想要的是”Documents”这个文件里
‘oh, it’s the Documents that I want.’ .
但是它里面什么也没有
And there’s nothing in there.
这使人兴趣骤减
It’s very anti-climactic.
但是我保证 后面有令人振奋的东西
But I promise you, this is, this is thrilling stuff here.
好了
Ok.
我们能做什么了呢?
So what can we do?
我们能查找所处位置
We can find out where we are,
我要清除一下终端
here I’ll clear this for you.
我们到底在哪呢?
Where the hell are we,
我们是在”/home/dave”文件夹下
we’re in ‘/home/dave’,
它里面有什么呢?
what, what’s around this, what’s in here,
我们可以列出里面的任意文件
and we can list arbitrary directories.
比如 现在有一个路径
So, if we have some path, like,
“/home/dave/Desktop”
‘/home/dave/Desktop/’,
我们就可以列出里面内容
we can list that.
非常酷
Ok, cool.
但是如果不能在文件系统中移动
This is doesn’t do us a hell lot of good,
这对我们也没什么用
if we can’t move around the file system.
所以为什么我们不试试移动呢?
So, why don’t we try moving?
我们要去根目录下
We’ll go into ‘/’,
命令是”cd” 它会改变当前目录
‘cd’ is the command, it’s ‘change directory’,
“cd /”就是”cd root”
‘cd /’ is ‘cd root’.
它会使我们移动到文件系统的根目录
it gets us to the very base of our file system.
我们可以用”ls”命令
So we can ‘ls’,
就和上次我们看到的一样
we can see the same thing that we saw last time.
为什么我们不从这移动到”home”目录呢?
So why don’t we go from here into ‘home’.
我们到了
There we are.
我们可以进入我们的家目录
Ah, now we can go into our ‘home’ folder,
这基本上就是我们开始的地方
this is basically where we started.
我们已经移动到了根目录 然后是”home” 然后是”dave”
So we’ve gone ‘cd’ to root, and then to ‘home’, and then to ‘dave’.
你可以看到这里前面没有”/”了
Now you notice there’s no slashes before any of these,
如果你位于一个目录下
because if you’re in a directory,
你只需要简单的输入”cd”命令
you can enter it by simply doing,
就可以进入一个子目录
change directory, ‘cd’,
至于目录的名字
and then the name of that directory.
你可以使用”Tab”自动补全
You can also use tab completion.
然而 如果你在其他地方……
However, if you’re somewhere else,
我们先回到根目录
let’s go back to ‘/’.
如果你位于根目录 并且想到那去
If you’re sitting in ‘/’ and you want to get there,
你就不能只是用”cd Downloads”命令
you can’t just go ‘cd Downloads’,
因为在根目录下没有Downloads目录
because there’s nothing in ‘Downloads’ in ‘/’.
我又说了一遍原因
I’m being repetitive for a reason, ok,
你必须要把这印在脑子里
you really need to just, get this ingrained in your brain.
所以
So,
如果我想从根目录到那……我现在在哪?
if I want to get there’re from ‘/’, where the hell am I?
用”pwd” 打印工作目录
‘pwd’, print working directory,
我在根目录
I’m in root, ok.
如果我想去”Downloads”目录
So if I want to go to ‘Downloads’,
就必须先到”home”目录
I have to go to ‘home’,
在这你也可以用自动补全功能
and you can start using tab completion here, too.
现在改变目录到”/home”
So change directory to ‘/home’.
记住下面是”dave”
Remember what it was, ‘dave’,
然后是”Downloads”
‘Downloads’,
现在我们就到了
now we’re there.
所以
So,
我们现在要谈论一下魔法
let’s talking about magic.
可以看到 提示符会告诉我们 我们所在的位置
You can see the prompt tells you where we are here,
它会说:嗨 伙计 你是在根目录
it says ‘hey dude, you’re in root’.
在这它又会说:伙计 你在神奇的波浪号目录
Here it says ‘hey dude, you’re in the magical tilde directory’,
那就是你的家目录
which is your user’s home.
所以如果我在根目录
So, if I’m sitting in ‘/’,
我就会说:我在这呢
let’s say, there I am,
改变目录到根目录
change directory to ‘/’.
如果我想去家目录
And I want to go ‘home’,
我只需要输入”cd ~”
all I have to do is type ‘cd ~’,
我就会回到家目录
and that get’s me home.
可以看到 现在我在”/home/dave” 这是我的家目录
Now you can see I’m in ‘/home/dave’, that’s my ‘home’ folder.
还有另一种方法可以到达
There’s another way to do that,
假设我在”Downloads”目录
and let’s say I’m in ‘Downloads’.
它里面什么也没有 我就在这
There’s nothing in here, I’m sitting here.
我先清空一下
I’ll clear this again.
如果我在这
If I’m sitting here,
并且我想返回到”home”目录
and I want to go back ‘home’,
我的意思是说
let’s say, I mean you, you can really, I mean,
有一个运行系统 比如一个大型web服务器
on a production system, if it’s like a giant web server,
正在运行一些web应用
and it’s running some kind of like, web application,
以及大型的数据库
and a huge database,
在它最上面还运行着一些仿真软件
and there’s kind of simulation software on top of that.
你有一个非常大的文件系统
You can have very large file systems,
你不知道自己在哪了
and you can kind of get lost in them.
如果你需要快速返回到”home”目录
So if you just need to get back to your ‘home’ folder quickly,
你可以只是输入”cd” 不用带任何参数
you can just type ‘cd’ without any arguments.
就是后面不带路径
So, so without a path after it,
你就可以返回到”home”目录了
and that would get you ‘home’.
可以看到 我们现在在”home”目录了
You could see now we’re ‘home’.
好了
Ok.
所以
So,
前面已经讲过了移动
that covers moving around,
查看当前目录内容
and it covers looking at what’s in front of us, ‘ls’,
也讲了 如何查看我们的位置
and it covers figuring out where the hell we are,
如果我们不想看这里的路径的话
if we don’t feel like reading the path here.
但是
But,
怎么新建一个文件呢?
how do we actually make a file?
我们就来新建一个文件
Ok, so let’s make a file.
我们在”home”目录下 或许我们可以移动到”Desktop”目录
We’re sitting in our ‘home’ folder, or we’d go on the ‘Desktop’.
改变目录到这里
So change directory there,
“touch”命令会新建一个空文件
and ‘touch’ creates an empty file.
如果输入”touch myawesomefile.txt”
So if you just ‘touch myawesomefile.txt’,
就创建了一个空的文本文件
this is an empty text file.
我已经在”Desktop”目录下创建了
and because I’ve made it on the ‘Desktop’,
可以看到 它就在这
you can actually see, there it is.
我甚至可以打开它
I could even open this up,
输入一些内容
and type in,
“this is some incredible stuff!”
‘this is some incredible stuff!’.
因为它是一个文本文件
Because, boy, it is.
我们已经用”touch”创建了一个文件
Ok, so we’ve created a file with touch,
还有其他几种方式可以做到
there’s other ways of doing that,
但是在这里我只会演示这一种
but that’s just the one I’m going to show you now for playing around.
有一种读取文件的方式
And there’s a way of reading.
有些人可能对我很生气 告诉我说
now some people would get really angry at me here and tell me,
“cat”实际是用来联接的
‘cat’ is actually for a concatenation,
它可以依次读取多个文件
which is reading out files sequentially,
只有在多个文件的时候才有意义
which is too pointless unless you get more than one file,
但是你知道吗 它是读取文本的简便方式
but you know what, it’s an easy way to read text from a file.
所以我们会使用”cat”
So, we’re going to ‘cat’,
打印出这个文件的内容
or print out everything that’s in here,
“myawesomefile.txt “文件
‘myawesomefile.txt’.
真是不可思议
Wow, that is incredible.
希望你不要被我无聊的幽默感吓到
I hope you aren’t horrified by my dry sense of humour,
我确实认为这个东西很酷
I actually do think this stuff is cool, but,
我知道这些很基础
boy these basics,
我也很确定你们想要一些更酷的东西
I’m sure you’re just itching to some, to something cooler, but,
但是我们要循序渐进
the only way is through.
我们已经创建了一个文件
Ok, so, we’ve touched the file, or created it.
并且在其中写入了一些东西
We’ve written some stuff in there,
但是怎么才能从命令行写入呢?
but how do we write stuff there from the command line?
这个我们会在稍后讲
No, we’ll get to that a little bit later.
现在 我们为什么不创建一个目录并把那个文件放进去呢?
But for now, why don’t we create a directory to put that file into?
创建目录的命令是 “mkdir”(make directory)
The command for that is ‘make directory’, ‘mkdir’.
它的使用就像其他命令一样
So you’re going to use it like any other command,
命令 空格 后面是可选项
the command, space, fly with any options that you want.
我们不用任何可选项
we don’t want any.
再后面是目录名称
And then the name of the directory.
我们可以写”aplaceforawesomeness “
So let’s, a ‘aplaceforawesomeness’,
这就是我们的目录
that will be our directory.
用”ls”可以看到当前目录的内容
If we ‘ls’, we can see all these things.
如果你想知道这个奇怪的东西是什么……
If you’re wondering what this wired thing is,
该死的Ubuntu和Gedit
damn, damn you Ubuntu and Gedit,
Gedit或者G-edit
Gedit or G-edit,
它是一个编辑器 我刚才用它来输入文本
the editor I used to just put some text in that file a second ago,
并且它可以创建自动保存文件
creates auto-saved files.
比如说临时文件
for like temp files,
这就是你看到的
so that’s what you’re seeing.
这个才是真正的文件
This is that actual file.
如果你正在编辑文件
But it’s all like, if you’re editing something,
还没保存电脑就突然崩溃了
and your computer crashes before you save,
你已经改变了的内容就会写入到这里
the state, the stuff you’ve changed is written into here.
但是有一件奇怪的事
But you know the weird thing is,
我已经保存了 这个文件却还在
I did save and it didn’t get rid of it,
这令人很恼火 不要对这感到困惑
which is annoying, so don’t get confused by that.
现在我们有了一个文件和一个放文件的地方
Ok, so now we’ve got a file, and a place for the awesome file,
接下来我们就要移动文件
now we’ve got to move the file.
我们已经创建了这个文件
So we’ve touched the file,
使用”mkdir”命令
we used ‘mkdir’,
创建了一个文件夹
to create a folder.
现在我们可以移动这个文件了
And now we can just move the file.
我会在这使用自动补全 “mv”移动
I’m using tab completion here, so ‘mv’ for move,
文件”myawesomefile “
‘myawesomefile’,
到目录”aplaceforawesomeness “
to ‘aplaceforawesomeness’.
所以
So,
这种命令格式在Linux中有很多
this sort of formula is going to come up a lot in Linux,
首先是命令
you have the command,
后面是它带的参数
and the arguments it takes,
在这个例子里 是文件名和目录名
in this case, a file name and a place,
这个文件也可以是文件夹
or a thing and a place, it can be a folder too.
它就是你要改变位置的东西
And it’s always going to be the thing that you’re going to change to the target,
就像源和目标一样
so it’s always like, the source and then the target.
靠近命令的第一个参数
So first the thing that’s close,
是你要操作的东西
the thing you’re going to do the thing to,
在这个例子中 是移动
in this case, moving it.
第二个参数是目标
And then the second argument will always be, like,
即要移动到的地方
the target, the place it’s going.
有非常多的命令的格式
And that would be the same,
都和这一样
across, so like a wide variety of, of commands.
一定要牢牢记住这一点
So just start getting that ingrained now.
你要操作第一个参数
You want to do something to the first argument,
第二个参数是目标 是要移动到的地方
and the second argument is like, kind of the target, the place it’s going.
文件的复制 移动
Any file-copying, moving,
甚至移动到远程机器
even like to a remote machine,
或者服务器都是这样的
or a server is done that way.
我们要把文件移动到文件夹
Ok, so we’re going to move the file to the folder.
不可思议
Incredible.
如果使用”ls aplaceforawesomeness”命令
If we ‘ls aplaceforawesomeness’,
就可以看到它里面的文件了
you can see the file’s in there.
我们现在仍在”Desktop”目录下
We’re still sitting in the desktop though,
从shell的提示符就可以看出来
as you can see from my shell prompt here.
那个声音实际上是我接收到消息的声音
That sound actually, the, my text received sound,
它来自《杀出重围》
is actually stolen horribly from, from Deus Ex,
就是刚开始屏幕上一闪而过的那个游戏
the game that I flashed across your screen earlier, at the very beginning.
它是一个很酷的游戏
It’s just such a cool game,
我从里面拿了一些我最喜欢的音效
I went in there and I took some of my favourite sound effects,
并且把它们做成了手机铃声
and made them to like, ringtones, and,
以及其他一些声音
other stuff for my phone.
如果你听到了鸟叫的声音 那就是它了
So if you hear that chirping in the background, that’s what that is.
我们已经成功地创建了一个文件
Ok, so we’ve now successfully created a file,
一个文件夹 并且把文件移动到了文件夹
created a folder, we moved the file into the folder.
这里还有一个烦人的备份文件
But now we’ve got this really annoying backup file here,
就是这个”myawesomefile.txt~”文件
this ‘myawesomefile.txt~’,
我讨厌波浪号
I just hate the tilde.
所以我们要删除它
So what we’re going to do is remove it.
删除文件是非常简单的
Removing a file is very easy.
你需要使用删除命令
You do it with the remove command,
“rm”
‘rm’.
我仍会使用自动补全
And I’m using tab completion again,
我只输入”m”
so I’m typing in like, ‘m’
因为只有一个以”m”开头的文件
and because the only thing with an ‘m’ here is that file,
按”Tab”键就会补全了
a ‘Tab’ will fill it in.
所以
So,
接下来我要用”rm”命令删除它
I’m going to go ahead and delete it by using ‘rm’ to remove.
可以看到 它已经没了
You can see, it’s gone.
非常酷
Ok, cool.
删除这个文件夹和它里面的文件怎么样?
So how about we remove the file inside the folder,
怎么才能删除一个文件夹呢?
and the folder itself, how do you get rid of a folder?
“rmdir”可以用来删除文件夹
Well, ‘rmdir’ is a way of removing a folder,
我们先创建一个文件夹
so let’s just make a,
叫”testrm”
‘testrm’,
创建文件夹”testrm”来试验删除命令
creating a directory test remove, ‘testrm’.
接下来 我们使用”rmdir testrm”命令
And we’ll do, ‘rmdir testrm’.
我要删除”testrm”文件夹
So I’m removing the directory ‘testrm’,
非常好
it’s well and good,
它起作用了
it works.
但是只有空文件夹时 它才起作用
It only works cause the directory is empty.
我们返回到刚才 重新创建那个目录
If we go back and create that directory again,
下面我要显示一个很酷的技巧
that’s a cool trick I’m going to show you later.
我们又创建了那个文件夹
If we just create that folder again,
不 是目录 怎么会是文件夹呢
sorry, directory, god, folder, you know that’s,
在Mac中 它会引起错误
corrupted from the Mac world,
大约20年前我开始使用Mac
I started on Macs like 20 years ago, so,
我想 这个极度错误的词汇一直潜伏在我大脑里
I think that, that horribly wrong vocabulary is somewhere in my brain.
无论如何 目录”testrm”
Anyway, the directory, ‘testrm’,
已经创建好了
is now created.
我们要在它里面创建一个文件
And let’s just ‘touch’ a file in there,
比如这样 我们可以创建”testrm/testdeletefile”文件
so like, we’ll make ‘testrm/testdeletefile’,
它只是一个空文件
and it’s just like an empty file.
如果列出目录中的内容
But if we list what’s in there,
就可以看到这个文件了
we can see the files in there.
可以看到这个文件
We can see, the folder there.
我们再试一下”rmdir”命令
Ok, so let’s try ‘rmdir’ again.
出现了错误
We got an error.
因为”rmdir”通常只能删除(空)目录
Because ‘rmdir’ generally is only deleting, big d, directories.
接下来我要教你”rm”命令
I’m just going to teach you ‘rm’,
你可以用”rm”删除文件 也可以删除目录
you can use ‘rm’ for files, you can use it for directories,
没多少东西要记
it’s less stuff to remember.
接下来我们要做什么呢?
So that what we’re going to do,
删除”testrm”目录
remove the ‘testrm’ directory.
我们试一下
Let’s try that.
好了
Ok.
我们会使用参数”r”表示递归删除
We’re going to use the ‘r’ for recursively,
也就是它下面的所有东西都会被删除
so everything underneath, deleted as well.
怎么才能知道如何使用命令呢?
Ok, now how did I know to do that?
如果出现了
If you get,
一个错误
an error,
你应该看的地方是……
the place you should look is,
比如 你忘记”mv”的用法了
so like, if you forget how to use move, right, ‘mv’,
不知道第一个参数是文件还是目标地址
do I put the file first or the destination, I don’t know,
“man” 查看手册
‘man’, for manual,
就起作用了
is the command,
基本上 你应该会一直用到它
that you should be using basically all the time.
每次你忘记怎么做的时候
Every time you forget how to do something,
每次你想知道一个命令的用法的时候
every time you’re wondering how to use a command,
就可以用”man”查看手册
‘man’ accesses the manual page.
通常它很有用
The command aid generally.
只需要输入”man”以及命令就可以了
So just type in ‘man’ and then the command.
再做一遍怎么样?
How do we do that again?
它可以移动和重命名文件
Oh yeah, move and rename files,
按’q’键可以退出
‘Q’ gets you out of here.
你可以正常的上下滚动
You can scroll normally,
你可以用上下键 也可以用”page down”键
you can use your ‘up/down’ keys, your ‘page down’,
一旦你想退出了 按’q’就可以
But once you want to quit, just ‘Q’ for quit.
所以
Ok, so,
怎样才能知道删除文件时”-r”的作用呢?
how did I know to use ‘-r’ for removing something?
可以看到
Well, you can see,
这是命令名称 它能做什么
it’s the name of the command, what it does,
它会告诉你可用选项
tells you which options or flags you can use.
可以看到
So you can see,
这个参数很有趣 你还会多次见到
this one is interesting, you’ll see this a lot,
这个也很有趣 我们刚刚用过
and this one is interesting, it’s the one we just used.
它会包括所有的子目录
So this will traverse through subdirectories,
删除里面的所有文件
and remove all the files inside of them,
然后再删除所有目录
then remove all the directories.
所以说”man”命令
Ok, so, ‘man’,
非常非常重要
it’s really really really really really important,
你应该学会如何使用它
that you learn to use ‘man’,
“man man”
‘man man’,
棒极了
yay, it’s wonderful,
它是一条不可思议的命令
it’s like a meta incredible command.
我们已经学习了什么呢?
Ok, so what have we covered?
这些都是基本命令 你应该实际操作一下
This is like, this is the basics and you should play around with this,
你应该逛遍整个系统
you should go around your entire system,
用”cd”切换不同位置
and ‘cd’ to different places,
我看一下…… 我们就列出”boot”目录的内容吧
like, let’s see what’s in…let’s ‘ls boot’,
听起来很有趣
that sounds interesting,
这是系统内核以及系统启动所需的东西
well it’s your Kernel and all the stuff that your system uses for booting.
我们有什么设备呢? 可以进入看一下
What kind of devices do we have, you can go in there.
哇偶
Ooh.
有许多电传打字机 它们是虚拟的
Lots of teletypes, virtual teletypes,
所有硬件设备都会安装在这
and all your hardware devices are, kind of, mounted here.
很容易让人混淆
This is all very confusing.
但是不要担心这里的东西
But don’t, don’t worry about what’s in here yet,
只担心怎样在系统中移动就行了
just worry about a mechanics of moving around the system,
并且要一直记得你在哪
of always keeping in your head where you are,
如果你需要提示
and if you need to cheat,
看提示符就好了
you can always, obviously just look at your prompt.
如果找不到路径了
If you ever get lost,
我们就这样……
let’s give it a,
就比如说 如果我们设置了逻辑卷管理
so it’ll be like, if we had LVM set up,
整个文件系统就都在这了
you, our whole file system would be in here.
天啊 我找不到位置了
Oh my god I’m lost.
用”cd”就可以回到家目录 非常好
Just ‘cd’, go home, it’s all good.
有3种不同的方法可以回到家目录
And you can obviously go home in 3 different ways,
你可以用”cd ~”回到家目录
you could ‘cd ~’, that gets you here;
也可以用”cd /home/”加上你的用户名
you could ‘cd’ to ‘/home’ and ‘/yourusername’,
这也可以回去
that gets you there;
也可以只输入”cd” 就能回去
or you can just hit ‘cd’, and that get you there.
我们能够创建文件了
We can ‘touch’ files,
但是
just,
一会儿你会很恼火的
this is going to really annoy you later,
如果你在文件系统的某一地方创建了一个文件
if you make files all over the file system.
我想说的是
So I would say,
你可能在”Desktop”创建了文件
keep the files that you created maybe on your ‘Desktop’,
我们可以回到”home”文件夹
so like, go to your ‘home’ folder,
或”Desktop” 并在其中创建文件及目录
or your ‘Desktop’ and create files and directories there.
同样也可以删除一些东西
Likewise with removing things,
如果你删错了Linux中的文件
you can bork your whole system,
可能会导致整个系统崩溃
if you remove the wrong file in Linux,
尤其是删除”root”里的文件时
like especially up here in ‘root’.
删除的时候一定要非常小心
Dah…use this with extreme caution,
因为
because,
这条著名的Linux命令”rm -rf /”
with the famous Linux command ‘rm -rf /’,
会破坏整个系统
will destroy your entire system.
它会强制递归
It will just recursively force,
也就是会遍历整个/”目录
so recursively work it’s way through all the directories in ‘/’,
包括它里面的所有目录 所以你整个系统
which is all of these directories, so your entire system,
内的文件都会被删除
delete all the files in there,
然后再删除目录
and then delete the folders or the directories,
只剩下一个死系统
leaving you with a, a totally dead system.
这就是Linux的力量
So that’s the kind of power Linux gives you,
你可以做任何事
you can do anything, but,
但可以做任何事也是问题所在
that’s also the problem, you could do anything.
所以使用时一定要明智
So use this power wisely,
现在我们是在家目录
and for now, only in you ‘home’ folder.
如果你记了笔记的话 可以复习一下
Review these commands if you’re writing notes,
可能会很有用
which you, may be as useful.
“ls” “pwd”
‘ls’, ‘pwd’,
“cd”
‘cd’,
“touch”创建文件 “mkdir”
‘touch’ files, ‘mkdir’,
“rm”删除文件
‘rm’ files,
也可以带”-r”参数
or ‘-r’,
我们还做了别的吗?
and did we do anything else?
当然了 “man”
Yeah, ‘man’,
一定要记住”man”命令
man oh man, gotta remember to ‘man’.
“man”命令页面的有些内容不理解也没关系
If you…it’s ok not to understand some of the ‘man’ pages,
有些地方需要你熟悉Linux
some of them require that, you’re like, at least a little bit familiar with Linux,
但是许多基础命令并不需要这些
a lot of the basic ones, for basic commands don’t.
所以在你开始疯狂的用谷歌搜索以前
So before you start googling like crazy,
在你询问别人以前
and before you ask anyone a question,
尤其是在你询问别人以前
especially before you ask anyone a question,
要自己研究一下
do your research,
“man”加上你遇到困难的命令
do ‘man’ and then the command that you’re having trouble with.
这条命令是做什么?应该怎么用?
Alright, what is this command, what’s this supposed to do?
好好读这些东西
Really, read this stuff,
它就像是命令如何工作的免费课程
this is like a free education on how these things work.
可能有些地方你不理解 也没关系
Some of it’s going to be over your head, and that’s ok.
但是你一定要读它
But you should, really you have to read this stuff,
你应该要学会
and you have to become someone,
在问问题之前自己研究一下
who researches stuff before you ask questions.
这是才能做一个快乐的系统管理员
That’s the path to happy Linux sysadminhood.
非常有趣 下次见
Good, it’s been fun, I’ll see you for the next video,
我们会从这继续
and we will proceed from here.
这些都是非常基础的命令:在文件系统中移动
So these are the very basics of moving around the file system,
复制文件 移动文件 创建文件及文件夹
copying files, moving files, creating things,
我们也学了”mv”命令
We also covered ‘mv’,
以及删除文件及文件夹
and remove things.
这些都很基础
So you can kind of…these are the basics.
你要练习这些东西 我们下节课见
Practice this stuff and I’ll see you in the next video.

发表评论

译制信息
视频概述

本节课程介绍了Linux中一些基础命令的使用,如ls、rm、mkdir、touch、cd等。

听录译者

positiveme

翻译译者

[B]hugue

审核员

审核团O

视频来源

https://www.youtube.com/watch?v=Lbh8Bh_SEzU

相关推荐