[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->] |
Sometimes, it's inevitable -- through no choice of your own, you must deal with a disk from another operating system, or a file with data stored in a proprietary format from one of these systems.
The recipes in this chapter are about converting data from other platforms -- reading disks from DOS, Windows, and MacOS systems, and converting DOS text and Microsoft Word files.
Debian: `mtools' WWW: http://mtools.linux.lu/
The mtools
package provides a collection of tools to facilitate
the manipulation of MS-DOS files. These tools allow you to use and
manipulate MS-DOS disks (usually floppies, but Jaz and Zip drives are
supported, too); they can handle the extensions to the MS-DOS format
which are used by the different Microsoft Windows operating systems,
including Windows NT.
The following recipes describe how to use some of the tools in this package to get directory listings of MS-DOS disks, copy files to and from them, delete files on them, and even format them. They're similar in use and syntax to the equivalent MS-DOS commands.
Use mdir
to get a directory listing of a DOS disk. Give as an
argument the "drive letter" of the disk to read, as used by DOS; for
example, to specify the primary floppy drive, use `A:' as the drive
to read, and use `B:' to specify the secondary floppy drive.
$ mdir a: [RET]
Use mcopy
to copy files to and from a DOS disk.
To copy a file to a DOS disk, give as arguments the name of the source file to copy and the "drive letter" of the disk to copy it to.
$ mcopy readme.txt a: [RET]
To copy a file from a DOS disk, give the "drive letter" of the
disk to copy from, followed by the file name to copy, and no other
arguments; mcopy
will copy the specified file to the current
directory.
$ mcopy b:resume.doc [RET]
To copy all files from a DOS disk, just give the "drive letter" without any file names.
$ mcopy a: [RET]
Use mdel
to delete a file on a DOS disk. Give as an argument the
name of the file to delete preceded by the "drive letter" of the disk
to delete from.
$ mdel a:resume.doc [RET]
To format a floppy disk for DOS, writing an empty MS-DOS filesystem to
the disk in the process, use mformat
. Give as an argument the
name of the "drive letter" of the disk to format. (Remember, when you
format a disk, any existing information contained on the disk is lost.)
$ mformat a: [RET]
NOTE: If you want to use a floppy disk with your Linux system and don't need DOS compatibility, don't bother using this MS-DOS format -- the native Linux format is much more efficient (see Formatting a Floppy Disk). If you know how long a DOS format takes, you'll be amazed at how much faster the Linux format is, too -- it will do it so fast you'll think it didn't work!
Debian: `hfsutils' WWW: http://www.mars.org/home/rob/proj/hfs/
Apple Macintosh computers use a file system called the "Hierarchical
File System," or HFS. The hfsutils
package contains a set of
tools to read and write disks in the HFS format.
The following recipes describe the use of the individual tools in this package.
To use a Macintosh disk with any of the `hfsutils' commands, you
must first use hmount
to specify the location of the HFS
filesystem. Give as an argument the name of the Linux device file where
the HFS filesystem exists; this virtually "mounts" the disk for use
with the other `hfsutils' described in this section.
The device file for the first floppy drive is `/dev/fd0', and for the second drive, `/dev/fd1'. Any valid device name, such as a SCSI device or Zip disk, may be given.
$ hmount /dev/fd0 [RET]
After you run this command, the other tools in the hfsutils
package will work on the Macintosh disk in the first floppy drive.
Use hls
to get a directory listing of the Macintosh disk
currently specified with hmount
(see Specifying the Macintosh Disk to Use).
$ hls [RET]
Give the name of a directory as a quoted argument.
$ hls 'Desktop Folder' [RET]
Use hcopy
to copy files to and from the Macintosh disk currently
specified with hmount
(see Specifying the Macintosh Disk to Use).
To copy a file to a Mac disk, give as arguments the name of the source file to copy and the quoted name of the target directory on the Mac disk.
$ hcopy readme.txt 'Desktop Folder' [RET]
To copy a file from a Mac disk, give the name of the directory and file to copy as a quoted argument, and the name of the target directory to copy to.
$ hcopy 'Desktop Folder:Readme' . [RET]
Use hdel
to delete a file on the Macintosh disk currently
specified with hmount
(see Specifying the Macintosh Disk to Use). Give as a quoted argument the path name of the file to
delete. It deletes both the resource fork and the data fork of the files
you specify.
$ hdel 'Desktop Folder:Readme' [RET]
To format a disk for the Mac, writing an empty HFS filesystem to the
disk, use hformat
. Give as an argument the name of the Linux
device file where the disk is at; for example, the device file for the
first floppy drive is `/dev/fd0', and the second drive is
`/dev/fd1'
$ hformat /dev/fd0 [RET]
If the disk currently has a partition on it, this command won't work; use the `-f' option to force the format, thus erasing any existing partition and data the disk contains.
Give a label for the drive as a quoted argument to the `-l' option. The label name can't contain a colon character (`:').
$ hformat -f /dev/fd0 [RET]
$ hformat -l 'Work Disk' /dev/fd1 [RET]
When a disk has multiple partitions, give the number of the partition to format as an additional argument. To format the entire medium, give `0' as the partition to use.
$ hformat /dev/sd2 2 [RET]
$ hformat -f -l "Joe's Work Disk" /dev/sd2 0 [RET]
Debian: `sysutils' WWW: http://web.singnet.com.sg/~cslheng/
In all versions of DOS (and all subsequent versions of Microsoft
Windows), text files are normally written with both a linefeed character
and a newline, both "invisible" control characters, to signify the end
of each line. In Linux and other unices, text files have only the
newline character.
In either of these operating systems, text files that originated from the other may display irregularly -- in DOS and Windows, the lines of a Linux text file may appear to run together; in Linux, a DOS or Windows text file may have `^M' newline characters at the end of each line.
To convert a text file from DOS to Linux, removing the `^M' newline characters in the file, use `fromdos'. It converts the file you give as an argument, removing the newline characters from the ends of all its lines.
To convert a text file from Linux to the convention used by DOS and
Windows, use todos
. It adds newline characters to the ends of all
lines in the file you give as an argument.
$ fromdos autoexec.bat [RET]
$ todos *.tex [RET]
NOTE: Both commands directly write to the files you specify. To make a backup of the original file, use the `-b' option; before the conversion, this writes a copy of each specified file with a `.bak' file name extension.
Debian: `word2x' WWW: http://word2x.alcom.co.uk/
Use word2x
to convert Word 6 files to a format you can read. It
can convert files to two different formats: LaTeX and plain text.
Convert to LaTeX when the layout of the original document,
including its formatting and font characteristics, is important. When
you just need the complete text of the document, convert it to
plain text. word2x
can send its output to the standard output, so
the latter conversion is useful for adding to a pipeline.
Word files usually have a `.doc' or `.DOC' extension, which you don't have to specify -- for example, if the Word file you want to convert is called `resume.doc', you can simply give `resume' as the source file. (But if there exists another file named `resume' in the same directory, this trick won't work).
If you don't specify an output file, word2x
writes its output to
a file with the same base file name and an appropriate extension for the
output format. This is useful for converting a lot of Word files in the
same directory -- specifying a wildcard such as `*.doc' as the input
and no output name will convert them all.
You can also set the maximum line width to be used in the output file; specify the width as an argument to the `-w' option.
The following recipes describe how to use word2x
to convert Word
files to LaTeX and plain text format.
NOTE: While word2x
does a pretty good job of conversion,
it won't convert any pictures embedded in Word documents.
Another way to read Word files is to import them into the AbiWord or StarWriter word processors (see Other Word Processors and Typesetting Systems).
To convert a Word file to LaTeX format, use word2x
and use
`latex' as an argument to the `-f' option.
$ word2x -f latex resume.doc [RET]
This command writes a new file, `resume.ltx', in the LaTeX format; you can then view, print, or convert the file to other formats -- see Processing LaTeX Files. The original `resume.doc' file is unaltered.
$ word2x -f latex -w 40 *.DOC [RET]
To convert a Word file to plain text, use word2x
, and use
`text' as an argument to the `-format' option.
$ word2x -f text resume.doc resume [RET]
To send a conversion to the standard output, give a hyphen character,
`-', as the output file to use. This is useful for piping the plain
text conversion to other tools that work on text, such as grep
, a
tool for searching text (see Searching for a Word or Phrase).
$ word2x resume.doc - | grep -i linux [RET]
These commands convert the Word file `resume.doc' to text, and output all lines of that text, if any, that contain the string `linux' regardless of case. The original `resume.doc' file is unaltered.
[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->]