ED 101: Essential Linux (25 pts) ED 101:基本Linux(25分)

What You Need for This Project你需要什么这个项目

Purpose目的

To practice basic Linux commands and understand how to efficiently improve your Linux command-line skills.练习基本的Linux命令并了解如何有效地提高Linux命令行技能。

Structure of this Project该项目的结构

Work through the commands and explanations below.完成下面的命令和解释。 After that, there are challenges to solve, without instructions.在那之后,没有指示就有挑战需要解决。 You can solve the challenges using the techniques explained below.您可以使用下面介绍的技术解决这些挑战。

1. ls ls

This is the most important command of all.这是所有人中最重要的命令。 It shows you the files and folders in the working directory, so you can see where you are and what's going on.它会显示工作目录中的文件和文件夹,因此您可以看到自己的位置和发生的情况。

Execute this command (lowercase LS):执行此命令(小写LS):

ls LS
This command shows files and directories in the current working directory, as shown below.此命令显示当前工作目录中的文件和目录,如下所示。

"ls" by itself isn't very useful, because it doesn't tell you much about the items. “ls”本身并不是很有用,因为它没有告诉你很多关于这些项目的信息。 The next command is far more helpful.下一个命令更有帮助。

Execute this command (lowercase LS -L):执行此命令(小写LS -L):

ls -l ls -l
This "long list" tells you a lot more information, as shown below.这个“长列表”会告诉您更多信息,如下所示。

The first character in each line is "d" for directories, or "-" for files.每行中的第一个字符对于目录是“d”,对于文件是“ - ”。 Towards the right, it shows the size of the file or directory in bytes and the date it was last modified, with the name at the far right.在右侧,它显示文件或目录的大小(以字节为单位)和上次修改的日期,名称位于最右侧。

My working directory contains only directories, no files.我的工作目录只包含目录,没有文件。

2. Getting Help 2.获得帮助

There are three ways of getting help that I recommend: --help, Google, and man.我建议有三种获得帮助的方法: - help,Google和man。

If you want a brief summary of command options, execute the command followed by "--help".如果需要命令选项的简短摘要,请执行命令后跟“--help”。 Execute this command:执行以下命令:

ls --help ls --help
A "brief" help page appear, as shown below.将出现一个“简短”帮助页面,如下所示。

Even that "brief" page contains far more information than I usually want to see.即使是那个“简短”的页面也包含了比我通常想要看到的信息更多的信息。 Most of those arguments are obscure and I never use them.大多数这些论点都很模糊,我从不使用它们。 My main source of help is actually Google.我的主要帮助来源实际上是谷歌。

Ooen a Web browser and go to google.com. Ooen是一个Web浏览器,然后去google.com。 Then search for然后搜索

linux ls examples linux ls的例子

You get a lot of really useful information, as shown below.您将获得许多非常有用的信息,如下所示。

Go to this page and skim through the options to see some more ways to use "ls".转到此页面并浏览选项以查看更多使用“ls”的方法。

http://linoxide.com/linux-command/linux-ls-command/ http://linoxide.com/linux-command/linux-ls-command/

Execute this command:执行以下命令:

man ls男人ls
This shows you a long, technical, and very confusing manual page about "ls" as shown below.这将向您展示一个关于“ls”的冗长,技术性且非常令人困惑的手册页,如下所示。 This type of help is almost completely useless for beginners--it provides far too much information.对于初学者来说,这种类型的帮助几乎完全没用 - 它提供了太多的信息。

Press q to exit man.q退出man。

3. Editing Files 3.编辑文件

Execute this command:执行以下命令:
nano file1纳米文件1
Nano opens, as shown below. Nano打开,如下所示。 Nano is a very simple text editor, like Notepad without the mouse. Nano是一个非常简单的文本编辑器,如没有鼠标的记事本。 Type in some text.输入一些文字。

Notice the bottom of the nano screen--the available commands are shown here in a shorthand form.请注意纳米屏幕的底部 - 可用命令以简写形式显示在此处。

Notice the lower left entry "^X Exit".注意左下方的条目“^ X退出”。 This means that you can exit nano by pressing Ctrl+X .这意味着您可以通过按Ctrl + X退出nano。 Press it now.现在按它。

The next screen asks if you want to save the file.下一个屏幕将询问您是否要保存文件。 The bottom shows your options: Y, N, or Ctrl+C.底部显示您的选项:Y,N或Ctrl + C. Type Y .输入Y.

At this screen, you can press Enter to save the file, or edit the name before saving it.在此屏幕上,您可以按Enter保存文件,或在保存之前编辑名称。 Unfortunately, the list of commands at the bottom don't tell you either of those facts.不幸的是,底部的命令列表并没有告诉你这些事实。

Press Enter .Enter键

To see what you've done, execute this command:要查看您已完成的操作,请执行以下命令:

ls -l ls -l
There's now an entry for "file1", as shown below.现在有一个“file1”条目,如下所示。

4. Changing Directories 4.更改目录

Execute this command, which stands for "print working directory":执行此命令,代表“打印工作目录”:
pwd PWD
The result is "/root", as shown below.结果是“/ root”,如下所示。 That's the directory we've been using.那是我们一直在使用的目录。

Execute these commands.执行这些命令。 The first one makes a new directory, and the second one lists out the contents of the current working directory.第一个创建一个新目录,第二个列出当前工作目录的内容。

mkdir proj0 mkdir proj0
ls -l ls -l
Now there's a directory named "proj0" in the working directory, as shown below.现在工作目录中有一个名为“proj0”的目录,如下所示。

Execute these commands.执行这些命令。 The first one moves file1 into the "proj0" directory, and the second one lists out the contents of the current working directory.第一个将file1移动到“proj0”目录,第二个列出当前工作目录的内容。

mv file1 proj0 mv file1 proj0
ls -l ls -l
"file1" no longer appears in the list, as shown below. “file1”不再出现在列表中,如下所示。

Execute these commands.执行这些命令。 The first one moves into the "proj0" directory, the second one shows the new working directory, and and the third one lists out the contents of the new current working directory.第一个进入“proj0”目录,第二个进入新工作目录,第三个进入新当前工作目录的内容。

cd proj0 cd proj0
pwd PWD
ls -l ls -l
This directory contains only one file, as shown below.该目录只包含一个文件,如下所示。

5. Output Redirection 5.输出重定向

Execute these commands.执行这些命令。 The first one prints the current date.第一个打印当前日期。 The second one sends the date to a file named "file2".第二个将日期发送到名为“file2”的文件。 The third one shows the long list of the current working directory.第三个显示当前工作目录的长列表。
date日期
date > file2日期> file2
ls -l ls -l
There's now a file named "file2", as shown below.现在有一个名为“file2”的文件,如下所示。

Execute this command to open "file2" in nano.执行此命令以打开nano中的“file2”。

nano file2纳米文件2
The file contains the date, as shown below.该文件包含日期,如下所示。

Press Ctrl+X to exit nano.Ctrl + X退出nano。

6. Displaying and Searching File Contents 6.显示和搜索文件内容

To see the contents of a file, use cat .要查看文件的内容,请使用cat

Execute these commands to display the contents of file1 and count .执行这些命令以显示file1count的内容。

cat file1猫文件1
cat count猫数
The contents appear, as shown below.内容显示,如下所示。

To search for a string in a file, use grep .要在文件中搜索字符串,请使用grep

Execute these commands to display the lines in the file1 containing the string ab , and the lines in the file1 containing the string ab ,执行这些命令以显示包含字符串abfile1中的行,以及包含字符串abfile1中的行,

grep ab file1 grep ab file1
grep a file1 grep一个文件1
The matching lines appear, as shown below.出现匹配的行,如下所示。

You can use the -r switch to search directories and subdirectories recursively.您可以使用-r开关以递归方式搜索目录和子目录。

Execute this command find all lines containing a in the current directory and all subdirectories.执行此命令查找当前目录和所有子目录中包含a的所有行。

Don't omit the period at the end--that's called "dot" and it denotes the current working directory.不要省略末尾的句点 - 称为“点”,它表示当前的工作目录。

grep a -r . grep a -r。
All matching lines in all files are found, as shown below.找到所有文件中的所有匹配行,如下所示。

7. Shell Scripting 7. Shell Scripting

Execute this command to open nano and start creating a file named "count".执行此命令打开nano并开始创建名为“count”的文件。
nano count纳米计数
Enter this text, as shown below.输入此文本,如下所示。
#!/bin/bash #!/斌/庆典

for i in 1 2 3因为我在1 2 3
do
echo $i回声$ i
done DONE

Press Ctrl+X , Y , Enter to save the file.Ctrl + XYEnter保存文件。

This script should count from one to three.这个脚本应该从一到三。 Execute this command to run the script:执行此命令以运行脚本:

./count 。/计数
An error message appears, saying "Permission denied", as shown below.出现错误消息,说“权限被拒绝”,如下所示。

To see why this happened, execute this command:要查看发生这种情况的原因,请执行以下命

ls -l ls -l
Notice the beginning of the line containing "count" as shown below.注意包含“count”的行的开头,如下所示。

This line starts with "-", indicating that this is a file, not a directory.该行以“ - ”开头,表示这是一个文件,而不是目录。 The next 9 letters are the permission string , using these letters:接下来的9个字母是权限字符串 ,使用这些字母:

The current permission string doesn't contain any "x" characters, so no one has permission to execute it.当前权限字符串不包含任何“x”字符,因此没有人有权执行它。

Execute these commands to give execute permission to the "count" file for all users, and to see the new permissions:执行这些命令为所有用户的“count”文件赋予执行权限,并查看新权限:

chmod a+x count chmod a + x count
ls -l ls -l
As shown below, the file now has three "x" permissions, and the name turns green, to indicate that this is an executable file.如下所示,该文件现在具有三个“x”权限,名称变为绿色,表示这是一个可执行文件。

Execute this command to run the "count" script:执行此命令以运行“count”脚本:

./count 。/计数
As shown below, the script runs, counting from 1 to 3.如下所示,脚本运行,从1到3计数。

8. Networking 8.网络

Execute this command to see what network adapters you have and your IP address:执行此命令以查看您拥有的网络适配器和IP地址:
ifconfig使用ifconfig
As shown below, there are two adapters:如下图所示,有两个适配器:

eth0 has an IP address (labelled "inet") and goes to the Internet. eth0有一个IP地址(标记为“inet”)并进入Internet。

lo is the loopback address and doesn't go anywhere. lo是环回地址,不会去任何地方。 Your computer uses that address to talk to itself, which is useless for normal Web browsing.您的计算机使用该地址与自己通信,这对于正常的Web浏览来说是无用的。

Execute this command test your Internet connection:执行此命令测试您的Internet连接:

ping google.com ping google.com
As shown below, you should see "reply" messages, indicating that your Internet connection is working.如下所示,您应该看到“回复”消息,表明您的Internet连接正在运行。

Press Ctrl+C to stop the pings.Ctrl + C可停止ping。

If you move your computer to a new network, it might lose connectivity because it's still using an old IP address.如果将计算机移动到新网络,则可能会丢失连接,因为它仍在使用旧的IP地址。

To fix that problem, execute this command:要解决该问题,请执行以下命令:

dhclient -v eth0 dhclient -v eth0
As shown below, your computer sends out DHCPDISCOVER messages, and gets an IP address from the router.如下所示,您的计算机发送DHCPDISCOVER消息,并从路由器获取IP地址。


ED 101.1: Using Directories (5 pts) ED 101.1:使用目录(5分)

Execute these commands:执行以下命令:
cd /tmp cd / tmp
mkdir apple mkdir apple
mkdir baker mkdir面包师
cd baker cd面包师
mkdir charlie mkdir查理
Find your current working directory.找到您当前的工作目录。 That's the flag.那是旗帜。


ED 101.2: Network Test (10 pts) ED 101.2:网络测试(10分)

The file /tmp/pinger contains these two lines:文件/ tmp / pinger包含以下两行:

However, the script will not run:但是,脚本不会运行:

What command will fix this problem?什么命令可以解决这个问题? That command is the flag.那个命令就是旗帜。


ED 101.3: Network Problem (10 pts) ED 101.3:网络问题(10分)

This machine can't ping google.这台机器无法ping谷歌。

What command should be executed to fix the problem?应该执行什么命令来解决问题?


Posted 6-13-18发表于6-13-18
Challenges 3 and 4 added 6-14-18挑战3和4增加了6-14-18