“UbuntuHelp:UsingTheTerminal/zh”的版本间的差异
来自Ubuntu中文
Dbzhang800(讨论 | 贡献) 小 |
Dbzhang800(讨论 | 贡献) 小 |
||
第3行: | 第3行: | ||
{{From|https://help.ubuntu.com/community/UsingTheTerminal}} | {{From|https://help.ubuntu.com/community/UsingTheTerminal}} | ||
− | {{Translator|convice | + | {{Translator|convice}} |
− | === | + | {{Languages|UbuntuHelp:UsingTheTerminal}} |
+ | |||
+ | === 为什么使用终端?=== | ||
''"Linux下面有多种GUIs(图形用户界面),可以在其下点击鼠标,拖拽,能够很好的工作却不需要一次读很多文档.而传统的Unix环境是 CLI(命令行界面),即在命令行下键入命令,执行想要的操作。相比之下,这种方式执行起来更快,功能也更强,不足之处是用户需要了解相关操作的命令。" --摘自 '''man intro(1)''''' 在做某些任务,特别是系统配置等任务时使用终端是很有意义的,或许在帮助页或 [http://www.ubuntuforums.org 论坛]中你已经看到过类似这样的指令: | ''"Linux下面有多种GUIs(图形用户界面),可以在其下点击鼠标,拖拽,能够很好的工作却不需要一次读很多文档.而传统的Unix环境是 CLI(命令行界面),即在命令行下键入命令,执行想要的操作。相比之下,这种方式执行起来更快,功能也更强,不足之处是用户需要了解相关操作的命令。" --摘自 '''man intro(1)''''' 在做某些任务,特别是系统配置等任务时使用终端是很有意义的,或许在帮助页或 [http://www.ubuntuforums.org 论坛]中你已经看到过类似这样的指令: | ||
第16行: | 第18行: | ||
* Different ways to open a terminal, how to work with multiple terminals, etc. | * Different ways to open a terminal, how to work with multiple terminals, etc. | ||
− | === | + | === 使用本页 === |
− | * | + | * 本文将指导您熟练掌握基本的 GNU/Linux shell 命令。 |
− | * | + | * 本文并不是命令行的完整教程,仅仅是对 Ubuntu图形界面工具的补充。 |
− | * | + | * 所有命令都用黑体'''标明。 ''' |
− | * | + | * 需要键入的命令用“引用黑体”'''标明。 ''' |
− | * | + | * 本文的所有命令都要在终端下执行。 |
− | * ''' | + | * 注意:Linux是大小写敏感的。'''User,user,USER在Linux是不同的。 ''' |
− | === | + | === 启动终端 === |
− | ==== | + | ==== 在 Gnome (Ubuntu) 中 ==== |
The terminal can be found at '''Applications menu''' -> '''Accessories''' -> '''Terminal'''. | The terminal can be found at '''Applications menu''' -> '''Accessories''' -> '''Terminal'''. | ||
− | ==== | + | ==== 在 Xfce (Xubuntu) 中==== |
The terminal can be found at '''Applications menu''' -> '''System''' -> '''Terminal'''. | The terminal can be found at '''Applications menu''' -> '''System''' -> '''Terminal'''. | ||
− | ==== | + | ==== 在 KDE (Kubuntu) 中 ==== |
The terminal can be found at '''KMenu''' -> '''System''' -> '''Terminal Program (Konsole)'''. | The terminal can be found at '''KMenu''' -> '''System''' -> '''Terminal Program (Konsole)'''. | ||
− | === | + | === 命令行 === |
− | ==== sudo: | + | ==== sudo:需要提升权限执行的命令 ==== |
− | * | + | * 如果您所在的目录或想操作的文件不在您的帐户所在的目录,下面的大多数命令都需要使用 '''sudo '''命令。这是一个特殊的命令,它给你临时的权限来修改系统设置。终端会询问你的密码。sudo 使用详情请参阅[[UbuntuHelp:RootSudo|RootSudo]] |
− | |||
− | + | ==== 文件 & 目录类命令 ==== | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | * '''pwd:''' '''pwd''' 命令查看您当前所处的路径('''pwd''' 代表 "打印当前工作目录")。例如:在桌面文件夹中执行 "pwd" 命令将输出 "~/Desktop"。注意,Gnome 的终端在窗口标题中也会显示这一信息-具体请看本页顶部的截屏图片'''。 ''' | |
− | + | ** '''"cd ~/Desktop"''' will move you to your desktop directory.<br>'''cd: cd''' 命令用来改变当前工作目录。当您打开一个终端的时候,您就位于您的home目录中。如果想要切换到其它的目录,就要用 cd 命令。例如: '''"cd ~/Desktop"'''将会进入到您的桌面目录。''' ''' | |
− | * ''' | + | *** 进入root目录,输入 '''"cd /" ''' |
− | * ''' | + | *** 进入到您自己的目录,输入 '''"cd" ''' |
− | + | *** 进入当前目录的上一次目录,输入 '''"cd .." '''/* 译者注:cd 与 .. 之间有空格 */''' ''' | |
− | + | *** 进入前一个操作的目录,输入 '''"cd -" ''' | |
− | + | *** 一次进入多层目录,输入 '''"cd /var/www" ''',将会直接切换到/var的子目录/www中。''' ''' | |
− | + | * '''cp: cp''' 命令用来复制文件。例如: '''"cp file foo" '''命令将会创建一个"file"的精确的副本,并命名为"foo",而 "file"''' '''不会有任何变化。当您用 mv 命令的时候,原始的文件将不在保留,而 cp 会保留原始的文件并创建一个新的副本。 | |
− | + | * '''mv: mv''' 命令将文件移动到另一个位置或者给文件更名。看下面的例子: '''"mv file foo"'''命令会将文件"file"更名为"foo"。'''"mv foo ~/Desktop"'''会将文件"foo"移动到桌面目录,但不会更名。如果想更名,你必须要指定一个新的名字。''' ''' | |
− | + | ** 为了输入方便,您可以用'''"~"'''符号来代替您的home目录。 | |
− | * ''' | + | ** 注意:如果你在用 '''mv''' 命令的时候加了 '''sudo,'''您就不能用~了,而必须用文件的全局路径了。''' ''' |
− | * ''' | + | * '''rm'''''' :''' 这个命令用来移动或删除文件。对于非空的目录,用这个命令不能删除。''' ''' |
− | * ''' | + | * '''ls''': ls 命令列出当前目录下的文件(和目录)。使用特定的参数,您可以查看文件的大小,创建时间,权限等。例如:'''"ls ~"''' 会列出您的home目录中的文件(和目录)。''' ''' |
− | * ''' | + | * '''man: man''' 命令用来显示其它命令的手册页。执行 '''"man man"'''可以查看到 man自己的信息。通过 "'''Man''' & Getting Help"能够分页显示更多的信息。 |
− | * ''' | + | * '''mkdir:''' mkdir 命令用来创建目录。例如:'''"mkdir music"''' 将会创建一个 music 目录。''' ''' |
− | <pre>user@computer:~$ lsb_release -a | + | ==== 系统信息类命令 ==== |
+ | * '''df: df '''命令用来查看各个文件系统当前的空间使用状况。'''"df -h"'''可能是最有用的选项了-它以M和G为单位输出,而不是以块为单位。('''-h''' 的含义是“便于阅读”) | ||
+ | * '''free: free '''命令用来查看系统中使用和剩余的内存情况。'''"free -m"''' 将结果以M为单位输出,这对现在的计算机来说非常有用。 | ||
+ | * '''top: top''' 命令用来查看linux系统的信息,运行着的进程和系统资源,包括 CPU, RAM & swap使用情况和运行着的任务的总的数量。退出 top ,按''' "q"'''。 | ||
+ | * '''uname -a: uname '''命令的 '''-a''' 参数用来查看系统的所有信息,包括 机器名,内核名称 & 版本 和一些其它的细节。它最大的用处是用来查看当前所用内核的信息。 | ||
+ | * '''lsb_release -a: lsb_release '''命令的 '''-a''' 参数查看当前运行的linux的版本信息,例如:''' ''' | ||
+ | <pre><nowiki> | ||
+ | user@computer:~$ lsb_release -a | ||
No LSB modules are available. | No LSB modules are available. | ||
Distributor ID: Ubuntu | Distributor ID: Ubuntu | ||
− | Description: Ubuntu 6.06 LTS | + | Description: Ubuntu 6.06 LTS |
− | Release: 6.06 | + | Release: 6.06 |
− | Codename: dapper | + | Codename: dapper |
− | </pre> | + | </nowiki></pre> |
− | * '''ifconfig''' | + | * '''ifconfig '''显示当前系统的网络接口信息。''' ''' |
+ | |||
+ | ==== 添加新用户 ==== | ||
+ | |||
+ | * '''"adduser newuser"''' 命令用来创建一个用户名为"newuser"的新用户,为新用户 newuser 创建一个密码,使用如下命令''' "passwd newuser"'''。''' ''' | ||
+ | |||
+ | === 命令选项 === | ||
+ | |||
+ | 命令的默认操作常常会被指定一个确定的 '''--参数'''所修改。例如''' ls '''命令有一个''' -s '''参数,因此 '''"ls -s"'''就会额外的显示出文件的大小。它也有一个 '''-h'''参数,将文件的大小以很好的可读性的格式输出。 | ||
+ | |||
+ | 参数可以以簇聚合,比如 '''"ls -sh"'''和"'''ls -s -h"'''的效果相同。大多数的参数都很长,两个破折号前缀代表一个参数,所以'''"ls --size --human-readable"'''也和上面得命令相同。''' ''' | ||
+ | |||
+ | === "Man" 和 获得帮助 === | ||
+ | |||
+ | ''command'' --help'''和'''man ''command'''''是命令行下面最重要的两个工具。''' ''' | ||
− | + | 实际上所有的命令都有一个'''-h(or --help)'''参数,能够输出命令的简要的描述和参数,然后自动退出。可以输出'''"man -h"''' 或 '''"man --help"'''查看。''' ''' | |
− | + | 在linux下面,几乎每一个命令和每一个应用程序都会有一个man(manual)文件,所以只要简单的键入'''"man "command""'''就能看到这个命令的手册页。例如,'''"man mv"'''会打开mv的手册页。''' ''' | |
− | + | 利用键盘上的方向键移动手册页面,用'''"q"'''退出。''' ''' | |
− | + | '''"man man"''' 会查看''' man''' 命令的手册页,这里是一个很好的开始!''' ''' | |
− | + | '''"man intro"'''也非常有用 -它能够查看 "用户命令介绍",写的非常好!是一份很简介的linux命令的介绍。 | |
− | + | 还有一个就是'''info''' 命令了,它通常比'''man'''还深入。试试'''"info info"'''命令。''' ''' | |
− | ==== | + | ==== 搜索man文档 ==== |
− | + | 如果您不确定用哪个命令或程序,您可以试试搜索'''man'''文件。 | |
− | * '''man -k ''foo''''' | + | * '''man -k ''foo'''''会搜索关于foo的man文件。试试看'''"man -k nautilus"'''是怎样的。 |
− | * | + | ** 注意:这同'''apropos''' 命令是一样的。 |
− | * '''man -f ''foo''''' | + | * '''man -f ''foo'''''仅仅搜所系统man文件的标题。试试'''"man -f gnome"'''。 |
− | * | + | ** 这个同 '''whatis''' 命令是相同的。''' ''' |
=== Other Useful Things === | === Other Useful Things === | ||
第179行: | 第186行: | ||
You can also get it with a function key You can run more than one - in tabs or separate windows | You can also get it with a function key You can run more than one - in tabs or separate windows | ||
− | === | + | === 更多信息 === |
− | + | * [[UbuntuHelp:AptGetHowto/zh|apt-get 使用指南]] - 用apt-get在命令行下安装软件包 | |
− | * [[UbuntuHelp:AptGetHowto| | + | * [[UbuntuHelp:Repositories/CommandLine|Commandline Repository Editing]] - 在命令行下添加 Universe/Multiverse 软件库。 |
− | * [[UbuntuHelp:Repositories/CommandLine|Commandline Repository Editing]] - | + | * [[UbuntuHelp:grep/zh|grep Howto]] - grep 是一个非常强大的命令行下的搜索工具。 |
− | * [[UbuntuHelp: | + | * [[UbuntuHelp:CommandlineHowto]] - 比本文要长,也要完整很多的基础命令指南,至今为止,仍未完成。 |
− | * [[UbuntuHelp: | + | * [[UbuntuHelp:HowToReadline]] - 针对命令行的更高级定制的信息。 |
− | + | ||
− | * [[UbuntuHelp: | + | |
− | + | 关于Linux命令行的更详细指南,请参阅: | |
− | * http://linuxcommand.org/ - | + | * http://linuxcommand.org/ - 基础 BASH 指南,包括 BASH 脚本。 |
− | * http://linuxsurvival.com/index.php - | + | * http://linuxsurvival.com/index.php - java基础指南 |
− | * http://rute.2038bug.com/index.html.gz - | + | * http://rute.2038bug.com/index.html.gz - 系统管理相关的大量文档,几乎全部使用命令行。 |
---- | ---- |
2008年4月14日 (一) 14:00的版本
点击翻译: |
English • 中文 |
目录
为什么使用终端?
"Linux下面有多种GUIs(图形用户界面),可以在其下点击鼠标,拖拽,能够很好的工作却不需要一次读很多文档.而传统的Unix环境是 CLI(命令行界面),即在命令行下键入命令,执行想要的操作。相比之下,这种方式执行起来更快,功能也更强,不足之处是用户需要了解相关操作的命令。" --摘自 man intro(1) 在做某些任务,特别是系统配置等任务时使用终端是很有意义的,或许在帮助页或 论坛中你已经看到过类似这样的指令:
sudo gobbledegook blah_blah -w -t -f aWkward/ComBinationOf/mixedCase/underscores_strokes/and.dots
It's normally assumed that you know how to use the terminal - and anyone can manage typing and backspacing. But there are some crafty shortcuts which can make your life a lot easier:
- How to move around in a terminal window and edit the text that you type there.
- Some Linux commands for basic tasks.
- Different ways to open a terminal, how to work with multiple terminals, etc.
使用本页
- 本文将指导您熟练掌握基本的 GNU/Linux shell 命令。
- 本文并不是命令行的完整教程,仅仅是对 Ubuntu图形界面工具的补充。
- 所有命令都用黑体标明。
- 需要键入的命令用“引用黑体”标明。
- 本文的所有命令都要在终端下执行。
- 注意:Linux是大小写敏感的。User,user,USER在Linux是不同的。
启动终端
在 Gnome (Ubuntu) 中
The terminal can be found at Applications menu -> Accessories -> Terminal.
在 Xfce (Xubuntu) 中
The terminal can be found at Applications menu -> System -> Terminal.
在 KDE (Kubuntu) 中
The terminal can be found at KMenu -> System -> Terminal Program (Konsole).
命令行
sudo:需要提升权限执行的命令
- 如果您所在的目录或想操作的文件不在您的帐户所在的目录,下面的大多数命令都需要使用 sudo 命令。这是一个特殊的命令,它给你临时的权限来修改系统设置。终端会询问你的密码。sudo 使用详情请参阅RootSudo
文件 & 目录类命令
- pwd: pwd 命令查看您当前所处的路径(pwd 代表 "打印当前工作目录")。例如:在桌面文件夹中执行 "pwd" 命令将输出 "~/Desktop"。注意,Gnome 的终端在窗口标题中也会显示这一信息-具体请看本页顶部的截屏图片。
- "cd ~/Desktop" will move you to your desktop directory.
cd: cd 命令用来改变当前工作目录。当您打开一个终端的时候,您就位于您的home目录中。如果想要切换到其它的目录,就要用 cd 命令。例如: "cd ~/Desktop"将会进入到您的桌面目录。- 进入root目录,输入 "cd /"
- 进入到您自己的目录,输入 "cd"
- 进入当前目录的上一次目录,输入 "cd .." /* 译者注:cd 与 .. 之间有空格 */
- 进入前一个操作的目录,输入 "cd -"
- 一次进入多层目录,输入 "cd /var/www" ,将会直接切换到/var的子目录/www中。
- "cd ~/Desktop" will move you to your desktop directory.
- cp: cp 命令用来复制文件。例如: "cp file foo" 命令将会创建一个"file"的精确的副本,并命名为"foo",而 "file" 不会有任何变化。当您用 mv 命令的时候,原始的文件将不在保留,而 cp 会保留原始的文件并创建一个新的副本。
- mv: mv 命令将文件移动到另一个位置或者给文件更名。看下面的例子: "mv file foo"命令会将文件"file"更名为"foo"。"mv foo ~/Desktop"会将文件"foo"移动到桌面目录,但不会更名。如果想更名,你必须要指定一个新的名字。
- 为了输入方便,您可以用"~"符号来代替您的home目录。
- 注意:如果你在用 mv 命令的时候加了 sudo,您就不能用~了,而必须用文件的全局路径了。
- rm' :' 这个命令用来移动或删除文件。对于非空的目录,用这个命令不能删除。
- ls: ls 命令列出当前目录下的文件(和目录)。使用特定的参数,您可以查看文件的大小,创建时间,权限等。例如:"ls ~" 会列出您的home目录中的文件(和目录)。
- man: man 命令用来显示其它命令的手册页。执行 "man man"可以查看到 man自己的信息。通过 "Man & Getting Help"能够分页显示更多的信息。
- mkdir: mkdir 命令用来创建目录。例如:"mkdir music" 将会创建一个 music 目录。
系统信息类命令
- df: df 命令用来查看各个文件系统当前的空间使用状况。"df -h"可能是最有用的选项了-它以M和G为单位输出,而不是以块为单位。(-h 的含义是“便于阅读”)
- free: free 命令用来查看系统中使用和剩余的内存情况。"free -m" 将结果以M为单位输出,这对现在的计算机来说非常有用。
- top: top 命令用来查看linux系统的信息,运行着的进程和系统资源,包括 CPU, RAM & swap使用情况和运行着的任务的总的数量。退出 top ,按 "q"。
- uname -a: uname 命令的 -a 参数用来查看系统的所有信息,包括 机器名,内核名称 & 版本 和一些其它的细节。它最大的用处是用来查看当前所用内核的信息。
- lsb_release -a: lsb_release 命令的 -a 参数查看当前运行的linux的版本信息,例如:
user@computer:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 6.06 LTS Release: 6.06 Codename: dapper
- ifconfig 显示当前系统的网络接口信息。
添加新用户
- "adduser newuser" 命令用来创建一个用户名为"newuser"的新用户,为新用户 newuser 创建一个密码,使用如下命令 "passwd newuser"。
命令选项
命令的默认操作常常会被指定一个确定的 --参数所修改。例如 ls 命令有一个 -s 参数,因此 "ls -s"就会额外的显示出文件的大小。它也有一个 -h参数,将文件的大小以很好的可读性的格式输出。
参数可以以簇聚合,比如 "ls -sh"和"ls -s -h"的效果相同。大多数的参数都很长,两个破折号前缀代表一个参数,所以"ls --size --human-readable"也和上面得命令相同。
"Man" 和 获得帮助
command --help和man command是命令行下面最重要的两个工具。
实际上所有的命令都有一个-h(or --help)参数,能够输出命令的简要的描述和参数,然后自动退出。可以输出"man -h" 或 "man --help"查看。
在linux下面,几乎每一个命令和每一个应用程序都会有一个man(manual)文件,所以只要简单的键入"man "command""就能看到这个命令的手册页。例如,"man mv"会打开mv的手册页。
利用键盘上的方向键移动手册页面,用"q"退出。
"man man" 会查看 man 命令的手册页,这里是一个很好的开始!
"man intro"也非常有用 -它能够查看 "用户命令介绍",写的非常好!是一份很简介的linux命令的介绍。
还有一个就是info 命令了,它通常比man还深入。试试"info info"命令。
搜索man文档
如果您不确定用哪个命令或程序,您可以试试搜索man文件。
- man -k foo会搜索关于foo的man文件。试试看"man -k nautilus"是怎样的。
- 注意:这同apropos 命令是一样的。
- man -f foo仅仅搜所系统man文件的标题。试试"man -f gnome"。
- 这个同 whatis 命令是相同的。
Other Useful Things
Prettier Manual Pages
Users who have Konqueror installed will be pleased to find they can read and search man pages in a web browser context, prettified with their chosen desktop fonts and a little colour, by visiting man:/command in Konqueror's address bar. Some people might find this lightens the load if there's lots of documentation to read/search.
Pasting in commands
Often, you will be referred to instructions that require commands to be pasted into the terminal. You might be wondering why the text you've copied from a web page using ctrl+C won't paste in with ctrl+V. Surely you don't have to type in all those nasty commands and filenames? Relax. Middle Button Click on your mouse (both buttons simultaneously on a two-button mouse) or Right Click and select Paste from the menu.
Save on typing
Up Arrow or ctrl+p | Scrolls through the commands you've entered previously. | |
Down Arrow or ctrl+n | Takes you back to a more recent command. | |
Enter | When you have the command you want. | |
tab | A very useful feature. It autocompletes any commands or filenames, if there's only one option, or else gives you a list of options. | |
ctrl+r | Searches for commands you've already typed. When you have entered a very long, complex command and need to repeat it, using this key combination and then typing a portion of the command will search through your command history. When you find it, simply press Enter. |
Change the text
The mouse won't work. Use the Left/Right arrow keys to move around the line. When the cursor is where you want it in the line, typing inserts text - ie it doesn't overtype what's already there.
ctrl+a or Home | Moves the cursor to the start of a line. | |
ctrl+e or End | Moves the cursor to the end of a line. | |
ctrl+b | Moves to the beginning of the previous or current word. | |
ctrl+k | Deletes from the current cursor position to the end of the line. | |
ctrl+u | Deletes the whole of the current line. | |
ctrl+w | Deletes the word before the cursor. |
More ways to run a terminal
You can also get it with a function key You can run more than one - in tabs or separate windows
更多信息
- apt-get 使用指南 - 用apt-get在命令行下安装软件包
- Commandline Repository Editing - 在命令行下添加 Universe/Multiverse 软件库。
- grep Howto - grep 是一个非常强大的命令行下的搜索工具。
- UbuntuHelp:CommandlineHowto - 比本文要长,也要完整很多的基础命令指南,至今为止,仍未完成。
- UbuntuHelp:HowToReadline - 针对命令行的更高级定制的信息。
关于Linux命令行的更详细指南,请参阅:
- http://linuxcommand.org/ - 基础 BASH 指南,包括 BASH 脚本。
- http://linuxsurvival.com/index.php - java基础指南
- http://rute.2038bug.com/index.html.gz - 系统管理相关的大量文档,几乎全部使用命令行。
Head back to UserDocumentation