⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0047-0049.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:




<HTML>

<HEAD>

<TITLE>Sams Teach Yourself Linux in 24 Hours:Reading and Navigation Commands:EarthWeb Inc.-</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311623 //-->

<!-- TITLE=Sams Teach Yourself Linux in 24 Hours//-->

<!-- AUTHOR=Bill Ball//-->

<!-- PUBLISHER=Macmillan Computer Publishing//-->

<!-- IMPRINT=Sams//-->

<!-- CHAPTER=04 //-->

<!-- PAGES=0041-0062 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->











<P><CENTER>

<a href="0041-0046.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0050-0052.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-47"><P>Page 47</P></A>







<P>you'll see

</P>



<!-- CODE SNIP //-->

<PRE>

/usr/bin

</PRE>

<!-- END CODE SNIP //-->



<P>Although there's a man page for the pwd command, chances are that when you use

pwd, you're using a pwd built into your shell. How do you tell? If you try calling

pwd with the following command, you should see only the current working directory printed:

</P>



<!-- CODE SNIP //-->

<PRE>

# pwd --help

</PRE>

<!-- END CODE SNIP //-->



<P>Instead, try calling pwd with

</P>



<!-- CODE SNIP //-->

<PRE>

# /bin/pwd --help

</PRE>

<!-- END CODE SNIP //-->



<P>You'll see a short help file for the pwd command, and not the current directory.

</P>



<H4><A NAME="ch04_ 8">

Searching Directories for Matching Files with the

find Command

</A></H4>



<P>The find command is a powerful searching utility you can use to find files on your hard

drive. You can search your hard drive for files easily with a simple

find command line. For example, to search for the

spell command under the /usr directory, you would use

</P>



<!-- CODE SNIP //-->

<PRE>

# find /usr -name spell -print

</PRE>

<!-- END CODE SNIP //-->



<P>You can also use the find command to find files by date; you can also specify a range of

times. For example, to find programs in the

/usr/bin directory that you have not used in the last

one hundred days, you can try:

</P>



<!-- CODE SNIP //-->

<PRE>

# find /usr/bin -type f -atime +100 -print

</PRE>

<!-- END CODE SNIP //-->



<P>To find any files, either new or modified, that are one or fewer days old in the

/usr/bin directory, you can use

</P>



<!-- CODE SNIP //-->

<PRE>

# find /usr/bin -type f -mtime -1 -print

</PRE>

<!-- END CODE SNIP //-->



<P>The find command will also accept wildcards, which you'll learn about in Hour

5, &quot;Manipulation and Searching Commands.&quot; As a simple example, you can use

find to show you all the PostScript files (which you'll learn about in &quot;Understanding Graphics

Formats&quot; in Hour 16, &quot;Graphics Tools&quot;) in your

/usr directory with

</P>



<!-- CODE SNIP //-->

<PRE>

# find /usr -name `*.ps' -print

</PRE>

<!-- END CODE SNIP //-->



<P>You should also know about one of the find command's handy options,

-xdev. The examples so far show searches limited to the

/usr directory. But what if you want to search

starting at the root or / directory? Without using

-xdev, which limits searches to the current

filesystem (in this case, Linux), find will merrily continue its search through any mounted

CD-ROMs, or your DOS or Windows partition, possibly finding files you're not interested in,

slowing down the search, and cluttering up the search printout.

</P>





<A NAME="PAGENUM-48"><P>Page 48</P></A>



<P>The find command has many different options and uses. For more details about

find, see its manual page. Although find will rapidly search your hard drive (and any other

filesystems), there are other ways of quickly finding files, especially programs. Read on to find out more!

</P>



<H4><A NAME="ch04_ 9">

Finding Files with the whereis Command

</A></H4>



<P>The whereis command can quickly find files, and it also shows you where the file's

binary, source, and manual pages reside. For example, the following command shows that the

find command is in the /usr/bin directory, and its man page is in the

/usr/man/man1 directory:

</P>



<!-- CODE SNIP //-->

<PRE>

# whereis find

find: /usr/bin/find /usr/man/man1/find.1

</PRE>

<!-- END CODE SNIP //-->



<P>You can also use whereis to find only the binary version of the program with

</P>



<!-- CODE SNIP //-->

<PRE>

# whereis -b find

find: /usr/bin/find

</PRE>

<!-- END CODE SNIP //-->



<P>If whereis cannot find your request, you'll get an empty return string, for example:

</P>



<!-- CODE SNIP //-->

<PRE>

# whereis foo

foo:

</PRE>

<!-- END CODE SNIP //-->



<P>Part of the problem could also be that the file is not in any of the directories the

whereis command searches. The directories whereis looks in are hard-coded into the

program. Although this may seem like a drawback, limiting searches to known directories such

as /usr/man, /usr/bin, or /usr/sbin can speed up the task of finding files.

</P>



<P>Although whereis is faster than using find to locate programs or manual pages, there's

an even faster search utility you can use, called

locate, discussed in the next section.

</P>



<H4><A NAME="ch04_ 10">

Locating Files with the locate Command

</A></H4>



<P>One way to speed up searches for files is not to search your file directories! You can

do this by using a program like locate, which uses a single database of filenames and

locations, and which saves time by looking in a single file instead of traversing your hard

drive. Finding a file using locate is much faster than the

find command because locate will go directly to the database file, find any matching filenames, and print its results.

</P>





<P>Locate is easy to use. For example, to find all the PostScript files on your system, you

can enter

</P>



<!-- CODE SNIP //-->

<PRE>

# locate *.ps

</PRE>

<!-- END CODE SNIP //-->



<P>Almost instantly, the files are printed to your screen. You may even

find the locate command line a little easier to use than the

find command. However, there is a catch: find will

work &quot;right out of the box,&quot; whereas with

locate, you need to first build a database of all the

files on your system. But don't worry, because the procedure is almost automatic.

</P>



<A NAME="PAGENUM-49"><P>Page 49</P></A>





<P>After you install Linux, locate can't show any search results because it can't locate

its database. To create this database, you'll need to use the

updatedb command. Make sure you're logged in as the root operator (or use the

su command; see Hour 20, &quot;Basic System Administration&quot;). At the prompt, enter

</P>



<!-- CODE SNIP //-->

<PRE>

# updatedb

</PRE>

<!-- END CODE SNIP //-->



<P>It may take a minute or so for the updatedb command to finish its work, but when it's

done, locate's database, locatedb (about 300,000 characters in size for 400MB worth of files),

will reside in the /var/lib directory. The only downside to using the

locate command is that after time, its database could become out of date as you add or delete files to your

system. However, you can have its database updated automatically; see the command

reference section at the end of this hour.

</P>



<H4><A NAME="ch04_ 11">

Getting Command Summaries with whatis and apropos

</A></H4>



<P>As you first explore your Linux system, you may come across programs whose

function is not clear. Many Linux programs are designed to give at least a little help with a

? or -help option on the command line, but you generally shouldn't run a program without

knowing what it does.

</P>



<P>The whatis command may be able to help you quickly find out what a program is with

a summary line derived from the program's manual page. For example, to find out what

is whereis (not whereis whatis!), you can enter

</P>



<!-- CODE SNIP //-->

<PRE>

# whatis whereis

whereis (1)- locate the binary, source, and manual page files for a command

</PRE>

<!-- END CODE SNIP //-->



<P>However, as with the locate command, you must first build a database of the

command summaries with the makewhatis command, found under the

/usr/sbin directory. To do this, make sure you're logged in as

root, and enter

</P>



<!-- CODE SNIP //-->

<PRE>

# makewhatis

</PRE>

<!-- END CODE SNIP //-->





<P>The makewhatis command, like the updatedb command, will take a few minutes to build the

whatis database, which, unlike locate's, is called

whatis and is found under the /usr/man/man1

directory. The makewhatis command has several options, but it does not have a manual page. To

see a quick summary, use

</P>



<!-- CODE SNIP //-->

<PRE>

# makewhatis -?

</PRE>

<!-- END CODE SNIP //-->



<P>Also, as with locate's database, you'll need to periodically update the

whatis database to keep track of any newly installed programs.

</P>



<P>So far, you've seen how whereis and whatis can help you find programs or figure out what

they</P>





<P><CENTER>

<a href="0041-0046.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0050-0052.html">Next</A>

</CENTER></P>











</td>
</tr>
</table>

<!-- begin footer information -->









</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -