old-www/LDP/espk-ug/html/working-with-files.html

555 lines
11 KiB
HTML

<HTML
><HEAD
><TITLE
>Working with files</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="Emacspeak User's Guide"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="System Administration"
HREF="system-administration.html"><LINK
REL="NEXT"
TITLE="Working online"
HREF="working-online.html"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Emacspeak User's Guide</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="system-administration.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="working-online.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="working-with-files">5. Working with files</H1
><P
>In addition to performing common file manipulation tasks, such as moving, copying, and deleting, you'll also want to download files from the Internet, search for files in your directories, and FTP files. Some of these functions are built into Emacs, while some of these tasks require additional applications that can be downloaded.</P
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="downloading-files">5.1. Downloading files</H2
><P
>Once you know the URL of the file to download, you can use the <B
CLASS="command"
>wget</B
> command from within the Emacs shell to retrieve the file. If you do not know the URL of the file to download, use the <SPAN
CLASS="application"
>W3</SPAN
> application to browse the web and find the URL of the file (refer to <A
HREF="working-online.html#browsing-the-internet"
>Browsing the Internet</A
> for information on using the <SPAN
CLASS="application"
>W3</SPAN
> application). Then use the command <B
CLASS="command"
>wget</B
> to download it. For more information on the <B
CLASS="command"
>wget</B
> command, refer to the <B
CLASS="command"
>wget</B
> man page.</P
><P
>To download a file:</P
><P
></P
><OL
TYPE="1"
><LI
><P
>From inside Emacs, type <B
CLASS="command"
>M-x shell</B
> to start the shell.</P
></LI
><LI
><P
>Since the <B
CLASS="command"
>wget</B
> command places the downloaded file into your current directory, change directories to the desired directory.</P
></LI
><LI
><P
>When you are in the appropriate directory, type <B
CLASS="command"
>wget [url]</B
>, then press <SPAN
CLASS="keysym"
>Enter</SPAN
>. Remember that you can copy and paste the URL of the file to download from the <SPAN
CLASS="application"
>W3</SPAN
> web browser application.</P
></LI
></OL
><P
>As the file is being downloaded, one dot appears on the screen for each kilobyte of data received. The <B
CLASS="command"
>wget</B
> command lets you know when the download is complete.</P
><P
>Another option for downloading (or uploading) a file is via FTP. Refer to <A
HREF="working-with-files.html#ftping-a-file"
>FTPing a file</A
> for more information.</P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="find-a-file">5.2. Finding a file</H2
><P
>There are several ways you can find a file. This section discusses two options.</P
><P
>If you know the name of the file, or at least remember part of it, you can use the <B
CLASS="command"
>find-file</B
> command:
</P
><P
></P
><OL
TYPE="1"
><LI
><P
>In Emacs, type <B
CLASS="command"
>M-x find-file</B
>.</P
><P
>Result: You will be prompted for the name of the file in the default working directory.</P
></LI
><LI
><P
>Type the name of the file (or use wildcards) you wish to find.</P
></LI
></OL
><P
>Alternatively, you may want to browse your directories to lookfor a file. You can do this using the Emacs directory editor,<SPAN
CLASS="application"
>dired</SPAN
>. To start <SPAN
CLASS="application"
>dired</SPAN
>: </P
><P
></P
><OL
TYPE="1"
><LI
><P
>In Emacs, type <B
CLASS="command"
>C-x d</B
> or <B
CLASS="command"
>M-x dired</B
>. You will be prompted for the name of the file. You can type the name (or part of the name) of the file to find, using the Tab key to complete the file name. <SPAN
CLASS="application"
>dired</SPAN
> will list any files that match the name you entered. Alternatively, you can view a full listing of the directory by providing a directory name (or pressing Return to view the current directory) when prompted.</P
></LI
></OL
><P
>For more information on using the directory editor, refer to <A
HREF="working-with-files.html#using-the-directory-editor"
>Using the directory editor</A
>. For a complete listing of <SPAN
CLASS="application"
>dired's</SPAN
> features and capabilities, refer to <A
HREF="http://www.delorie.com/gnu/docs/emacs/emacs_360.html"
TARGET="_top"
>http://www.delorie.com/gnu/docs/emacs/emacs_360.html</A
>.</P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="ftping-a-file">5.3. FTPing a file</H2
><P
>Emacs contains a built-in file transfer protocol, or FTP,application. The FTP application can be used to upload and download files to and from other machines. In order to use FTP, you will need to know the hostname of the machine to contact.</P
><P
>To invoke the FTP application:</P
><P
></P
><OL
TYPE="1"
><LI
><P
>Within Emacs, type <B
CLASS="command"
>M-x ftp</B
>.</P
><P
>Result: You will be prompted for an ftp hostname.</P
></LI
></OL
><P
>Alternatively, you can start an Emacs shell using <B
CLASS="command"
>M-x shell</B
> and use FTP from the command line. There is a short tutorial on using the command line FTP at
<A
HREF="http://unix.about.com/library/weekly/aa121800a.htm?once=true"
TARGET="_top"
>Focus on Unix</A
>.</P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="file-manipulation">5.4. Manipulating files</H2
><P
>This section contains information on moving, copying, and deleting files from within Emacs. In general, there are two ways you can go about these tasks. One option is to use the command line from an Emacs shell, and the other is to use <SPAN
CLASS="application"
> dired</SPAN
>. Both methods are discussed in this section.</P
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="using-the-command-line">5.4.1. Using the command line</H3
><P
>If you are familiar with Unix command-line arguments, you may prefer to use the command line to manipulate files. To use the command line, open an Emacs command shell using <B
CLASS="command"
>M-x shell</B
>. The following list shows some basic file manipulation commands and what they do:</P
><P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><B
CLASS="command"
>cp <TT
CLASS="filename"
>file1 file2</TT
></B
></DT
><DD
><P
>Copies file1 to a new filenamed file2.</P
></DD
><DT
><B
CLASS="command"
>mv <TT
CLASS="filename"
>sourcetarget</TT
></B
></DT
><DD
><P
>Moves a file from the source directory to the target directory.</P
></DD
><DT
><B
CLASS="command"
>rm <TT
CLASS="filename"
>file</TT
></B
></DT
><DD
><P
>Deletes a file.</P
></DD
><DT
><B
CLASS="command"
>mkdir <TT
CLASS="filename"
>directoryname</TT
></B
></DT
><DD
><P
>Creates a directory with the name <TT
CLASS="filename"
>directoryname</TT
>.</P
></DD
><DT
><B
CLASS="command"
>rmdir <TT
CLASS="filename"
>directoryname</TT
></B
></DT
><DD
><P
>Deletes the directorym <TT
CLASS="filename"
>directoryname</TT
> if it is empty.</P
></DD
><DT
><B
CLASS="command"
>ls</B
></DT
><DD
><P
>Lists all the files in th ecurrent directory.</P
></DD
></DL
></DIV
><P
>You can find more information on any of these commands (most can be run with various options that allow for more user control) by looking them up in the online man pages. Since the list presented here covers only the most basic commands, you may want to consult the Linux user's guide, available at <A
HREF="http://www.ibiblio.org/pub/Linux/docs/linux-doc-project/users-guide/"
TARGET="_top"
>http://www.ibiblio.org/pub/Linux/docs/linux-doc-project/users-guide/</A
>, for more information.</P
></DIV
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="using-the-directory-editor">5.4.2. Using the directory editor</H3
><P
>Although many Linux users use the command line to manipulate files, Emacs provides a powerful alternative, called <SPAN
CLASS="application"
>dired</SPAN
>. <SPAN
CLASS="application"
>Dired</SPAN
> is the Emacs directory editor, and is great for manipulating files if you'd rather not use the command line or aren't familiar with it. To start <SPAN
CLASS="application"
>dired</SPAN
>:</P
><P
></P
><OL
TYPE="1"
><LI
><P
>In Emacs, type <B
CLASS="command"
>M-x dired</B
>. You will be prompted for the directory to open.</P
></LI
><LI
><P
>Type in the directory to display, or press <SPAN
CLASS="keysym"
>Return</SPAN
> to open the default directory.</P
></LI
></OL
><P
>Once you've started <SPAN
CLASS="application"
>dired</SPAN
>, you can move around in the Emacs buffer to have the file names, permissions, owners, sizes, and dates created/edited read aloud.</P
><P
>In dired, some commands mark files for manipulation (for example, you can mark several files, then delete them all), and some commands (such as the copy command) are executed immediately. Note that, in dired, case does make a difference for many commands. Some of the more common <SPAN
CLASS="application"
>dired</SPAN
> commands and what they do are listed below:</P
><P
></P
><DIV
CLASS="variablelist"
><DL
><DT
>press the <B
CLASS="command"
>Return</B
>key</DT
><DD
><P
>Pressing <B
CLASS="command"
>Return</B
> when the focus is on a particular file opens that file in the appropriate major mode.</P
></DD
><DT
><B
CLASS="command"
>d</B
></DT
><DD
><P
>Marks a single file for deletion, but doesn't actually delete the file. You can mark multiple files for deletion, then delete them all simultaneously.</P
></DD
><DT
><B
CLASS="command"
>u</B
></DT
><DD
><P
>If a file is marked for deletion, this option unmarks it.</P
></DD
><DT
><B
CLASS="command"
>x</B
></DT
><DD
><P
>Deletes all files marked for deletion. You will be prompted to make sure you want to delete the files in question; type <B
CLASS="command"
>yes</B
> or <B
CLASS="command"
>no</B
> as appropriate. </P
></DD
><DT
><B
CLASS="command"
>C</B
></DT
><DD
><P
>Copies a file. You will be asked for the name of the new file to create when you copy the old file.</P
></DD
><DT
><B
CLASS="command"
>R</B
></DT
><DD
><P
>Renames a file. You will be prompted for the name of the new file to create when you rename the file.</P
></DD
></DL
></DIV
><P
>Because <SPAN
CLASS="application"
>dired</SPAN
> is so extensive, including the full documentation for it here is not feasible. However, complete instructions can be found in the GNU Emacs Manual at <A
HREF="http://www.delorie.com/gnu/docs/emacs/emacs_360.html"
TARGET="_top"
>http://www.delorie.com/gnu/docs/emacs/emacs_360.html</A
>.</P
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="system-administration.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="working-online.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>System Administration</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Working online</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>