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

《胡须Linux教程》#3 新手命令行5分钟教程 – 译学馆
未登陆,请登陆后再发表信息
最新评论 (0)
播放视频

《胡须Linux教程》#3 新手命令行5分钟教程

Linux Command-Line for Beginners: Your First 5 Minutes

有些时候 你被甩到了Linux命令行
So sometimes, you just get dumped on the Linux command line,
自此对所作所为一无所知
without really knowing what you’re doing.
可能是你正在致力于开发的一个项目
Maybe it’s for a project you’re working on,
或者说 你是个程序员
or you’re a programmer,
对Linux并不是很适应
and you’re not entirely comfortable with Linux.
但服务器上运行着它
But the server’s running it,
或其它原因让你不得不用到Linux命令行
or for some reason you end up on the Linux command line.
那么
So,
不要感觉害怕
instead of being terrified,
我会给你展示非常非常非常基础的使用方法
I’m going to show you the very, very, very basics of what to do,
比如 怎么在目录间移动
how to move around,
其工作原理是什么
and how the thing generally works.
对于我的大部分订阅者们
So for most of my subscribers,
这回有点… 我不得不说 这些东西很基础
this will be a…a little bit, I would say a lot, too basic.
但重点是
But the point is,
我会在右边屏幕给你解释命令行的操作
I’m going to try to translate actions over here on the right,
其实就是在文件管理器中的操作
in a file manager,
与命令行中的操作结果一致
to corresponding actions on the command line.
然后你就会发现
So you can see that,
其实命令行并不是晦涩难懂的
it’s not just this scary arcane commands,
实际上命令行是个很简单的东西
but it’s actually just fairly simple things.
只要你用上几次 你就能够轻松记住
And once you try ’em a couple of times,
然后就会觉得在命令行中操作会很舒服
you’ll remember ’em, and you’ll feel comfortable on the Linux command line.
通常情况下 当你开始打开一个shell窗口
You start, generally when you open a shell,
出于我们本次目的 shell就是命令行
so the shell is, for our purposes, the command line,
这个环境表示的意思就是窗口正在等待你的命令
it’s the environment that is listening for your commands,
当你输入命令的时候它会给你一些反馈
and then giving you something back, when you type in a command.
需要输入命令 执行命令 最后返回给你结果
It takes a command, evaluates that command and then gives you the result,
它很像一个计算器
it’s pretty much like a calculator,
像一个非常 非常高级 非常酷炫的计算器
like a really, really advanced, really awesome calculator.
那么 我将要教给你的第一行命令
You can see, the very first command I’m going to teach you,
因为在很多时候
is because, a lot of the time,
最终 你可能会处在一个未知位置
you’ll end up somewhere where you don’t know where you are.
那么 你想要做的第一个事情会是
And the very first thing you want to do,
去寻找“我到底在系统中的哪个地方?”问题的答案
if find out, ‘where the heck am I on this system?’.
为了解决这个问题的命令是pwd
And for that, the command is ‘pwd’,
也就是print working directory的简写
which is short for ‘print (my) working directory’.
然后输入pwd
So, just type in ‘pwd’,
按Enter键提交命令
and the ‘Enter’ key submits a command,
shell就会去执行它 很神奇
and then the shell goes and evaluates it, does some magic,
然后在下一行开始给你答案
and then gives you the answer on the next line or lines.
现在复习一下
So, just to review,
你会有个提示符
you’re given a prompt,
一个shell的提示符 就是这个
a shell prompt, that’s what this is.
它的意思是 hey我准备好你给我下达命令了
It’s saying, ‘hey, I’m ready for you to give me some commands’,
输入命令 点击Enter
you type in a command, you hit ‘Enter’,
然后很神奇的给出了结果
it does its magic, and gives you back an answer.
这是一个非常非常简单的版本
It’s the very, very simple version of what’s going on here.
输出工作目录
So, ‘print working directory’,
它实际上是什么意思呢?
well, what, what is this actually saying?
它指的是 ‘you’re in the directory’
It’s saying, ‘you’re in the directory’,
/home/dave
‘/home/dave’.
路径通常从这里开始
Paths, generally will start with root,
第一个’/’被叫做根目录
this first ‘/’ is called the root,
基本上 不存在比这个更高一级的目录
and basically, you can’t go up any higher than this.
我给你展示一下
I’ll show you.
在这 我们有个一样的目录
So here, we’ve got the same exact directory.
这个文件管理器是图形化的
This file manager is graphical,
但其实是一样的东西
but it’s the same thing,
它的意思是说 hey 老哥 你在这个目录下
it’s saying, ‘hey dude, you’re in the home directory’,
你在这里 就是home
there you are, it’s ‘home’.
然后
So,
第一个’/’是所有文件系统的开头
this first ‘/’, is all the way at the top of the file system.
如果我们在这点击’Computer’的话
So if we click on ‘Computer’ here,
这是文件系统的最高层
this is the top of the file system.
别管这些东西
Don’t worry about all these confusing things.
你能看到’/’在最开始 然后是’home’
So you see ‘/’ is the top, and then we have ‘home’.
那么进入home目录里
So we go into ‘home’,
然后是dave
and then ‘dave’,
我们进到dave目录下
so we go into ‘dave’.
看 现在我们在dave下了
And there we are.
那么 对于这个问题
So, that’s the same action.
我在哪一个目录里?
Basically asking ‘which directory am I in?’,
在图形化的文件浏览中
in a graphical file browser,
以及在命令行中 两者是相同的
and on the command line.
输出工作目录 pwd
‘print working directory’, ‘pwd’.
如果你现在不能试试这个命令的话 写下来
If you don’t, if you haven’t tried it right now, write it down.
下一个问题我们会问
So the next question we ask,
既然我们现在知道了自己在哪个文件系统里
now that we know where we are on the file system,
那么这个目录是什么
is, what’s here,
这目录里面有什么
what is in this directory that I’m in?
在图形化的浏览中很明显
Obviously in a graphical file browser,
默认的界面会显示目录下有什么东西
that’s sort of, the default view is, what’s in this directory.
但是如果我想在命令行中看的话
If I want to do that on the command line,
我就得在这里输入ls 也就是list的缩写
all I have to do is type in ‘ls’, for ‘list’,
请列出现在的目录的东西
please list the things that are in my directory right now.
你就能看到结果
And you could see the answer it gives me,
这里的东西完全是一样的
is essentially the exact same thing as this here.
你能在这里看到’site.retry’
So you can see there’s ‘site.retry’,
‘hithere’文本文件
the ‘hithere’ text file,
‘Downloads’文件夹 ‘Music’文件夹等等
the ‘Downloads’ document, ‘Music’ etc. ,
这边 很显然有漂亮的图标和所有东西
in here, obviously they have pretty icons and everything,
但是它们的含义并无区别
but it’s the same idea.
都是列出一些东西
You list something,
显示这里有什么
and it shows you what’s in the place that you are.
现在我们做点更难的事
Now, what’s a little bit harder do to,
我想看看这里的Desktop有什么
is let’s say, I want to see what’s on the ‘Desktop’ here.
双击Desktop
We’ll have to double click on the ‘Desktop’,
然后它告诉我
and then it’ll tell me.
这些就是Desktop里的东西
Ok, that what’s in the ‘Desktop’.
我会返回到home
I’ll go back to ‘home’.
如果我想看看这里的Desktop
If I want to see what’s on the ‘Desktop’ here,
实际上我不用移动
I actually don’t have to move.
我只是仅仅在所在的文件系统中
I can simply stay where I am on the file system,
在/home/dave中
so in ‘/home/dave’,
我可以说 ls /Desktop
and I can say ‘ls /Desktop’,
在大部分情况下按Tab键会有自动补全
and hitting ‘Tab’ in most trials will get you autocompletion.
我刚才就只输入了
So I just actually typed in,
ls Des
‘ls Des’,
它已经知道要输入什么了
and it already knows,
缩小范围的话就只有一个选择就是Desktop
that narrows it down to just one choice, which is ‘Desktop’.
假如我只输入了D
If I just did ‘D’,
这里就会有模糊搜寻结果
there would be some ambiguity there,
他就出现了3个选项
it could be any of those 3 things.
它给我显示了3个可能的选项
So it shows me the 3 things which it could be.
你看这里没有新的提示符
And you can there’s no new shell prompt at the bottom,
它实际上是在等我输完命令并提交
so it’s actually still waiting for me to finish typing in my command and hit ‘Enter’.
这是我会做的事
So that is what I’ll do,
我会说 哦 耶 实际上我只想输入Des
I’ll say, ‘oh yeah I actually meant Des’,
因为补全的话这已经足够了
and that should be enough for you to figure it out.
下一次我按Tab的时候会自动补全
And it is, next time I hit ‘Tab’, it autocompletes.
当我在这按下Enter时
So when I hit ‘Enter’ here,
我得到Desktop的列表
I get a listing of what’s on the ‘Desktop’.
就这样子 一样的想法 对吗
So there you go, same idea, right?
看看这个’ansible’目录还有所有的文件
See the ‘ansible’ directory, and all those files.
Ok 返回到home目录下
Ok, back to the ‘home’ directory,
你可以看到
and you can see, I actually,
我没有改变地址
here I haven’t changed location,
我仍然在/home/dave目录下
I’m still sitting in ‘/home/dave’.
如果要做和图形化同样的操作 即移动到Desktop
So, if I actually wanted to do the same thing and move to the ‘Desktop’,
看这里 我本来就是要去Desktop目录下
here, essentially I’m moving to the ‘Desktop’,
我看看这里面是什么
and I’m looking at what’s there.
如果我想要移动到这里
If I wanted to actually move there,
我得改变现在的目录
I’d have to change the directory that I’m in.
所以很多人把这个叫做文件夹 文件夹 目录
So a lot of people call this the folder, folder directory,
他们都是一样的
it’s all the same.
所以我想要改变所在的文件夹或目录的话
So if I wanted to change the folder I’m in, or the directory,
我会用 cd
I would say, ‘cd’,
请改变我当前所在的目录
please change the directory that I’m in.
在这之前
And as before,
Tab帮我自动补全了
‘Tab’ gets me my autocompletion,
因为我很懒 不过我觉得你也应该这样做
because I’m lazy, and you should be, too.
cd Desktop的意思是
So, ‘cd Desktop’ says,
ok 现在我想要移动到Desktop目录
‘ok, now I actually want to move to the Desktop,’ ,
我不想要列出里面的东西
‘I just don’t, I don’t want a list of what’s in there,’ ,
我只是想移动自己的位置
‘I just want to move myself’,
所以现在我在Desktop目录下
‘so that I’m sitting in the Desktop.’ .
我现在在Desktop目录下
And I’m sitting in the ‘Desktop’.
你可以看到显示的是Desktop 它刚才已经改了
You can see it’s showing me ‘Desktop’, this has changed.
这有一个标记
This little symbol here,
是/home/yourusername的简写
is a shortcut for ‘/home/your username’.
我的用户名是dave
So, my username’s ‘dave’,
这个标记让我知道我确实在这里
so this little symbol let’s me know I’m actually here.
如果我是其他用户
If I was a different user,
这还会有一个标记
you know, this would be the symbol for,
/home/我的用户名
‘/home/whatever my username is’.
如果我是andrew
So if I was ‘andrew’,
这个标记会是/home/andrew
then this symbol would mean, ‘/home/andrew’.
好 我们还在Desktop里面
Ok, but we’re sitting on the ‘Desktop’,
现在我们做和刚才相同的事
and now we can the same thing we did before.
我们可以用 ls
We can just ‘ls’,
就会得到当前目录下的文件
and we’ll get the list of files and directories in our current directory,
我们在什么位置
so where we are.
我们现在在Desktop目录下
Since we’re sitting on the ‘Desktop’ here,
得到了这个 一样的列表
we get this, same list.
现在讲解关于up和down在文件系统中的概念
Now, there’s this concept of going up and down in the file system,
这可能会有点难
this can be a little bit confusing,
我会用整个视频来解释这个
and I’ve got a whole video that explains this.
现在的话
But just for now,
我会演示给你
I’m going to show you,
up通常意味着朝向文件系统的根目录
up, generally means towards the root of the file system,
也就是目录的最外层
which is this outermost directory here.
你会看到这种说法
So you can see it says,
打开文件系统目录
‘Open the contents of the file system’,
这是所有的了
that’s everything.
这个就是’/’
And that’s what this ‘/’ is,
就像你之前记得一样
as you remember from before,
它叫做root
it’s called ‘root’.
所有的文件都在这个目录里面
And that’s the directory where everything else is inside of it.
你不能返回到比这个更深的目录
You can’t go back any further than that.
你看
So, you can see,
如果我们点击这里的Computer图标
if we actually click on this ‘Computer’ icon here,
那就是根目录 就像显示的那样子
that’s the root directory, it’s showing us what that is.
我们也可以到这里
And we can…we can go there, too.
我们能改变目录
So we can change directory,
你也可以只是列出这个
you could also just list it,
如果你给ls加一个’/’就像目录名那样
right, if you gave ‘ls’ just a ‘/’ as the directory name,
他会列出根目录
it would list the root directory.
但是你看我们还在Desktop目录下
But you can see we’re still sitting in the Desktop’,
你能从这个提示符后面看到
which you can see after the prompt.
如果你用 cd / 的话
So if you say, ‘cd /’,
然后运行命令ls 也可以看到相同的结果
you’ll…and then run a listing, you’ll see the same thing.
但你实际上就已经到达根目录了
But you’ll actually be sitting there, ok.
现在我要改变我所在的shell
Now, I’m going to change the shell I’m in.
这个就是很可能的结果
And this is most likely going to be,
顺便说一下 如果你想清除这些东西
by the way, if you want to clear the,
就是刚才在shell里屏幕上显示的那些东西
the stuff you’ve got on your screen on the shell,
clear命令就可以
‘clear’ does that.
这个命令其实就把shell向下卷屏了
and it really just sort of, scrolls the shell down, so,
如果把滚轮滑上去 它没有改变任何东西
I can, you can see I can actually scroll up, it didn’t do anything.
这就是创建了新的一行并且滑到了下面
It just created a new line, and scrolled me down,
我不会在看到上面的任何东西了
so I couldn’t see all this junk up here anymore, ok.
我们刚才清除了小终端
So we’ve cleared our little terminal,
这个是… 我知道在这里有很多名字 但是
that’s, I know there’s a lot of names for everything here, but,
terminal是最基本的叫法 这个视频里会这样说
terminal, is basically, for the purposes of this video,
这和shell或者命令行一样
it’s the same as shell, and it’s the same thing as command line.
把所有的名称挤在脑子里吧
Just glum all those things together in you brain,
它们都是一样的东西
that’s, that all means the same thing,
shell 终端 命令行
your shell, your terminal, command line.
很明显技术上它们略有区别
Obviously there’s technical differences to them,
但这个现在不重要
but it’s not important for now.
你不需要现在学会
You don’t have to learn that right away.
ok
Ok.
你能看到我改了一点提示符
So you can see I just changed how my little shell prompt looks.
这还有更多的信息
And there’s a little bit more information,
这也可能更接近于你的shell中的显示
and this is probably a little bit more like what you’d be seeing on your shell.
我用的这个叫Z shell 你用的终端可能叫Bash
I use one that’s called Z shell, you’d be using a shell called probably Bash.
Bash里面会给你更多的信息
And Bash shows you a little bit more information,
不过它也会让你的屏幕更加的凌乱
at the cost of cluttering up your screen a little bit more.
它显示了我的所在机器的用户名
So it’s showing me my username, at the machine I’m on,
它叫mylinuxmachine也就是机器的主机名
it’s called ‘mylinuxmachine’, that’s the host name of the machine.
附带一说 email地址起源于此
Incidentally this is where email addresses come from,
他们曾经在70年代被使用
they were, this was being used, you know, in the 70s,
这时距离email被广泛使用还有相当一段时间
way before email really was a thing.
‘user@mymachinesname’
So ‘user@mymahcinesname’,
然后是’location’
and then ‘location’.
你看路径这里用了一个小标记
And the location you see, it’s using this little, this little tilled symbol,
这就是一个简写
which we said, is really just a short name of,
‘/home/username’ 也就是 ‘dave’
‘/home/username’ right, ‘dave’.
这说的是
So what this is really saying is,
你所在的这个位置 在脑子里展开它
‘you’re sitting in’, if you just expand this in your mind,
相当于是
you’re actually saying,
/home/dave/Desktop
‘/home/dave/Desktop’.
这是你看到的部分
But this is the only part you see,
否则如果你在一个文件夹的很里面的位置
otherwise, your shell would just be full of, like, your path,
你的shell会显示全部的路径
if you’re sitting in some folder very far down the tree.
ok 现在我会解释up和down
Ok, now I’m going to explain this whole up and down thing,
cd
‘cd’,
这个’..’ 两个点 意思是返回或up一层
this ‘..’ means back, or up.
这是我们当前的路径
And if we just say, so here’s our path,
我们在/home/dave/Desktop
we’re sitting in ‘/home/dave/Desktop’.
如果你想返回上一层目录
If we want to go up a directory,
up的意思是离根目录更接近
up just means closer to the root of the tree,
大概可以画一个颠倒的树
basically picture an upside-down tree.
如果我们想去目录的上边
If we want to go up a directory,
进入/home/dave离开Desktop目录
so into ‘/home/dave’ and get out of the ‘Desktop’,
你可以用 ‘cd ..’
you simply say, ‘cd ..’ .
这个是一个简写
Now this is a shortcut for,
我们也可以用 cd /home/dave
I’m mean we could also say ‘cd /home/dave’,
这个命令就可以让我们到那个目录下
and that would get us there.
在这
There we are.
让我们返回Desktop
But let’s go back to the ‘Desktop’,
现在又在desktop目录了
here we are in the desktop again,
我们可以用 cd 命令
we can just shortcut that to ‘cd ..’ .
你能看到同样的结果
And you’ll see the same thing happens.
cd ..和cd up one directory的意思一样
‘cd ..’ is the same as saying ‘cd up one directory’.
那也是一个节约输入的方法
That’s just a way of saving yourself some typing.
附带一提 一个点意味着返回到当前目录
A single dot incidentally just means the current directory that I’m in.
当你第一次用Linux可能不会觉得这些有用
Not that useful when you’re first starting on Linux,
但是以后会觉得他们有用
but it comes into play later.
ok 这些是在Linux上操作非常非常基础的东西
Ok, so these are the very, very, very basics of working and playing with Linux.
如果你有时候被困在命令行
If you end up stranded on the command line somewhere,
也不知道该做什么
and you don’t know what to do,
这至少会让你了解一下
this should at least get you moving around looking at things,
找到你所在的位置
figuring where you are,
探索一点点未知道路
and exploring a tiny bit.
如果这个有用的话
If this has been helpful,
关注我的twitter和Facebook
make sure to twitter, tweet, subscribe, add me to your Facebook,
关注我的Instagram 给我发Snapchat
Instagram me, send me a Snapchat,
-然后 痴迷于社交媒体-他们怎么会因为账户里关注这些炒你鱿鱼呢?
-and otherwise, go crazy with social media.-How can they fire you for any accounts for all those things?
-确实是我所有任何账号都没有关注这些-你没有任何账号关注
-That’s true, I don’t have accounts for all of them.-You don’t have accounts for any of them.
好吧 糟了个糕的 我没有账户 再见(笑声)
-Alright, I don’t have account, it’s too bad, goodbye.-Hahaha.

发表评论

译制信息
视频概述

Linux需要图形界面吗?好的程序员不会用图形界面!

听录译者

positiveme

翻译译者

[B]Azrael

审核员

审核团1024

视频来源

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

相关推荐