免费注册 查看新帖 |


  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1078 | 回复: 0

Certification Objective 1.03: Basic Commands [复制链接]

发表于 2007-04-01 20:28 |显示全部楼层
Certification Objective 1.03: Basic Commands
认证目的 1.03: 基本命令
Linux was developed as a clone of Unix, which means that it has the same functionality with different source code.
Linux 当做一个 Unix 的复制, 意谓它用不同的根源程序码有相同的功能性被发展。
And the essence of both operating systems is at the command line.
Basic commands for file manipulation and filters are available to help you do more with a file.
Basic File Operations
Two basic groups of commands are used to manage Linux files.
二个基本群体的指令被用处理 Linux 文件。
One group helps you get around Linux files and directories.
一个组帮助,你传开 Linux 文件和目录。
The other group actually does something creative with the files.
Remember, in any Linux file operation, you can take advantage of the HISTORY (this is capitalized because it's a standard environment variable) of previous commands, as well as the characteristics of command completion, which allow you to use the TAB key almost as a wildcard to complete a command or a filename, or give you the options available in terms of the absolute path.
记得,在任何的 Linux 文件运算,你能利用早先指令的历史 (这被以大写字母写因为它是标准的环境变数) 连同指令完成的特性,让你当做一个取代字符几乎使用定位键键完成一个指令或者一个档名, 或给你根据绝对的路径得到的选择项。
Almost all Linux commands include switches, options that allow you to do more.
几乎所有的 Linux 指令包括开关,让你做更多的选择项。
Few are covered in this chapter.
If you're less familiar with any of these commands, use their man pages.
Study the switches.
Try them out!
Only with practice, practice, and more practice can you really understand the power behind some of these commands.
Basic Navigation
Everything in Linux can be reduced to a file.
在 Linux 的每件事物能被转为一个文件。
Directories are special types of files that serve as containers for other files.
Drivers are files.
As discussed earlier, devices are special types of files.
如早地当做, 装置是文件的特别类型。
The nodes associated with USB hardware are just files.
And so on.
To navigate around these files, you need some basic commands to tell you where you are, what is there with you, and how to move around.
为了要在附近航行这些文件,你需要一些基本的指令告诉你你是哪里,与你有什么, 和该如何到处移动。
The Tilde (~)
But first, every Linux user has a home directory.
但是第一的, 每 Linux 使用者有一个家目录。
You can use the tilde (~) to represent the home directory of any currently logged on user.
你能使用化符号 (~) 表现家目录任何的现在登录了使用者。
For example, if your username is tb, your home directory is /home/tb.
举例来说,如果你的使用者名称是 tb, 你的家目录是 /home/tb。
If you've logged in as the root user, your home directory is /root.
如果你已经登录如根使用者, 你的家目录是 /root。
Thus, the effect of the cd ~ command depends on your username.
因此, cd 的效果 ~ 指令仰赖你的使用者名称。
For example, if you've logged in as user mj, the cd ~ command brings you to the /home/mj directory.
举例来说,如果你已经当做使用者 mj 登录, cd~ 指令带着你到那 /home/mj 目录。
If you've logged in as the root user, this command brings you to the /root directory.
如果你已经登录如根使用者,这指令带着你到那 / 根目录。
There are two path concepts you need to know when you work with Linux directories:
有二个路径观念当你与 Linux 目录合作的时候,你需要知道:
absolute paths and relative paths.
An absolute path describes the complete directory structure based on the top level directory, root (/).
一个绝对的路径描述以最上面的同高目录, 根为基础的完全的目录结构。 (/)
A relative path is based on the current directory, also known as the present working directory.
一个比较的路径以目前的目录为基础, 也当做现在的工作目录知道。
Relative paths do not include the slash in front.
The difference between an absolute path and a relative one is important.
Especially when you're creating a script, absolute paths are essential.
Otherwise, scripts executed from other directories may lead to unintended consequences.
In many configurations, you may not know where you are relative to the root (/) directory.
在许多配置中,你可能不知道你相对于根 (/) 目录的地方。
The pwd command, which is short for present working directory, can tell you, relative to root (/).
pwd 指令,是现在的工作目录的短,能告诉你, 比较的植根pe from prison.(/)
Once you know where you are, you can know if you need to move to a different directory.
It's easy to change directories in Linux.
在 Linux 改变目录很容易。
Just use cd and cite the absolute path of the desired directory.
正直使用的 cd 而且引证被需要的目录的绝对路径。
If you use the relative path, just remember that your final destination depends on the present working directory.
The most basic of commands is to list the files in the current directory.
But the Linux ls command, with the right switches, can be quite powerful.
但是 Linux ls 指令, 藉由正确的开关,可能是相当有力。
The right kind of ls can tell you everything about a file, such as creation date, last access date, and size.
正确类型的 ls 能告诉你关于一个文件的每件事物, 像是创造日期,最后的存取日期和大小。
It can help you organize the listing of files in just about any desired order.
Important variations on this command include ls -a to reveal hidden files, ls -l for long listings, and ls -i for inode numbers.
在这指令方面的重要的变更包括 ls-一显示隐藏的文件, ls-l 为长的列表、和 ls-为 inode 编号的 i。
Looking for Files
There are two basic commands for file searches:
find and locate.
The find command searches through directories and subdirectories for a desired file.
For example, if you wanted to find the directory with the XF86Config GUI configuration file, you could use the following command, which would start the search in the root directory:
举例来说,如果你想要用 XF86 配置图形用户接口配置文件找目录,你可以使用下列的指令, 会让搜寻从在根目录中开始:
# find / -name XF86Config
But this search on my older laptop computer with a 200 MHz CPU took several minutes.
但是在我的较旧的笔记型电脑上的这搜寻用一个 200 MHz 处理器花了好几分钟。
Alternatively, if you know that this file is located in the /etc subdirectory tree, you could start in that directory with the following command:
二者择一地,如果你知道这一个文件位于那 /及其他子目录树, 你可以启动在目录用下列的指令:
# find /etc -name XF86Config
If this is all too time-consuming, RHEL 3 includes a default database of all files and directories.
如果这是全部都太耗时, RHEL 3 包括所有文件和目录的一个内定数据库。
Searches with the locate command are almost instantaneous.
And locate searches don't require the full filename.
The drawback is that the locate command database is normally updated only once each day, as documented in the /etc/cron.daily/slocate.cron script.
不利点是那通常位于指令数据库只有一旦每天被更新, 如那 /etc/cron.daily/ slocate.cron 脚本所证明。
Exam Watch  The first time I started Linux during the RHCE exam, I ran this script.
考试表第一个次我在 RHCE 考试期间启动了 Linux ,我跑这一个脚本。
I could then use the locate command to quickly find the files that I needed.
Getting into the Files
Now that you see how to find and get around different files, it's time to start reading, copying, and moving the files around.
既然你见到该如何找而且传开不同的文件,它是该启动读、拷贝的时候, 而且在附近移动文件。
Most Linux configuration files are text files.
大多数的 Linux 配置文件是文字档。
Linux editors are text editors.
Linux 编辑程序是文字档编辑程序。
Linux commands are designed to read text files.
Linux 指令被设计读文字档。
If in doubt, you can check the file types in the current directory with the file * command.
如果在怀疑方面,你以文件能在目前的目录中检查文件类型 * 指令。
The most basic command for reading files is cat.
The cat filename command scrolls the text within the filename file.
It also works with multiple filenames;it concatenates the filenames that you might list as one continuous output to your screen.
less and more
Larger files demand a command that can help you scroll through the file text at your leisure.
Linux has two of these commands:more and less.
Linux 有这些指令中的二个: 更多和更少。
With the more filename command, you can scroll through the text of a file, from start to finish, one screen at a time.
With the less filename command, you can scroll in both directions through the same text with the PAGE UP and PAGE DOWN keys.
Both commands support vi-style searches.
两者的指令支援 vi-风格的搜寻。
head and tail
The head and tail commands are separate commands that work in essentially the same way.
By default, the head filename command looks at the first 10 lines of a file;
预先设定地,磁头档名指令看文件的最初 10个线;
the tail filename command looks at the last 10 lines of a file.
在后面的档名指令看文件的最后 10个线。
You can specify the number of lines shown with the -nxy switch.
你能叙述与线的数目一起显示的那 -nxy 开关。
Just remember to avoid the space when specifying the number of lines;
for example, the tail -n15 /etc/passwd command lists the last 15 lines of the /etc/passwd file.
举例来说, tail -n 15/etc/passwd 指令列出那 /etc/passwd 文件的最后 15个线。
Creating Files
A number of commands are used to create new files.
Alternatively, you can let a text editor such as vi create a new file for you.
二者择一地,你能让一个文字档编辑程序,像是 vi 为你产生一个新的文件。
The cp (copy) command allows you to take the contents of one file and place a copy with the same or different name in the directory of your choice.
cp(拷贝) 指令让你采取一个文件的内容而且把一个拷贝放与一样的或在你的选择的目录中的不同名字。
For example, the cp file1 file2 command takes the contents of file1 and saves the contents in file2.
举例来说, cp 文件 1个文件 2个指令采取文件 1 的内容而且把在文件 2 内的内容存档.
One of the dangers of cp is that it can easily overwrite files in different directories, without prompting you to make sure that's what you really wanted to do.
cp 的危险之一是它能容易地在不同的目录中重写文件, 没有促使你确定那是你真的想要做的。
While you can't rename a file in Linux, you can move it.
你不能在 Linux 重新命名一个文件,不过你能移动它。
The mv command essentially puts a different label on a file.
mv 指令本质上把一个不同的标示放在一个文件。
For example, the mv file1 file2 command changes the name of file1 to file2.
举例来说, mv 文件 1个文件 2个指令改变文件 1 的名字申请 2.
Unless you're moving the file to a different partition, everything about the file, including the inode number, remains the same.
除非你正在移动文件到一个不同的分区,关于文件的每件事物,包括 inode 数目, 保持相同。
You can create a linked file.
As discussed earlier, linked files are common with device files such as /dev/modem and /dev/mouse.
如早地同样地, 联接文件是通常的具有装置申请如此的当做 /dev/调制解调器和 /dev/鼠标。
They're also useful to make sure that multiple users have a copy of the same file in their directories.
Hard links include a copy of the file.
As long as the hard link is made within the same partition, the inode numbers are identical.
只要硬式联结在相同的分区里面被做, inode 编号是同一的。
You could delete a hard-linked file in one directory, and it would still exist in the other directory.
你可以划除一硬式-在一个目录中联接文件, 而且它会仍然在另一个目录中存在。
For example, the following command creates a hard link from the actual Samba configuration file to smb.conf in the local directory:
举例来说,下列的指令在当地的目录中从真实的桑巴舞配置文件到 smb.conf 产生一个硬式联结:
# ln smb.conf /etc/samba/smb.conf
On the other hand, a soft link serves as a redirect;when you open up a file created with a soft link, you're directed to the original file.
另一方面,一个软式联结视为再直接; 当你打开与一个软式联结一起建立的一个文件的时候,你指向最初的文件。
If you delete the original file, the file is lost.
While the soft link is still there, it has nowhere to go.
The following command is an example of how you can create a soft link:
# ln -s smb.conf /etc/samba/smb.conf
File Filters
Linux is rich in commands that can help you filter the contents of a file.
Linux 在能帮助你过滤文件的内容的指令是富有的。
There are simple commands to help you search, check, or sort the contents of a file.
有简单的指令要帮助你搜寻, 检验, 或分类文件的内容。
And there are special files that contain others;these container files are known colloquially as 'tarballs,' which is an alternative to the Red Hat Package Manager.
而且有包含其他的特别的文件; 这些容器文件被用白话当做红帽的替代品软件包经理的 'tarballs,' 知道。
On The Job  Tarballs are a common way to distribute Linux packages.
在作业 Tarballs 上是分配 Linux 软件包的一个通常的方法。
They are normally distributed in a compressed format, with a .tar.gz or .tgz file extension, consolidated as a package in a single file.
他们通常以一个被压缩的格式被分配, 与一。tgz 文件扩充,在一个文件中联合当做一个软件包了。
In this respect, they are similar to Microsoft-style compressed zip files.
You can sort the contents of a file in a number of ways.
By default, the sort command sorts the contents in alphabetical order depending on the first letter in each line.
For example, the sort /etc/passwd command would sort all users (including those associated with specific services and such) by username.
举例来说, 分类 /etc/passwd 指令会藉着使用者名称分类所有的使用者 (包括与特定的服务有关的那些和如此的)。
grep and egrep
grep 和 egrep
The grep command uses a search term to look through a file.
grep 指令使用一个搜寻期限看过一个文件。
It returns the full line that contains the search term.
For example, grep ‘Michael Jang' /etc/passwd looks for the name of this author in the /etc/passwd file.
举例来说, grep' Michael Jang'/etc/passwd 在那 /etc/passwd 文件中找寻这一位作家的名字。
The egrep command is more forgiving;
egrep 指令更宽大;
it allows you to use some unusual characters in your search, including +, ?, |, (, and ).
它让你使用你的搜寻的一些不寻常的字符, 包括 +, ?,|,.(, and )
While it's possible to set up grep to search for these characters with the help of the backslash, the command can be awkward.
建立 grep 寻找有着反斜线的辅助的这些字符是可能的,不过指令可能是笨拙的。
On The Job  The locate command is essentially a specialized version of the grep command, which uses the slocate command-based database of files on your Linux computer.
在作业上那本质上位于指令是 grep 指令的一个被特殊化的版本,在你的 Linux 计算机上使用 slocate 文件的以指令为基础数据库。
The wc command, short for word count, can return the number of lines, words, and characters in a file.
wc 指令, 短为字组,计数,能在一个文件中返回线、字组和字符的数目。
The wc options are straightforward;for example, wc -w filename returns the number of words in that file.
wc 选择项是笔直的; 举例来说, wc-w 的档名在那一个文件中返回字组的数目。
The sed command, short for stream editor, allows you to search for and change specified words or even text streams in a file.
sed 指令, 短为水流编辑程序,让你寻找而且改变指定的字组或平坦的文本流出在一个文件中。
For example, the following command changes the first instance of the word 'Windows' with 'Linux' in each line of the file opsys, and writes the result to the file newopsys:
举例来说,下列的指令在文件 opsys 的每个线中以 'Linux' 来取代字组 'Windows' 的第一个例图, 而且写结果给文件 newopsys:
# sed 's/Windows/Linux' opsys > newopsys
However, this may not be enough.
If there's more than one instance of 'Windows' in a line in the opsys file, it does not change the second instance of that word.
如果排成一列有 'Windows' 的超过一个例图在 opsys 文件中,它不改变那一个字组的第二个例图。
But you can fix this by adding a 'global' suffix:
但是你能藉由增加一个 '全球的' 后缀固定这:
# sed 's/Windows/Linux/g' opsys > newopsys
The awk command, named for its developers (Aho, Weinberger, and Kerrigan), is more of a database management command.
awk 指令, 为它的开发者 (Aho 、 Weinberger 和 Kerrigan) 命名,是资料库管理指令的更多。
It can identify lines with a key word, and read out the text from a specified column in that line.
它能将线和一个牛鼻子字视为等同, 和出自来自那一个线的一个指定的栏的文本的阅读。
A common example is with the /etc/passwd file.
一个通常的例子与那 /etc/passwd 文件。
For example, the following command will read out the username of every user with a 'Mike' in the comment column:
举例来说,下列的指令将会和注解栏的一个 '微音器的俚语' 大声朗读每个使用者的使用者名称:
# awk '/Mike/ {print $1}' /etc/passwd
Administrative Commands
You'll work with a number of administrative commands in this book.
But every budding Linux administrator should be familiar with at least two basic administrative commands:
但是每一萌芽的 Linux 系统管理师应该熟悉至少二个基本的管理指令:
ps and who.
It's important to know what's running on your Linux computer.
知道什么正在涉及你的 Linux 计算机很重要。
The ps command has a number of critical switches.
ps 指令有一些紧要关头的开关。
When trying to diagnose a problem, it's common to get the fullest possible list of running processes, then look for a specific program.
当尝试诊断一个问题的时候, 拿完整可能列表是通常的正在运行中的程序, 然后找寻一个特有程序。
For example, if the Mozilla Web browser were to suddenly crash, you'd want to kill any associated processes.
举例来说, 如果 Mozilla 网页浏览器是到突然坠毁, 你将会想要杀任何的联合程序。
The ps aux | grep mozilla command could then help you identify the process(es) that you need to kill.
ps aux| grep mozilla 然后指令可以辅助你识别程序 (es) 你需要杀。
who and w
If you want to know what users are currently logged into your system, use the who command or the w command.
如果你想要知道,使用者现在进入你的系统之内被纪录的,使用指令或者 w 命令谁。
This can help you identify the usernames of those who are logged in, their terminal connections, their times of login, and the processes that they are running.
On The Job  If you suspect that a username has been compromised, use the w command to check currently logged-on users.
在作业上,如果你怀疑一个使用者名称已经被妥协处理,使用 w 指令现在检查登入使用者。
Look at the terminal.
If the user is in the office but the terminal indicates a remote dial-in connection, be suspicious.
The w command can also identify the current process being run by that user.
w 指令也能识别被那一个使用者管理的目前的程序。
Sometimes you may not know the exact name of the file or the exact search term.
That is when a wildcard is handy.
The basic wildcards are shown in Table 1-4.
基本的取代字符在表 1-4 被显示。
Table 1-4:Wildcards in the Shell  Wildcard
表 1-4:在外壳取代字符中的取代字符
Any number of alphanumeric characters (or no characters at all).For example, the ls ab* command would return the following filenames, assuming they exist in the current directory:ab, abc, abcd.
一些文数字符.(或没有字符全然)举例来说, ls ab* 指令会返回下列的档名,假定他们在目前的目录中存在:ab 、 abc,abcd。
One single alphanumeric character: For example, the ls ab?command would return the following filenames, assuming they exist in the current directory:abc, abd, abe.
一个独身者文数字符:举例来说, ls ab? 指令会返回下列的档名, 傲慢的他们在目前的目录中存在: abc 、 abd,abe。
A range of options. For example, the ls ab[123] command would return the following filenames, assuming they exist in the current directory: ab1, ab2, ab3.Alternatively, the ls ab[X-Z] command would return the following filenames, assuming they exist in the current directory: abX, abY, abZ.
多种的选择项。举例来说, ls ab[123] 指令会返回下列的档名,假定他们在目前的目录中存在: ab 1 、 ab 2,ab 3.二者择一地, ls ab[X-Z] 指令会返回下列的档名,假定他们在目前的目录中存在:abX 、 abY,abZ。
On The Job  Wildcards are sometimes known in the Linux world as globbing.
在作业取代字符上有时当做小滴在 Linux 世界中被知道。

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复


【数字转型 架构重塑】2021年5月20日-22日第十三届中国系统架构师大会将在云端进行网络直播。



北京盛拓优讯信息技术有限公司. 版权所有 16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP