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

📄 ch16_03.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 16] 16.3 Reordering ls Listings </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:37:37Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch16_01.htm"TITLE="16. Where Did I Put That?"><LINKREL="prev"HREF="ch16_02.htm"TITLE="16.2 Finding Oldest or Newest Files with ls -t and ls -u "><LINKREL="next"HREF="ch16_04.htm"TITLE="16.4 List All Subdirectories with ls -R "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch16_02.htm"TITLE="16.2 Finding Oldest or Newest Files with ls -t and ls -u "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 16.2 Finding Oldest or Newest Files with ls -t and ls -u "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 16<BR>Where Did I Put That?</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch16_04.htm"TITLE="16.4 List All Subdirectories with ls -R "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 16.4 List All Subdirectories with ls -R "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1571">16.3 Reordering ls Listings </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-16767"></A>In the<SPANCLASS="link">previous tutorial (<ACLASS="linkend"HREF="ch16_02.htm"TITLE="Finding Oldest or Newest Files with ls -t and ls -u ">16.2</A>)</SPAN>,I introduced you to several different waysof sorting <EMCLASS="emphasis">ls</EM>' output, based on file time. There was oneconstant: <EMCLASS="emphasis">ls</EM> listings were always from first (most recent) tolast, moving (first) down each column and then across the page.</P><PCLASS="para">That's often not the most convenient way to look at the world.For example, if you're going to look at a directory with many, manyfiles, it might be easier to list the files <EMCLASS="emphasis">across</EM> the screenfirst, and then down. This would be particularly nice if you'reusing a pager (like <EMCLASS="emphasis">pg</EM> or<SPANCLASS="link"><EMCLASS="emphasis">more</EM> (<ACLASS="linkend"HREF="ch25_03.htm"TITLE="Using more to Page Through Files ">25.3</A>)</SPAN>)to read the listing.Then the first screenful will show the files at the top of the list.Here's an example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">jerry@ora ~/.bin59 % <CODECLASS="userinput"><B>ls -x | pg</B></CODE>README        alifile       append        c-w           cgrepcrontab       cw            cx            dirtop        distprompterdrmm          echoerr       fixsubj       fols          inccincs          maillog       mhadd         mhprofile     pickthisrecomp        reheader      replf         rfl           rhnorhyes         rmmer         rn2mh         rtfm          saveartscandrafts    showmult      showpr        tcx           tofromunshar        weather       which         xmhprint      zfolderszloop         zrefile       zscan</PRE></BLOCKQUOTE></P><PCLASS="para">&#13;This listing is &quot;alphabetic&quot;-not sorted by time.So <EMCLASS="emphasis">README</EM> is first in the list (uppercase comesbelow lowercase), and <EMCLASS="emphasis">alifile</EM> is next to it.<ACLASS="indexterm"NAME="AUTOID-16783"></A>The <EMCLASS="emphasis">-x</EM> flag makes the outputmulti-column.BSD doesn't have <EMCLASS="emphasis">-x</EM>.To get the same sorting order under BSD, pipe <EMCLASS="emphasis">ls</EM> outputthrough the<SPANCLASS="link"><EMCLASS="emphasis">cols</EM> (<ACLASS="linkend"HREF="ch35_16.htm"TITLE="Make Columns Automatically with cols ">35.16</A>)</SPAN>script.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-16792"></A>Both BSD and System V have the <EMCLASS="emphasis">-C</EM> option; it sortsfilenames down columns instead of across.In fact, <EMCLASS="emphasis">-C</EM> is the default on BSD when you <EMCLASS="emphasis">aren't</EM>redirecting the output of <EMCLASS="emphasis">ls</EM>.If BSD <EMCLASS="emphasis">ls</EM> detects that it's writing anywhere other thana terminal, it defaults to single-column output, rather than multi-column.Under BSD, you'll need to use <EMCLASS="emphasis">-C</EM> (or another techniquelike the <EMCLASS="emphasis">cols</EM> script or <SPANCLASS="link"><EMCLASS="emphasis">pr&nbsp;-number</EM> (<ACLASS="linkend"HREF="ch35_17.htm"TITLE="Making Text in Columns with pr ">35.17</A>)</SPAN>)to get output in columns when you pipe <EMCLASS="emphasis">ls</EM> output.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-16806"></A>The <EMCLASS="emphasis">-r</EM> option lists the files in reverse order.I find this particularly useful when I'm looking at modification times.Because <EMCLASS="emphasis">-t</EM> shows files by modification time, newest first&nbsp;- using<EMCLASS="emphasis">-tr</EM> shows files by modification time, oldest first:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">jerry@ora ~/.bin 61 % <CODECLASS="userinput"><B>ls -tr</B></CODE>echoerr       replf         zscan         c-w           dirtopsaveart       xmhprint      zrefile       cx            cgreprtfm          distprompter  reheader      maillog       pickthisREADME        fixsubj       drmm          rfl           rhyesappend        mhadd         incc          showpr        rhnofols          rmmer         tofrom        zloop         crontabmhprofile     rn2mh         scandrafts    unshar        weatherrecomp        alifile       showmult      tcxincs          zfolders      cw            which</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-16816"></A>Adding the <EMCLASS="emphasis">-u</EM> option shows theleast recently accessed files first:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">jerry@ora ~/.bin63 % <CODECLASS="userinput"><B>ls -tur</B></CODE>README        maillog       which         mhadd         tofromalifile       replf         zfolders      crontab       tcxappend        reheader      zloop         recomp        showmultcgrep         rhyes         xmhprint      distprompter  mhprofiledirtop        rhno          zscan         cw            rmmerfixsubj       showpr        zrefile       cx            rflechoerr       scandrafts    drmm          c-w           rtfmfols          saveart       incc          weatherincs          unshar        pickthis      rn2mh</PRE></BLOCKQUOTE></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</SPAN>, <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch16_02.htm"TITLE="16.2 Finding Oldest or Newest Files with ls -t and ls -u "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 16.2 Finding Oldest or Newest Files with ls -t and ls -u "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch16_04.htm"TITLE="16.4 List All Subdirectories with ls -R "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 16.4 List All Subdirectories with ls -R "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">16.2 Finding Oldest or Newest Files with ls -t and ls -u </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">16.4 List All Subdirectories with ls -R </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

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