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

📄 ch21_10.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 21] 21.10 Keep a Directory Listing at Top of the Screen: dirtop </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:40:11Z"><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="ch21_01.htm"TITLE="21. More About Managing Files"><LINKREL="prev"HREF="ch21_09.htm"TITLE="21.9 Keep File Printouts Up-to-Date Automatically with make"><LINKREL="next"HREF="ch21_11.htm"TITLE="21.11 Safer Removing, Moving, and Copying "></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="ch21_09.htm"TITLE="21.9 Keep File Printouts Up-to-Date Automatically with make"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 21.9 Keep File Printouts Up-to-Date Automatically with make"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 21<BR>More About Managing Files</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch21_11.htm"TITLE="21.11 Safer Removing, Moving, and Copying "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 21.11 Safer Removing, Moving, and Copying "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-5930">21.10 Keep a Directory Listing at Top of the Screen: dirtop </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-23486"></A><ACLASS="indexterm"NAME="AUTOID-23489"></A>When I'm cleaning out a directory, I'm always using <EMCLASS="emphasis">ls</EM> tosee what files are there.When I have a terminal with windows, I can keep an <EMCLASS="emphasis">ls</EM> listing inone window and do cleanup in another.In a terminal without windows, I use this script named <EMCLASS="emphasis">dirtop</EM>.It clears the screen, puts an <EMCLASS="emphasis">ls</EM> listing at the top of the screen,and sends an<SPANCLASS="link">escape sequence (<ACLASS="linkend"HREF="ch05_08.htm"TITLE="Terminal Escape Sequences ">5.8</A>)</SPAN>to the terminal that makes the screen topnonscrolling.So, as I type my commands, they scroll &quot;underneath&quot; the <EMCLASS="emphasis">ls</EM> listingat the top without disturbing it.If I use a command like <EMCLASS="emphasis">vi</EM> that resets the screen, I just use<EMCLASS="emphasis">dirtop</EM> again when the command is done.When I'm done, the command <EMCLASS="emphasis">dirtop -c</EM> clears the screen andmakes the whole screen scrollable again.</P><PCLASS="para">This script works only on VT100-type terminals and compatiblesbecause the escape sequences are hardcoded into it.It should probably be rewritten to use <EMCLASS="emphasis">termcap</EM> or <EMCLASS="emphasis">terminfo</EM> information so it'd work on more terminals.Luckily, there are lots of VT100-compatible terminals and communicationsprograms.</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist">&#13;<ACLASS="co"HREF="ch46_10.htm"TITLE="46.10 A Portable echo Command ">THE...</A> <ACLASS="co"HREF="ch45_35.htm"TITLE="45.35 Using a Control Character in a Script ">echo...33'</A> <ACLASS="co"HREF="ch45_31.htm"TITLE="45.31 Nested Command Substitution ">`..`</A> &#13;</PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">&#13;#! /bin/shls=&quot;/bin/ls -CF&quot;                # ls command to usemaxlines=10     # if more lines in listing than this, quit# UNCOMMENT THE LINE FOR YOUR SYSTEM:cmd=echo   c='\c'   e='\033'   n=                       # SysV#cmd=/usr/5bin/echo   c='\c'   e='\033'   n=            # SunOS#cmd=/bin/echo   c=   e=&quot;`echo e | tr e '\033'`&quot;   n=-n # BSDcase &quot;$1&quot; in-c) $cmd $n &quot;${e}[r${e}[2J${c}&quot;; exit 0;; # just reset screen&quot;&quot;) ;;*) echo &quot;Usage: `basename $0` [-c]&quot; 1&gt;&amp;2; exit 1 ;;esactemp=/tmp/DIRTOP$$trap 'rm -f $temp; exit' 0 1 2 15$ls &gt; $temp# set number of lines to clear: one more than length of ls listing:lines=`expr 1 + \`wc -l &lt; $temp\``if [ $lines -gt $maxlines ]then    echo &quot;`basename $0`: Directory listing &gt; $maxlines lines&quot; 1&gt;&amp;2    exit 1else    # CLEAR SCREEN.  SET NO-SCROLL AREA:    $cmd $n &quot;${e}[2J${c}&quot;    $cmd $n &quot;${e}[${lines};24r${c}&quot;    # MOVE CURSOR TO TOP-LEFT CORNER, THEN PRINT LISTING:    $cmd $n &quot;${e}[0;0f${c}&quot;    cat $temp    exitfi</PRE></TD></TR></TABLE></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JP</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="ch21_09.htm"TITLE="21.9 Keep File Printouts Up-to-Date Automatically with make"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 21.9 Keep File Printouts Up-to-Date Automatically with make"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="ch21_11.htm"TITLE="21.11 Safer Removing, Moving, and Copying "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 21.11 Safer Removing, Moving, and Copying "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">21.9 Keep File Printouts Up-to-Date Automatically with make</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">21.11 Safer Removing, Moving, and Copying </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 + -