|
发表于 2003-12-14 18:04:33
|
显示全部楼层
bash-2.05$ cp -rfv foo1/ file2.txt tmp/ <ENTER>
bash-2.05$ cp -rf /cdrom/* ~/ <ENTER>
The `-r' means "recursive", so `file2.txt', the `foo1' directory, and all the contents of `foo1' are copied to the `tmp' directory. The `-f' means "force", I have a habit of forcing things. The `-v' means "verbose", It will show you on the screen what files are being copied. In the second example, we have this `~/', which is a short cut representing your home directory. So that command would copy the contents of `/cdrom' to your home directory.(Note:_The asterik symbol '*' is called a wildcard character which means "anything"_.)
'-r'意思是”recursive循环”这样'file2.txt','fool'目录和'fool'的所有内容都复制到'tmp'目录.'-f'意思是”force强制”,我有一个强制执行的习惯.'-v'意思是”verbose详述”,它会在屏幕上显示什么文件正在被复制.在第二个例子中,我们有这个东西'~/'一个代表你的home目录的快捷方式.这样命令会复制'/cdrom'的所内容到你的home目录.(注意:_符号'*'叫做通配符,意思是”任何东西”_)
To rename or move a file or directory you would use the `mv' (move) command. Be careful, because `mv' is a very powerful command. You can lose data if you're not careful about what you do. To rename a file or directory you would type, for example:
要重命名和移动一个文件或者目录你会用到'mv'(move移动)命令.小心,因为'mv'是一个功能非常强大的命令.你如果对你做的事情不在意的话你会丢失你的数据.要重命名一个文件或者目录你会输入,例如:
bash-2.05$ mv foo1/ foo2 <ENTER>
Now you no longer have a `foo1' directory, it's called `foo2' now. The same thing can be done with plain files, too.
现在你不再有一个'fool'目录了,他现在叫做'foo2'.同样的事情可以对无格式的文件进行操作.
I'll bet you're saying, "I'm doing all this work, but how do I view my directories?" You answer would be the `ls' (list)command. The `ls' command also has many options.
我打赌你在说,”我在做所有的工作,但是我怎么查看我的目录呢?”你的答案会是'ls'(list)命令.'ls'命令也有许多选项.
bash-2.05$ ls -al <ENTER>
The two options I have here are used more often than any others. The `-a' will show us all hidden files in the current directory.(3) The `-l' option tells us to display the directory in long format. This means it shows us the date modified, file size, file attributes, etc. of all files.
这里我给的两个选项比任何别的选项使用的更频繁.'-a'会显示所有当前目录(3)下的隐藏文件.'-l'选项告诉我们以长格式显示目录.这意味着它显示数据的修改,文件大小,文件属性,所有的文件.
A user will also notice that there are files with dots in front of some files in thier home directory. The dotted files are typically hidden configuration files. The user will also notice a dot, followed by two dots. In the unix file system a dot represents the current directory. The two dots represent the directory above your current working directory. Examples of using these dots are common in building software.
用户也会注意到在他们的home目录下有一些前面带着点号的文件.这些带点号的文件是典型的隐藏的配置文件.用户也会注意到一个点号,跟着是两个点号.在unix文件系统里一个点号代表当前目录.两个点代表你当前目录的上一层目录.使用这些点号的例子常见于编译文件时.
bash-2.05# ../configure # This runs configure from the directory above.
bash-2.05# ./program # This runs program from current directory.
Now that you have made all this mess in your home directory, I'll bet you're wondering how you can get rid of things. There are two important deleting commands. The `rm' (remove) command is convienent for removing files. `rm' command can also remove directorys that the `rmdir' command can't. I'll show the you a basic `rm' example, then my favorite with the extra options. The `rmdir' command will only delete directories that are empty.
既然你已经把你的home目录给搞乱了,我会打赌你想知道如何处理他们.有两个重要的删除命令.'rm'(删除)命令适合删除文件'rm'命令也可以删除那些'rmdir'命令无法删除的目录我会展示一个基本的'rm'命令的例子,然后我会加上一些额外的选项.'rmdir'命令会仅仅删除空的目录.
bash-2.05$ rm README <ENTER>
Now, `rm' with some options:
现在,'rm'跟着一些选项:
bash-2.05$ rm -rf foo2/ <ENTER>
The second example is very powerful. The `-r' means "recursive" and the -f means "force." This removes all the contents of `foo2', without prompting the user for confirmation.
第二个例子功能十分强大.'-r'意思是”recursive循环”而-f意思是”force强制”这会移除'foo2'的所有内容,而不提示用户确认.
These are only the basic commands to get you started... there are many, many two- and three-letter commands. The more you use GNU/Hurd, the more options and commands you'll learn. The more you learn, the more freedom you'll have.And that is a very valuable thing.
这些仅仅是你开始的基本命令...还有很多很多的两个和三个字母的命令.你使用GNU/Hurd越多,你学到的命令和选项就会越多.你学的越多,你就会有更多的自由.(享受自由的能力提高了).这是非常有价值的事情.
Now that you have been cruising around your filesystem, you might be wondering how much space you have left on your drive. There is a simple command to check this:
既然你已经漫游了一遍你的文件系统.一可能会想知道你的磁盘还有多大的空间.这里有简单的命令来做这个检查:
bash-2.05$ df / <ENTER>
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hd0s1 1920748 1203996 619180 67% /
If you don't put a directory after the command such as `/' or `/home', the `df' (diskfree) command will spit out some errors.
如果你把像'/'或者'/home'的目录放到命令后,'df'(diskfree磁盘空余)命令会弹出一些错误.
If your prompt is not telling you what directory you are in, you can use the `pwd' (present working directory) command:
如果你的提示符不告诉你当前正在的目录,你可以使用'pwd'(present working directory当前工作目录)命令:
bash-2.05$ pwd <ENTER>
/usr/src
As a final note, always remember: _`info' is your friend on GNU/Hurd._
作为最后的笔记,时时记住._'info'在你的GNU/Hurd是你的朋友.
---------- Footnotes ----------
脚注
(1) This is a pun on the name of the original Unix shell, the Bourne shell, and the Christian idea of being "born again".
(1)这是一个关于初始的Unix shell的双关语, the Bourne shell,和基督教的意思”重生”
(2) An abbreviation for _concatenate_, since `cat' can be used to concatenate files.
(2)_concatenate_连接的另一个缩写,因为'cat'可以用来连接文件
(3) Important files are often hidden, to prevent the user from accidentally deleting them.
(3)重要的文件常常隐藏,防止用户不小心删了它们.
Standard Input and Output
=========================
标准输入输出
Computers borrow many concepts from mathematics. One very important concept that will be familiar to those with a background in programming is the idea of a _function_. Informally, the term _function_ encapsulates the following idea:
计算机从数学中带来了许多的概念.其中一个非常重要的对于那些有编程背景的人来说熟悉的概念是_function_(函数),通常来说,术语_function_封装了以下的思想:
*When you put something in, you get something out.*
*当你放一些东西进去的时候,你会从里面拿出一些东西来*
Let's look at some examples of functions:
让我们看一些函数的例子:
1. In math classes, students draw graphs of functions, such as y =
x^2. In this case, you put in x, and you get x^2; for example,
if you put in 3, you get 9.
1.在数学课上,学生们画函数的图像,像y=x^2.这样,你放进去x,得到了x^2;例如,如果你放进去3,你得到9.
2. A drink machine: you input a quantity of money and a drink
selection, and the machine outputs a drink and your change.
2.一个饮料机:你放入一定数量的钱和一个饮料的选择,机器输出饮料和你的零钱.
3. Programming functions, such as _C_'s `isdigit()': you give it a
character, and it returns 1 if the character is a digit, and 0
otherwise.
3.程序的函数,像_C_的'isdigit()':你给它一个字符,它返回1如果字符是数字;不是的话返回0.
There are many more examples of functions. Notice from our examples that a function may have multiple inputs an outputs; however, a function must always produce the same output for any given set of inputs. It would not do for a drink machine to sometimes give root beer when asked for iced tea!
还有许许多多的函数的例子.注意我们的例子里一个函数可以有多个输入和输出;然而,一个函数必须常常对给出的任何一组输入产生一样的结果.不可能让机器某些时候根用户要一瓶冰红茶的时候给他一瓶啤酒.
In GNU systems and other systems that follow the UNIX tradition, programs are functions. Every program in a GNU system has a "standard input" and a "standard output".
在GNU系统和别的跟随UNIX传统的系统,程序就是很多函数.一个GNU系统里的每一个程序有一个标准输入和标准输出.
By default, a program's standard input comes from the command line, and its output goes to the terminal. For example:
缺省的,一个程序的标准输入从命令行来,而它的输出到终端去.例如:
$ echo "Echo prints whatever you type."
Echo prints whatever you type.
We may "redirect" a program's standard output using the <>> key:
我们可以使用>”重定向”一个程序的标准输出:
$ echo "Here's a quick way to write one-line files." > quickie.txt
$ ls
quickie.txt
$ cat quickie.txt
Here's a quick way to write one-line files.
$ ls quickie.txt > dir.txt
$ ls
quickie.txt dir.txt
$ cat dir.txt
quickie.txt
Similarly, we can use the <<> key to redirect a program's standard input:
类似的,我们可以使用<键重定向一个程序的标准输入:
$ cat < dir.txt
quickie.txt
We can use <>> and <<> together:
我们可以一起使用>和<.
$ cat < dir.txt > copy.txt
$ cat copy.txt
quickie.txt
Another property of functions that is useful to us is _composition_: we can make the output of one function the input of another. When we use <|>, the pipe symbol, we are composing two functions; see *Note The Shell::. For example, we can pipe the output of the `info' program into `less', and scroll through a page:
另一个实用的函数属性是_composition_(组合):我们可以使得一个函数的输出作为另一个函数的输入.当我们使用<|>,管道符号时我们在组合两个函数;另见*注意The Shell::.例如,我们可以把'info'程序的输出输到'less',并且通过页面来滚动:
$ info gcc | less
Understanding standard input and output, redirection, and pipes is fundamental to intermediate and advanced use of the GNU command shell. Keep this section in mind while reading the rest of this manual.
懂得标准输入输出,重定向,和管道对于GNU命令shell的中高就应用是基础.阅读这个手册的剩余的部分紧紧记住这一节.
Searching your Computer
=======================
搜索你的计算机
Your computer is full of files. Some of these files are your personal files; others, such as `/etc/passwd', are used by the system. You may often want to find certain files on your computer, or find specific information in one or more files. This searching could be done manually through many invocations of `cd', `ls', and `less'; however, repetitive tasks such as searching are the sort of jobs for which computers were invented, and your GNU system has several tools to make searching easier.
你的计算机满是文件.这些文件的一些是你的个人文件;别的,像'/etc/passwd',是由系统使用的.你也许经常想要查找你计算机上特定的文件,或者在一个或者多个文件里的特定信息.这个搜索可以人工的通过许多对'cd','ls'和'less'的援用来完成.然而,重复的任务如这样的搜索是计算机发明来做的一种工作,你的GNU系统有许多这样的工具使搜索变得容易.
The executables on your system are easy to find; simply use the `which' command:
可执行文件在你的机器很容易找到;只是简简单单的使用'which'命令:
$ which ls
/usr/bin/ls
The `which' command is especially useful when you have multiple copies of a program, each at a different location in your filesystem, since it allows you to find out which is executed by default. For example, if I install one version of Mozilla using Debian's `apt-get' command, and another version by downloading the source from `http://www.mozilla.org' and compiling it, I can type `which mozilla' to find out which is executed by default.
'which'命令在你有许多同一程序的copies,每一个在你的文件系统的不同位置的时候尤其有用,因为它允许你查找哪一个可执行程序是缺省的.例如,如果我用Debian的'apt-get'命令安装了一个版本的Mozilla,另外一个版本是通过从 `http://www.mozilla.org' 现在源代码和编译它得到的,我可以输入'which mozilla'来找出哪一个缺省执行.
Your GNU system's more general searching tools are:
你的GNU系统更通用的搜索工具有这些:
* `locate'
* `find'
* `grep'
* `xargs' |
|