BasicCommands
系统基本命令
原文出处:
原文作者:brian
授权许可:
翻译人员:casm
校正人员:
贡献人员:
适用版本: 文章状态:等待校正
"Under Linux there are GUIs (graphical user interfaces), where you can point and click and drag, and hopefully get work done without first reading lots of documentation. The traditional Unix environment is a CLI (command line interface), where you type commands to tell the computer what to do. That is faster and more powerful, but requires finding out what the commands are." -- from man intro(1)
"Linux下面有多种GUIs(图形用户界面),可以在其下点击鼠标,拖拽,能够很好的工作却不需要一次读很多文档.而传统的Unix环境是CLI(命令行界面),即在命令行下键入命令,执行想要的操作。相比之下,这种方式执行起来更快,功能也更强,不足之处是用户需要了解相关操作的命令。"--摘自 'man intro(1)'''
attachment:BasicCommandsSample.png
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 Linux is case sensitive. User, user, and USER are all different to Linux.
注意:Linux是大小写敏感的。User,user,USER在Linux是不同的。
Starting a Terminal in Gnome(在Gnome环境下启动终端)
In Ubuntu 6.06 (Dapper Drake) & Ubuntu 5.10 (Breezy Badger):Applications menu --> Accessories --> Terminal. To get the right-click Open Terminal option back in 5.10, searchSynapticfornautilus-open-terminal
and install it.
针对Ubuntu 6.06 (Dapper Drake) & Ubuntu 5.10 (Breezy Badger): 应用程序 --> 附件 --> 终端。如果想在5.10以后的版本中,右键单击能够有启动终端选项,请在新立得软件包管理器中搜索并安装 nautilus-open-terminal。
In Ubuntu 5.04 (Hoary Hedgehog)': Applications menu --> System Tools --> Terminal' or right-click on any empty area of desktop and choose "Terminal".
针对Ubuntu 5.04 (Hoary Hedgehog):应用程序 --> 附件 --> 终端 或者在桌面的任何空白区域鼠标右键单击,然后选择"终端"。
Commands(命令)
sudo: Executing Commands with Elevated Privileges(需要提升权限执行的命令)
- 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. Please see RootSudo for information on using sudo.
如果您所在的目录或想操作的文件不在您的帐户所在的目录,下面的大多数命令都需要以 sudo 开头。sudo 使用详情请参阅 RootSudo 。
File & 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 it's window - see the example screenshot at the top of this page.
pwd: pwd 命令查看您当前所处的路径(pwd 代表 "打印当前工作目录")。例如:在桌面文件夹中执行 "pwd" 命令将输出 "~/Desktop"。注意,Gnome 的终端在窗口标题中也会显示这一信息-具体请看本页顶部的截屏图片。- 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. Example: "cd ~/Desktop" will move you to your desktop directory.
cd: cd 命令用来改变当前工作目录。当您打开一个终端的时候,您就位于您的home目录中。如果想要切换到其它的目录,就要用 cd 命令。例如: "cd ~/Desktop"将会进入到您的桌面目录。- To navigate into the root directory,' use "cd /"'
进入root目录,输入 "cd /" - To navigate to your home directory, use "cd"
进入到您自己的目录,输入 "cd" - To navigate up one directory level, use "cd .."
进入当前目录的上一次目录,输入 "cd .." /* 译者注:cd 与 .. 之间有空格 */ - To navigate to the previous directory (or back), use "cd -"
进入前一个操作的目录,输入 "cd -" - To navigate through multiple levels of directory at once, use, "cd /var/www" for example, which will take you directly to the /www subdirectory of /var/.
一次进入多层目录,输入 "cd /var/www" ,将会直接切换到/var的子目录/www中。
- To navigate into the root directory,' use "cd /"'
- 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. Example: "cd ~/Desktop" will move you to your desktop 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. When you use mv that file would no longer exist, as when you use cp the file stays but a new copy is made.
cp: cp 命令用来复制文件。例如: "cp file foo" 命令将会创建一个"file"的精确的副本,并命名为"foo",而 "file" 不会有任何变化。当您用 mv 命令的时候,原始的文件将不在保留,而 cp 会保留原始的文件并创建一个新的副本。 - 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.
mv: mv 命令将文件移动到另一个位置或者给文件更名。看下面的例子: "mv file foo"命令会将文件"file"更名为"foo"。"mv foo ~/Desktop"会将文件"foo"移动到桌面目录,但不会更名。如果想更名,你必须要指定一个新的名字。- To save on typing, you can substitute '~' in place of the home directory.
为了输入方便,您可以用"~"符号来代替您的home目录。 - Note that if you are using mv with sudo you will not be able to use the ~ shortcut, but will have to use the full pathnames to your files.
注意:如果你在用 mv 命令的时候加了 sudo,您就不能用~了,而必须用文件的全局路径了。
- To save on typing, you can substitute '~' in place of the home directory.
- rm' : Use this command to remove or delete a file in your directory. It will not work on directories which have files in them.
rm' : 这个命令用来移动或删除文件。对于非空的目录,用这个命令不能删除。 - 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.
ls: ls 命令列出当前目录下的文件(和目录)。使用特定的参数,您可以查看文件的大小,创建时间,权限等。例如:"ls ~" 会列出您的home目录中的文件(和目录)。 - 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 & Getting Help" section down the page for more information.
man: man 命令用来显示其它命令的手册页。执行 "man man"可以查看到 man自己的信息。通过 "Man & Getting Help"能够分页显示更多的信息。 - mkdir: The mkdir command will allow you to create directories. Example: "mkdir music" will create a music directory.
mkdir: mkdir 命令用来创建目录。例如:"mkdir music" 将会创建一个 music 目录。
System Information Commands(系统信息类命令)
- df: The df command displays filesystem disk space usage for all partitions. "df -h" is probably the most useful - it uses megabytes (M) and gigabytes (G) instead of blocks to report. (-h means "human-readable")
df: df 命令用来查看各个文件系统当前的空间使用状况。"df -h"可能是最有用的选项了-它以M和G为单位输出,而不是以块为单位。(-h 的含义是“便于阅读”) - 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.
free: free 命令用来查看系统中使用和剩余的内存情况。"free -m" 将结果以M为单位输出,这对现在的计算机来说非常有用。 - t'op:' The top command displays information on your Linux system, running processes and system resources, including CPU, RAM & swap usage and total number of tasks being run. To exit top, press "q".
top: top 命令用来查看linux系统的信息,运行着的进程和系统资源,包括 CPU, RAM & swap使用情况和运行着的任务的总的数量。退出 top ,按 "q"。 - uname -a: The uname command with the -a option prints all system information, including machine name, kernel name & version, and a few other details. Most useful for checking which kernel you're using.
uname -a: uname 命令的 -a 参数用来查看系统的所有信息,包括 机器名,内核名称 & 版本 和一些其它的细节。它最大的用处是用来查看当前所用内核的信息。 - lsb_release -a: The lsb_release command with the -a option prints version information for the Linux release you're running, for example:
* 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' reports on your system's network interfaces.'
ifconfig 显示当前系统的网络接口信息。
Adding A New User(添加新用户)
- "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".
"adduser newuser" 命令用来创建一个用户名为"newuser"的新用户,为新用户 newuser 创建一个密码,使用如下命令 "passwd newuser"。
Options(参数)
The default behavior for a command may usually be modified by adding a --option to the command. The ls command for example has an -s"ls -s" option so that will include file sizes in the listing. There is also a -h option to get those sizes in a "human readable" format.
命令的默认操作常常会被指定一个确定的 --参数所修改。例如 ls 命令有一个 -s 参数,因此 "ls -s"就会额外的显示出文件的大小。它也有一个 -h参数,将文件的大小以很好的可读性的格式输出。
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.
参数可以以簇聚合,比如 "ls -sh"和"ls -s -h"的效果相同。大多数的参数都很长,两个破折号前缀代表一个参数,所以"ls --size --human-readable"也和上面得命令相同。
"Man" and getting help("Man" 和 获得帮助)
command --help' and' man command are the two most important tools at the command line.
command --help和man command是命令行下面最重要的两个工具。
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.
实际上所有的命令都有一个-h(or --help)参数,能够输出命令的简要的描述和参数,然后自动退出。可以输出"man -h" 或 "man --help"查看。
Every command and nearly every 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.
在linux下面,几乎每一个命令和每一个应用程序都会有一个man(manual)文件,所以只要简单的键入"man "command""就能看到这个命令的手册页。例如,"man mv"会打开mv的手册页。
Move up and down the man file with the arrow keys, and quit back to the command prompt with "q".
利用键盘上的方向键移动手册页面,用"q"退出。
"man man" will bring up the manual entry for the man command, which is a good place to start!
"man man" 会查看 man 命令的手册页,这里是一个很好的开始!
"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.
"man intro"也非常有用 -它能够查看 "用户命令介绍",写的非常好!是一份很简介的linux命令的介绍。
There are also info pages, which are generally more in-depth than man pages. Try "info info" for the introduction to info pages.
还有一个就是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 the apropos command.
注意:这同apropos 命令是一样的。
- Note that this is the same as the apropos command.
- 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"。- This is the same as the whatis command.
这个同 whatis 命令是相同的。
- This is the same as the whatis command.
More Information(更多信息)
- AptGetHowto - using apt-get to install packages from the command line.
apt-get 使用指南 - 用apt-get在命令行下安装软件包 - Commandline Repository Editing - adding the Universe/Multiverse repositories through the command line.
Commandline Repository Editing - 在命令行下添加 Universe/Multiverse 软件库。 - grep Howto - grep is a powerful command line search tool.
grep Howto - grep 是一个非常强大的命令行下的搜索工具。 - CommandlineHowto - longer and more complete than this basic guide, but still unfinished.
CommandlineHowto - 比本文要长,也要完整很多的基础命令指南,至今为止,仍未完成。 - HowToReadline - information on some more advanced customization for the command line.
HowToReadline - 针对命令行的更高级定制的信息。
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 - 系统管理相关的大量文档,几乎全部使用命令行。