Рейтинг@Mail.ru
[Войти] [Зарегистрироваться]

Наши друзья и партнеры

UnixForum






Книги по Linux (с отзывами читателей)

Библиотека сайта rus-linux.net

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27. Cross-Platform Conversions

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.

27.1 Using DOS and Windows Disks  Dealing with DOS and Windows disks.
27.2 Using Macintosh Disks  Dealing with MacOS disks.
27.3 Converting Text Files between DOS and Linux  Converting text files between DOS and Linux.
27.4 Converting Microsoft Word Files  Dealing with Microsoft Word files.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.1 Using DOS and Windows Disks

@sf{Debian}: `mtools'
@sf{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.

27.1.1 Listing the Contents of a DOS Disk  Listing the contents of DOS disks.
27.1.2 Copying Files to and from a DOS Disk  Copying files to and from DOS disks.
27.1.3 Deleting Files on a DOS Disk  Deleting files on DOS disks.
27.1.4 Formatting a DOS Disk  Formatting DOS disks.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.1.1 Listing the Contents of a DOS Disk

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.

  • To get a directory listing of the DOS disk currently in the primary floppy drive, type:

     
    $ mdir a: RET
    


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.1.2 Copying Files to and from a DOS Disk

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.

  • To copy the file `readme.txt' to the DOS disk in the primary floppy drive, type:

     
    $ 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.

  • To copy the file `resume.doc' from the DOS disk in the secondary floppy drive to the current directory, type:

     
    $ mcopy b:resume.doc RET
    

To copy all files from a DOS disk, just give the "drive letter" without any file names.

  • To copy all of the files and directories from the DOS disk in the primary floppy drive to the current directory, type:

     
    $ mcopy a: RET
    


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.1.3 Deleting Files on a DOS Disk

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.

  • To delete the file `resume.doc' on the DOS disk in the primary floppy drive, type:

     
    $ mdel a:resume.doc RET
    


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.1.4 Formatting a DOS Disk

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.)

  • To format the floppy disk in the primary floppy drive so that it can be used with MS-DOS, type:

     
    $ 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 section 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!


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.2 Using Macintosh Disks

@sf{Debian}: `hfsutils'
@sf{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.

27.2.1 Specifying the Macintosh Disk to Use  Specifying which Mac disk to use.
27.2.2 Listing the Contents of a Macintosh Disk  Listing the contents of a Mac disk.
27.2.3 Copying Files to and from a Macintosh Disk  Copying files to and from Mac disks.
27.2.4 Deleting Files on a Macintosh Disk  Deleting files on a Mac disk.
27.2.5 Formatting a Macintosh Disk  Formatting a Mac disk.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.2.1 Specifying the Macintosh Disk to Use

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.

  • To introduce the floppy disk in the first floppy drive as an HFS volume for the `hfsutils', type:

     
    $ 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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.2.2 Listing the Contents of a Macintosh Disk

Use hls to get a directory listing of the Macintosh disk currently specified with hmount (see section Specifying the Macintosh Disk to Use).

  • To get a directory listing of the currently specified Macintosh disk, type:

     
    $ hls RET
    

Give the name of a directory as a quoted argument.

  • To get a directory listing of the `Desktop Folder' directory in the currently specified Macintosh disk, type:

     
    $ hls 'Desktop Folder' RET
    


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.2.3 Copying Files to and from a Macintosh Disk

Use hcopy to copy files to and from the Macintosh disk currently specified with hmount (see section 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.

  • To copy the file `readme.txt' to the `Desktop Folder' directory in the current Mac disk, type:

     
    $ 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.

  • To copy the file `Desktop Folder:Readme' from the current Mac disk to the current directory, type:

     
    $ hcopy 'Desktop Folder:Readme' . RET
    


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.2.4 Deleting Files on a Macintosh Disk

Use hdel to delete a file on the Macintosh disk currently specified with hmount (see section 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.

  • To delete the file `Desktop Folder:Readme' on the current Mac disk, type:

     
    $ hdel 'Desktop Folder:Readme' RET
    


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.2.5 Formatting a Macintosh Disk

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'

  • To format the disk in the first floppy drive with a Macintosh HFS filesystem, type:

     
    $ 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 (`:').

  • To format the disk in the first floppy drive with a Mac HFS filesystem, overwriting any existing Mac filesystem, type:
     
    $ hformat -f /dev/fd0 RET
    

  • To format the disk in the second floppy drive with a Mac HFS filesystem, giving it a volume label of `Work Disk', type:

     
    $ 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.

  • To format the second partition of the SCSI disk at `/dev/sd2' with a Mac HFS filesystem, type:
     
    $ hformat /dev/sd2 2 RET
    

  • To format the entire SCSI disk at `/dev/sd2' with a Mac HFS filesystem, overwriting any existing Mac filesystem and giving it a label of `Joe's Work Disk', type:

     
    $ hformat -f -l "Joe's Work Disk" /dev/sd2 0 RET
    


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.3 Converting Text Files between DOS and Linux

@sf{Debian}: `sysutils'
@sf{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.

  • To remove the newline characters from the text file `autoexec.bat', type:
     
    $ fromdos autoexec.bat RET
    

  • To add newline characters to all of the text files with a `.tex' extension in the current directory, type:

     
    $ 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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.4 Converting Microsoft Word Files

@sf{Debian}: `word2x'
@sf{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 section Other Word Processors and Typesetting Systems).

27.4.1 Converting Word to LaTeX  
27.4.2 Converting Word to Plain Text  Converting Word to plain text.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.4.1 Converting Word to LaTeX

To convert a Word file to LaTeX format, use word2x and use `latex' as an argument to the `-f' option.

  • To convert the Word file `resume.doc' to LaTeX, type:

     
    $ 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.

  • To convert all of the `.DOC' Word files in the current directory to LaTeX files with maximum line widths of 40 characters, type:

     
    $ word2x -f latex -w 40 *.DOC RET
    


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

27.4.2 Converting Word to Plain Text

To convert a Word file to plain text, use word2x, and use `text' as an argument to the `-format' option.

  • To convert the Word file `resume.doc' to a plain text file called `resume', type:

     
    $ 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 section Searching for a Word or Phrase).

  • To search the text of the Word file `resume.doc' for the string `linux' regardless of case, type:

     
    $ 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.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]


Эта статья еще не оценивалась
Вы сможете оценить статью и оставить комментарий, если войдете или зарегистрируетесь.
Только зарегистрированные пользователи могут оценивать и комментировать статьи.

Комментарии отсутствуют