已翻译20140702 Command Line Tuesdays--Part Three.md by Luoxcat

This commit is contained in:
Luoxcat
2014-07-14 20:58:13 +08:00
parent ce9b00c33d
commit c356539e6b
2 changed files with 85 additions and 84 deletions

View File

@@ -1,84 +0,0 @@
暑假 先来一发 Luoxcat 翻译
Command Line Tuesdays Part Three
================================================================================
Today, mr Shotts takes us on a first part of a guided tour through our file system. Well learn how to visit, list files within directories and well learn to use some options for the first time. So lets begin with the first command of the week.
### ls ###
ls is a command used to list files in a directory. It can be used in various ways. These various ways come with using a form of adding an **option** to our command. To make things clearer; You can type only ls. But, you can also add an option, which will modify your command. It can come in useful when you want to sandbox some of the information, when looking for something specific, and the command issues a very long output, you can, for example, narrow it down to only specific information.
Thats what an option is. And formally we can write it down like this:
command -option argument
Command is, well, a command we write in (like pwd, ls or anything else we have learned by now).
We already stated above the purpose of an option. But let me note it should be written exactly as its in the form; With a dash in front of it. So, if the option is l, you should put **-l** after the command.
An **argument** is an object upon which the command operates (in this case, it will be directories, as well learning how to navigate through them).
So, lets try out ls, and use it on the /etc directory in our home folder. This time, without any options.
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-184127.png)
There you go, a whole bunch of files. It also sorts them by colours. The blue ones are directories, the white ones are files, the green one seems like a shell script of some sort. There are more colors, as they represent different file types.
Next, you can use the same command, but with an option -l added. Option -l will list the same files and directories, but in a long format. In case you need more information:
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-184542.png)
### The Long Format ###
So, using the long format, you see much more information, and some crazy looking signs like -rw-rr at the beginning of all lines. Actually, heres a scheme, representing what all of the given information actually means.
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-184829.png)
File Name is the name of the file. Modification time is the last time the file has been modified. Size is the size of the file in bytes. Group is the name of the group that has file permissions along with the owner, and Owner is the user who owns the file. The most important one is…
### …File Permissions ###
Thats the gibberish at the beginning of every line in long format. The first character is the file type. If its a d, it means the files a directory. If its -, it means its an ordinary file. The next three characters represent the read, write and execution rights of the files owner. The next three are the same rights of the group that also has access to the file, and the last three characters represent rights of everyone else trying to use the file.
So for example, if we have a file which in long format displays: -rw-rr, it means its an ordinary file (the first -), the owner of the file can read and write the file, but he cant execute it, as its not an executable file (the rw- characters after the initial -), and the user group and everyone else can only read the file (you can see r sequence repeating twice. If the user group had rwx instead of r, it would mean they could read, write and execute the file).
Next option for ls is ls -la .. this will list all of the files, as in a usual command, hidden files are not shown. It will list all files in the parent of the working directory in long format.
### less ###
Less is a command which will display your text file. For example, youre looking for text file os-release in /etc. You have succesfully found it there with ls /etc, and now you want to read it.
You just use less /etc/os-release.
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-190252.png)
..and there you go.
How do you control less?
Easy, with your keyboard!
less will display only one page of your text at a time. To go forward one page, you can press **Page Up, or b**. To go back one page, you can use **Page Down, or space**. Capital **G** will take you to the end of the text file, while **1G** will take you to the beginning of the text. **/characters** will search for characters inside the text (for example, if you write /suse, it will search for occurances of suse inside your text and mark them). n will repeat the last search you performed, and **h** will display all your options (h, as in haalp!).
![](https://news.opensuse.org/wp-content/uploads/2014/06/halp.jpg)
You quit less with the letter q.
### file ###
The file command will show what kind of file is that youre looking for, be it ASCII text, a jpg image, a bash script etc. As we performed our exercise with /etc/os-release, lets use it here also.
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-191402.png)
There you go, os-release is an ASCII text file. Please, do try it out with something else, and see the output.
And until next time, remember to…
…have a lot of fun!
--------------------------------------------------------------------------------
via: https://news.opensuse.org/2014/07/01/command-line-tuesdays-part-three/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出

View File

@@ -0,0 +1,85 @@
暑假 先来一发 Luoxcat 翻译
命令行星期二 - 第三篇
================================================================================
今天Shotts 将带领我们游历文件系统的第一部分。我们将学到如何访问列出目录内的文件以及首次介绍一些选项的运用。OK,让我们开始学习这周的第一个命令。
### ls ###
ls 是一个用来列出目录内文件的命令。通过添加**选项**来实现多种不同的用途。当然为了得心应手,你可以只需键入 ls 。但是,你也可以添加一个选项后,它会帮助你修饰你的命令。如果你想要"沙盒"一些信息时,这会帮到你的。举例来说,当你要从一个命令的大量输出中找寻指定信息,你可以用选项缩小范围来实现。
这就是选项的基础概念。我们可以用下面书写格式表示:
command(命令) -option(选项) argument(参数)
命令,恩...,我们可以输入 pwd, ls, 或者是我们到目前为止所有学过的命令。
以上我们已经阐述了选项的目的。但是我们需要注意一下书写格式:在前头添加一个破折号。所以,如果选项为 l, 你需要在命令后键入**-l**。
**参数**是一个命令的操作对象(在这个例子中,它是一个目录,我们将会学到如何浏览它们)。
接着,让我们尝试在主目录里尝试用 ls 命令列出 /etc 目录内容。这次我们先不添加选项。
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-184127.png)
就这样,列出了一大堆的文件。它们还根据颜色进行了分类。蓝色的是目录,白色的为普通文件,绿色的似乎是一个 shell 脚本文件。除此之外,还有其他不同的颜色来代表不同的文件类型。
接下来,你可以在刚才的命令里添加 -l 选项。添加选项 -l 后也会列出同样的文件和目录,但是会有长格式(the long format)的输出。如果你需要查看更多信息的话,这个选项将是不错的选择。
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-184542.png)
### 长格式 ###
所以,用了长格式后,你可以看到更详细的信息,以及在每行开头类似-rw-r--r-- 令人抓狂的标示。实际上,这只是一种组合,代替了所有有意义的信息。
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-184829.png)
(File Name)就是文件的名称。Modification time是文件最后修改的时间。(Size) 用 byte 计量的文件大小。(Group) 是组的名称和拥有者一起形成文件权限。(Owner) 是文件拥有者的名称。最最重要的。。。
### 。。。文件权限 ###
文件权限在长格式每一行的开端都显得非常的杂乱。第一个字符代表文件类型。如果是 'd' , 意味着它是一个目录。如果是 '-' , 意味着它是一个一般文件。接下来的三个字符分别代表拥有者的 可读, 可写 ,可执行的权限。再接着三个字符表示组成员的享有的文件权限,而最后三个字符表示其他人对文件的享有权限。
例如,如果有个文件在长格式下显示为:-rw-r--r--, 这说明这是个普通文件(首字符 '-'), 拥有者享有可读可写权限,但是没有可执行权限,导致拥有者无法执行该文件(首字符'-'后'rw-'),用户组和其他用户只享有可读权限(你不难发现r--'字段在后面出现了两次 。如果用户组是 'rwx' 而不是 'r-', 则意味着它们可读,可写,可执行文件)。
ls 的下个选项是 ls -la .. -a 它会列出所用文件包括隐藏文件,在通常情况下,隐藏文件是不可见的。用长格式列出当前工作目录下的父目录的所有文件。
### less ###
less 是一个可以显示你的文本文件的命令。举例来说,你要在 /etc 下找寻名为 os-release 的文本文件。你可以使用 ls /etc 成功实现,而现在你想要阅读它。
你只需要使用 less /etc/os-release。
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-190252.png)
..就这样了。
你要如何控制 less 呢?
简单的, 你只需要动动键盘就行了!
less 一次只会显示一个页面的文本。往页面之前你需要按 **Page Up, 或者 'b'**。往页面之后你可以按**Page Don, 或者 space**。大写的**G**会跳转到文本的末尾,**1G**会跳转到文本的开端。**/字符**会在文本内搜索指定字符(例如,如果你输入 /suse ,它会找寻所有文本含有的 suse 并标记出来)。n 会重复执行你的搜索,**h**会显示所有的选项(h,haalp!)。
译注haalp !不懂求解释
![](https://news.opensuse.org/wp-content/uploads/2014/06/halp.jpg)
按q退出 less 命令。
### file ###
file 会显示文件的类型,是否是你要找的 ASCII 文本,还是 jpg 图片bash 脚本等。让我们用 /etc/os-release 执行练习。
![](https://news.opensuse.org/wp-content/uploads/2014/06/Screenshot-30.-06.-2014-191402.png)
就这样os-release 是一个 ASCII 文本文件。 请尝试其他文件,并观察结果。
下回见了,记住。。。
。。。一定要玩的开心啊!
--------------------------------------------------------------------------------
via: https://news.opensuse.org/2014/07/01/command-line-tuesdays-part-three/
译者:[Luoxcat](https://github.com/Luoxcat) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出