特殊:Badtitle/NS100:UsingTheTerminal/zh:修订间差异

来自Ubuntu中文
跳到导航跳到搜索
Dbzhang800留言 | 贡献
无编辑摘要
Dbzhang800留言 | 贡献
无编辑摘要
第3行: 第3行:
{{From|https://help.ubuntu.com/community/UsingTheTerminal}}
{{From|https://help.ubuntu.com/community/UsingTheTerminal}}


{{Translator|convice}}<br>{{Languages|UbuntuHelp:UsingTheTerminal}}
{{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.


=== Using this page ===
=== 使用本页 ===


* This page will make you familiar with basic GNU/Linux shell commands.
* 本文将指导您熟练掌握基本的 GNU/Linux shell 命令。
* It is not intended to be a complete guide to the command line, just an introduction to complement Ubuntu's graphical tools.
* 本文并不是命令行的完整教程,仅仅是对 Ubuntu图形界面工具的补充。
* All command names will be in '''bold'''.
* 所有命令都用黑体'''标明。 '''
* Commands needing to be typed will be in '''"bold with quotes"'''.
* 需要键入的命令用“引用黑体”'''标明。 '''
* All of the commands on this page are to be issued from a command prompt in a terminal.
* 本文的所有命令都要在终端下执行。
* '''Note that the terminal is case sensitive.''' User, user, and USER are all different to Linux.
* 注意:Linux是大小写敏感的。'''User,user,USER在Linux是不同的。 '''


=== Starting a Terminal ===
=== 启动终端 ===


==== In Gnome (Ubuntu) ====
==== Gnome (Ubuntu) ====


The terminal can be found at '''Applications menu''' -&gt; '''Accessories''' -&gt; '''Terminal'''.
The terminal can be found at '''Applications menu''' -&gt; '''Accessories''' -&gt; '''Terminal'''.


==== In Xfce (Xubuntu) ====
==== Xfce (Xubuntu) ====


The terminal can be found at '''Applications menu''' -&gt; '''System''' -&gt; '''Terminal'''.
The terminal can be found at '''Applications menu''' -&gt; '''System''' -&gt; '''Terminal'''.


==== In KDE (Kubuntu) ====
==== KDE (Kubuntu) ====


The terminal can be found at '''KMenu''' -&gt; '''System''' -&gt; '''Terminal Program (Konsole)'''.
The terminal can be found at '''KMenu''' -&gt; '''System''' -&gt; '''Terminal Program (Konsole)'''.


=== Commands ===
=== 命令行 ===


==== sudo: Executing Commands with Elevated Privileges ====
==== sudo:需要提升权限执行的命令 ====


* Most of the following commands will need to be prefaced with the '''sudo''' command if you will be working with directories or files not owned by your account. This is a special command which temporarily gives you access to change computer settings. The terminal will ask you for your password. Please see [[UbuntuHelp:RootSudo|RootSudo]] for information on using sudo.
* 如果您所在的目录或想操作的文件不在您的帐户所在的目录,下面的大多数命令都需要使用 '''sudo '''命令。这是一个特殊的命令,它给你临时的权限来修改系统设置。终端会询问你的密码。sudo 使用详情请参阅[[UbuntuHelp:RootSudo|RootSudo]]  


==== File &amp; Directory Commands ====


* '''pwd''': The '''pwd''' command will allow you to know in which directory you're located ('''pwd''' stands for "print working directory"). Example: '''"pwd"''' in the Desktop directory will show "~/Desktop". Note that the Gnome Terminal also displays this information in the title bar of its window - see the example screenshot at the top of this page.
==== 文件 & 目录类命令 ====
* '''ls''': The '''ls''' command will show you the files in your current directory. Used with certain options, you can see sizes of files, when files where made, and permissions of files. Example: '''"ls ~"''' will show you the files that are in your home directory.
* '''cd''': The '''cd''' command will allow you to change directories. When you open a terminal you will be in your home directory. To move around the file system you will use '''cd'''. Examples:
* To navigate into the root directory, use '''"cd /"'''
* To navigate to your home directory, use '''"cd"''' or '''"cd ~"'''
* To navigate up one directory level, use '''"cd .."'''
* To navigate to the previous directory (or back), use '''"cd -"'''
* To navigate through multiple levels of directory at once, specify the full directory path that you want to go to. For example, use, '''"cd /var/www"''' to go directly to the /www subdirectory of /var/. As another example, '''"cd ~/Desktop"''' will move you to the Desktop subdirectory inside your home directory.
* '''cp''': The '''cp''' command will make a copy of a file for you. Example: '''"cp file foo"''' will make a exact copy of "file" and name it "foo", but the file "file" will still be there. If you are copying a directory, you must use '''"cp -r directory foo"''' (copy recursively).
* '''mv''': The '''mv''' command will move a file to a different location or will rename a file. Examples are as follows: '''"mv file foo"''' will rename the file "file" to "foo". '''"mv foo ~/Desktop"''' will move the file "foo" to your Desktop directory but will not rename it. You must specify a new file name to rename a file.
* To save on typing, you can substitute '~' in place of the home directory.
* Note that if you are using '''mv''' with '''sudo''' you can use the ~ shortcut, because the terminal expands the ~ to your home directory. However, when you open a root shell with '''sudo -i''' or '''sudo -s''', ~ will refer to the root account's home directory, not your own.
* '''rm''': Use this command to remove or delete a file in your directory.
* '''rmdir''': The '''rmdir''' command will delete an ''empty'' directory. To delete a directory and all of its contents recursively, use '''rm -r''' instead.
* '''mkdir''': The '''mkdir''' command will allow you to create directories. Example: '''"mkdir music"''' will create a directory called "music".
* '''man''': The '''man''' command is used to show you the manual of other commands. Try '''"man man"''' to get the man page for '''man''' itself. See the "'''Man''' &amp; Getting Help" section down the page for more information.


==== System Information Commands ====
* '''pwd:''' '''pwd''' 命令查看您当前所处的路径('''pwd''' 代表 "打印当前工作目录")。例如:在桌面文件夹中执行 "pwd" 命令将输出 "~/Desktop"。注意,Gnome 的终端在窗口标题中也会显示这一信息-具体请看本页顶部的截屏图片''''''
 
**  '''"cd ~/Desktop"''' will move you to your desktop directory.<br>'''cd: cd''' 命令用来改变当前工作目录。当您打开一个终端的时候,您就位于您的home目录中。如果想要切换到其它的目录,就要用 cd 命令。例如: '''"cd ~/Desktop"'''将会进入到您的桌面目录。''' '''
* '''df''': The '''df''' command displays filesystem disk space usage for all mounted partitions. "'''df -h'''" is probably the most useful - it uses megabytes (M) and gigabytes (G) instead of blocks to report. ('''-h''' means "human-readable")
*** 进入root目录,输入 '''"cd /" '''
* '''du''': The '''du''' command displays the disk usage for a directory. It can either display the space used for all subdirectories or the total for the directory you run it on. Example:
*** 进入到您自己的目录,输入 '''"cd" '''
<pre>user@users-desktop:~$ du /media/floppy
*** 进入当前目录的上一次目录,输入 '''"cd .."    '''/* 译者注:cd 与 .. 之间有空格 */''' '''
1032 /media/floppy/files
*** 进入前一个操作的目录,输入 '''"cd -" '''
1036 /media/floppy/
*** 一次进入多层目录,输入 '''"cd /var/www" ''',将会直接切换到/var的子目录/www中。''' '''
user@users-desktop:~$ du -sh /media/floppy
* '''cp: cp''' 命令用来复制文件。例如: '''"cp file foo" '''命令将会创建一个"file"的精确的副本,并命名为"foo",而 "file"''' '''不会有任何变化。当您用 mv 命令的时候,原始的文件将不在保留,而 cp 会保留原始的文件并创建一个新的副本。
1.1M /media/floppy/
* '''mv: mv''' 命令将文件移动到另一个位置或者给文件更名。看下面的例子: '''"mv file foo"'''命令会将文件"file"更名为"foo"。'''"mv foo ~/Desktop"'''会将文件"foo"移动到桌面目录,但不会更名。如果想更名,你必须要指定一个新的名字。''' '''
</pre>
** 为了输入方便,您可以用'''"~"'''符号来代替您的home目录。
* '''-s''' means "Summary" and '''-h''' means "Human Readable"
** 注意:如果你在用 '''mv''' 命令的时候加了 '''sudo,'''您就不能用~了,而必须用文件的全局路径了。''' '''
* '''free''': The '''free''' command displays the amount of free and used memory in the system. '''"free -m"''' will give the information using megabytes, which is probably most useful for current computers.
* '''rm'''''' :''' 这个命令用来移动或删除文件。对于非空的目录,用这个命令不能删除。''' '''
* '''top''': The '''top''' command displays information on your Linux system, running processes and system resources, including CPU, RAM &amp; swap usage and total number of tasks being run. To exit '''top''', press '''"q"'''.
* '''ls''': ls 命令列出当前目录下的文件(和目录)。使用特定的参数,您可以查看文件的大小,创建时间,权限等。例如:'''"ls ~"''' 会列出您的home目录中的文件(和目录)。''' '''
* '''uname -a''': The '''uname''' command with the '''-a''' option prints all system information, including machine name, kernel name &amp; version, and a few other details. Most useful for checking which kernel you're using.
* '''man: man''' 命令用来显示其它命令的手册页。执行 '''"man man"'''可以查看到 man自己的信息。通过 "'''Man''' & Getting Help"能够分页显示更多的信息。
* '''lsb_release -a''': The '''lsb_release''' command with the '''-a''' option prints version information for the Linux release you're running, for example:
* '''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''' reports on your system's network interfaces.
* '''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'''''是命令行下面最重要的两个工具。''' '''


==== Adding A New User ====
实际上所有的命令都有一个'''-h(or --help)'''参数,能够输出命令的简要的描述和参数,然后自动退出。可以输出'''"man -h"''' 或 '''"man --help"'''查看。''' '''


* '''"adduser newuser"''' command will create a new general user called "newuser" on your system, and to assign a password for the newuser account use '''"passwd newuser"'''.
在linux下面,几乎每一个命令和每一个应用程序都会有一个man(manual)文件,所以只要简单的键入'''"man "command""'''就能看到这个命令的手册页。例如,'''"man mv"'''会打开mv的手册页。''' '''


=== Options ===
利用键盘上的方向键移动手册页面,用'''"q"'''退出。''' '''


The default behaviour for a command may usually be modified by adding a '''--''option''''' to the command. The '''ls''' command for example has an '''-s''' option so that '''"ls -s"''' will include file sizes in the listing. There is also a '''-h''' option to get those sizes in a "human readable" format. Options can be grouped in clusters so '''"ls -sh"''' is exactly the same command as '''"ls -s -h"'''. Most options have a long version, prefixed with two dashes instead of one, so even '''"ls --size --human-readable"''' is the same command.
'''"man man"''' 会查看''' man''' 命令的手册页,这里是一个很好的开始!''' '''


=== "Man" and getting help ===
'''"man intro"'''也非常有用 -它能够查看  "用户命令介绍",写的非常好!是一份很简介的linux命令的介绍。


/!\ '''man ''command''''', '''info ''command''''' and '''''command'' --help''' are the most important tools at the command line. Nearly every command and application in Linux will have a man (manual) file, so finding them is as simple as typing '''"man "command""''' to bring up a longer manual entry for the specified command. For example, '''"man mv"''' will bring up the '''mv''' (Move) manual. Move up and down the man file with the arrow keys, and quit back to the command prompt with '''"q"'''. '''"man man"''' will bring up the manual entry for the '''man''' command, which is a good place to start! '''"man intro"''' is especially useful - it displays the "Introduction to user commands" which is a well-written, fairly brief introduction to the Linux command line. There are also '''info''' pages, which are generally more in-depth than '''man''' pages. Try '''"info info"''' for the introduction to info pages. Some software developers prefer '''info''' to '''man''' (for instance, Debian and GNU developers), so if you find a very widely used command or app that doesn't have a '''man''' page, it's worth checking for an '''info''' page. Virtually all commands understand the '''-h''' (or '''--help''') option which will produce a short usage description of the command and it's options, then exit back to the command prompt. Try '''"man -h"''' or '''"man --help"''' to see this in action. ''Caveat: It's possible (but rare) that a program doesn't understand the -h option to mean help. For this reason, check for a '''man''' or '''info''' page first, and try the long option --help before -h.''
还有一个就是'''info''' 命令了,它通常比'''man'''还深入。试试'''"info info"'''命令。''' '''


==== Searching for man files ====
==== 搜索man文档 ====


If you aren't sure which command or application you need to use, you can try searching the man files.
如果您不确定用哪个命令或程序,您可以试试搜索'''man'''文件。


* '''man -k ''foo''''' will search the man files for ''foo''. Try '''"man -k nautilus"''' to see how this works.
* '''man -k ''foo'''''会搜索关于foo的man文件。试试看'''"man -k nautilus"'''是怎样的。
* Note that this is the same as doing '''apropos ''command'''''.
** 注意:这同'''apropos''' 命令是一样的。
* '''man -f ''foo''''' searches only the titles of your system's man files. Try '''"man -f gnome"''', for example.
* '''man -f ''foo'''''仅仅搜所系统man文件的标题。试试'''"man -f gnome"'''
* Note that this is the same as doing '''whatis ''command'''''.
** 这个同 '''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


=== More Information ===
=== 更多信息 ===
 
* [[UbuntuHelp:AptGetHowto/zh|apt-get 使用指南]] - 用apt-get在命令行下安装软件包
* [[UbuntuHelp:AptGetHowto|AptGetHowto]] - using apt-get to install packages from the command line.
* [[UbuntuHelp:Repositories/CommandLine|Commandline Repository Editing]] - 在命令行下添加 Universe/Multiverse 软件库。
* [[UbuntuHelp:Repositories/CommandLine|Commandline Repository Editing]] - adding the Universe/Multiverse repositories through the command line.
* [[UbuntuHelp:grep/zh|grep Howto]] - grep 是一个非常强大的命令行下的搜索工具。
* [[UbuntuHelp:Grep|grep Howto]] - grep is a powerful command line search tool.
* [[UbuntuHelp:CommandlineHowto]] - 比本文要长,也要完整很多的基础命令指南,至今为止,仍未完成。
* [[UbuntuHelp:Find|find Howto]] - locate files on the command line.
* [[UbuntuHelp:HowToReadline]] - 针对命令行的更高级定制的信息。
* [[UbuntuHelp:CommandlineHowto|CommandlineHowto]] - longer and more complete than this basic guide, but still unfinished.
* [[UbuntuHelp:HowToReadline|HowToReadline]] - information on some more advanced customization for the command line.


For more detailed tutorials on the Linux command line, please see:
关于Linux命令行的更详细指南,请参阅:


* http://linuxcommand.org/ - basic BASH tutorials, including BASH scripting
* http://linuxcommand.org/ - 基础 BASH 指南,包括 BASH 脚本。
* http://linuxsurvival.com/index.php - Java-based tutorials
* http://linuxsurvival.com/index.php - java基础指南
* http://rute.2038bug.com/index.html.gz - a massive online book about system administration, almost all from the command line.
* http://rute.2038bug.com/index.html.gz - 系统管理相关的大量文档,几乎全部使用命令行。


----
----

2008年4月14日 (一) 14:00的版本

{{#ifexist: :UsingTheTerminal/zh/zh | | {{#ifexist: UsingTheTerminal/zh/zh | | {{#ifeq: {{#titleparts:UsingTheTerminal/zh|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:UsingTheTerminal/zh|1|-1|}} | zh | | }}


为什么使用终端?

"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中。
  • 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 --helpman 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

更多信息

关于Linux命令行的更详细指南,请参阅:


Head back to UserDocumentation