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

📄 0053-0055.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="0050-0052.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0056-0058.html">Next</A>

</CENTER></P>



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





<P><B>

Specifying Other Directories

</B></P>



<P>You can also use the ls command to view the contents of other directories by

specifying the directory, or pathname, on the command line. For example, if you want to see all

the files in the /usr/bin directory, use

</P>



<!-- CODE //-->

<PRE>

# ls /usr/bin

arch           dd             gzip           netstat        stty

ash            df             hostname       nisdomainname  su

awk            dmesg          kill           ping           sync

basename       dnsdomainname  ksh            ps             tar

bash           doexec         ln             pwd            tcsh

bsh            domainname     login          red            touch

cat            echo           ls             rm             true

chgrp          ed             mail           rmdir          umount

chmod          egrep          mkdir          rpm            uname

chown          false          mknod          sed            ypdomainname

cp             fgrep          more           setserial      zcat

cpio           gawk           mount          sh

csh            grep           mt             sleep

date           gunzip         mv             sort

</PRE>

<!-- END CODE //-->



<P>The ls command also supports using wildcards, or regular expressions, which means

you can use options similar to (and much more complex than) the examples you've seen

with the find and locate commands. For example, if you only want to search for text files in

the current directory, you can use

</P>



<!-- CODE SNIP //-->

<PRE>

# ls *.txt

</PRE>

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



<P>Finally, if you want to see all of the files on your system, you can use the

ls -R option, which recursively descends directories to show you the contents. Although you can use

this approach to search for files and build a catalog of the files on your system, you should

</P>



<P>be warned that it might take several minutes to list your files. The listing may also include

files you don't want listed, or files on other operating system filesystems, such as DOS

or Windows, especially if you use

</P>



<!-- CODE SNIP //-->

<PRE>

# ls -R /

</PRE>

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



<P>A better approach might be to use the -d option with

-R to list only a certain number of directory levels. For example, the following command will search three directory

levels along the root or / directory:

</P>



<!-- CODE SNIP //-->

<PRE>

# ls -Rd /*/*/*

</PRE>

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



<P>However, there's a much better utility for getting a picture of the directory structure of

your system, the tree command, which is discussed later in this hour.

</P>



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





<TABLE BGCOLOR=#FFFF99><TR><TD>JUST A MINUTE</TD></TR><TR><TD>

<BLOCKQUOTE>

Do you like how ls -aF shows your directories? Or would you prefer

ls to use colors all the time? If you want the ls command to always show this sort

of detail, see Hour 6.

</BLOCKQUOTE></TD></TR></TABLE>





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

Listing Directories with the dir and vdir Commands

</A></H4>



<P>If you just can't get the hang of using ls to list your directories, you can use the

dir or vdir commands. These commands have only about 45 command-line options, compared to

ls's over 75, but they're just as capable. They work like

ls, but with certain defaults.

</P>



<P>The dir command works like the default ls command, listing the files in sorted columns,

for example:

</P>



<!-- CODE SNIP //-->

<PRE>

# dir

News          axhome        nsmail        search

author.msg    documents     reading       vultures.msg

auto          mail          research

</PRE>

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



<P>The vdir command works like the ls -l option, and presents a long format listing by

default, for example:

</P>



<!-- CODE //-->

<PRE>

# vdir

total 15

drwxr-xr-x   2 bball    bball        1024 Nov 12 08:20 News

-rw-rw-r--   1 bball    bball        4766 Nov 12 07:41 author.msg

drwxrwxr-x   2 bball    bball        1024 Nov  5 10:04 auto

drwxrwxr-x   3 bball    bball        1024 Nov 12 13:54 axhome

drwxrwxr-x   2 bball    bball        1024 Nov 12 15:13 documents

drwx------   2 bball    bball        1024 Nov 12 14:02 mail

drwx------   2 bball    bball        1024 Sep 15 01:57 nsmail

drwxrwxr-x   2 bball    bball        1024 Oct 29 20:28 reading

drwxrwxr-x   5 bball    bball        1024 Nov  5 10:03 research

-rwxrwxr-x   1 bball    bball         200 Oct 24 13:24 search

-rw-rw-r--   1 bball    bball         801 Nov 11 22:46 vultures.msg

</PRE>

<!-- END CODE //-->



<P>Although you won't find separate manual pages for

dir or vdir (they're mentioned in the ls man page), you can get help with each command by using the

--help option.

</P>



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

Graphic Directory Listings with the tree Command

</A></H4>



<P>You now know how to list the contents of your directories, but you may also be

interested in the directory structure of your system, or the directory structure of a particular tree

of your system (such as /usr/X11R6). For example, ls

-R will recursively print out your directories, but how are these directories related to each other? If you would like a more

direct, graphical view of your directories, a directory listing utility can help.

</P>



<P>Steve Baker's tree utility will print a graphic view of any desired structure, and it has

several handy features. First, tree's syntax, or command-line, options are similar to several of

those for the ls command. Wildcards or expressions are supported. The tree command also

</P>





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







<P>supports color in its listings, like ls. Finally,

tree has a -x option similar to the find command's

-xdev option, so you don't have to get a directory picture of operating systems if you

choose to start your listing with the root or / directory.

</P>







<P>The tree command is easy to use. For example, if you would like to see the contents of

the /var/lib directory, along with all files, try the following:

</P>



<!-- CODE //-->

<PRE>

# tree /var/lib

/var/lib

|-- alien

|   |-- applix-english_4.3-2.diff.gz

|   |-- applix_4.2-2.diff.gz

|   `-- applix_4.3-2.diff.gz

|-- games

|-- locatedb

|-- logrotate.status

|-- rpm

|   |-- conflictsindex.rpm

|   |-- fileindex.rpm

|   |-- groupindex.rpm

|   |-- nameindex.rpm

|   |-- packages.rpm

|   |-- providesindex.rpm

|   `-- requiredby.rpm

`-- texmf

    |-- fonts

    |   `-- pk

    |       `-- ljfour

    |           `-- public

    |               `-- cm

    |                   |-- cmbx10.600pk

    |                   |-- cmbx10.720pk

    |                   |-- cmbx10.840pk

    |                   |-- cmmi10.600pk

    |                   |-- cmmi10.720pk

    |                   |-- cmr10.420pk

    |                   |-- cmr10.480pk

    |                   |-- cmr10.600pk

    |                   |-- cmsy10.480pk

    |                   |-- cmsy10.600pk

    |                   |-- cmti10.600pk

    |                   `-- cmtt10.600pk

    `-- texfonts



10 directories, 24 files

</PRE>

<!-- END CODE //-->



<P>The tree command also has a handy -d option to list only directories, and not files

(unlike ls). This is one of the best ways to get an idea of what your Linux file system looks like

from a directory standpoint. You can also use it to view the directory structure of

installed software. For example, to see what is on your system after installing the Netscape

Web browser, try

</P>





<!-- CODE SNIP //-->

<PRE>

# tree -d /usr/local/netscape

</PRE>

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



<P><CENTER>

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

</CENTER></P>











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

<!-- begin footer information -->









</body></html>

⌨️ 快捷键说明

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