mtools Commands in Linux



mtools is a collection of utilities designed to allow Unix systems to manipulate MS-DOS files. This suite of tools enables users to read, write, and move files on an MS-DOS file system, typically found on floppy disks, without the need for mounting1. Each program within mtools attempts to emulate the corresponding MS-DOS command, providing a seamless way to interact with DOS files from a Unix environment.

Table of Contents

Here is a comprehensive guide to the options available with the mtools command −

Key Features of mtools Command

  • File Manipulation − mtools allows you to read, write, and move files on MS-DOS file systems.
  • No Mounting Required − Unlike traditional methods, mtools does not require mounting the disk, making it more convenient and efficient.
  • Emulation of MS-DOS Commands − Most commands within mtools emulate their MS-DOS counterparts, providing familiarity for users transitioning from DOS to Unix.
  • Handling Long File Names − Supports VFAT-style long file names, which are common in MS-DOS.

Installing mtools Command

To get started with mtools, you need to install it on your system. The installation process varies depending on your Linux distribution.

On Debian-based Systems (e.g., Ubuntu)

sudo apt install mtools

On Red Hat-based Systems (e.g., Fedora)

sudo dnf install mtools

On Arch Linux

sudo pacman -S mtools

mtools Commands Options

Here are some frequently used mtools commands −

Options Description
mdir Lists the contents of a DOS disk.
mcopy Copies files to and from a DOS disk
mformat Formats a DOS disk.
mcopy Copies files to and from a DOS disk.
mmove Moves files within a DOS disk.
mren Renames files on a DOS disk
mshowfat Displays the FAT (File Allocation Table) of a DOS disk.
mdel Deletes files from a DOS disk.
mmd Creates directories on a DOS disk.
mrd Removes directories from a DOS disk.
mlabel Labels a DOS disk.
mattrib Changes file attributes on a DOS disk (e.g., read-only, hidden).
mcd Changes the current working directory on a DOS disk.

Examples of mtools Command in Linux

Let's explore how you can effectively use mtools to manage files on an MS-DOS file system −

  • Listing Contents of a DOS Disk
  • Copying Files to a DOS Disk
  • Formatting a DOS Disk
  • Moving File on a DOS Disk
  • Renaming Files on a DOS Disk
  • Viewing the Directory Structure of a DOS Disk
  • Transferring Multiple Files to a DOS Disk
  • Creating Directories on a DOS Disk

Listing Contents of a DOS Disk

To see what's stored on your DOS disk, use the mdir command −

mdir a:

This command will display a list of all files and directories on the a: drive, which typically represents a floppy disk.

Copying Files to a DOS Disk

If you want to transfer a file from your Unix system to a DOS disk, you can use the mcopy command −

mcopy file.txt a:

This copies file.txt from your current directory to the root directory of the a: drive.

Formatting a DOS Disk

In case you want to prepare a DOS disk for use, you can format it using mformat −

mformat -f 720 -v DOS_DISK a:

This command formats the a: floppy disk with a 720KB capacity and labels it as DOS_DISK.

Moving Files on a DOS Disk

If you need to move a file within the DOS disk, the mmove command will do the job −

mmove a:oldfile.txt a:newfile.txt

This command renames oldfile.txt to newfile.txt on the a: drive.

Renaming Files on a DOS Disk

To simply rename a file on a DOS disk, use the mren command −

mren a:oldfile.txt a:newfile.txt

This command renames oldfile.txt to newfile.txt on the a: floppy disk.

Viewing the Directory Structure of a DOS Disk

To display the directory structure of a DOS disk, you can use the mdir command with a specific path −

mdir a:/

This command will show all files and directories in the root of the a: drive.

Transferring Multiple Files to a DOS Disk

If you need to copy multiple files at once to a DOS disk, use the mcopy command with wildcards −

mcopy *.txt a:

This copies all .txt files from your current directory to the root directory of the a: drive.

Creating Directories on a DOS Disk

To create a new directory on a DOS disk, use the mmd command −

mmd a:/newdir

This command creates a directory named newdir in the root of the a: drive.

Conclusion

mtools is a powerful suite of utilities that simplifies the process of accessing and manipulating MS-DOS files from a Unix system. Whether you're working with legacy software or managing old data storage formats, mtools provides a convenient and efficient way to handle DOS disks without the need for mounting.

Advertisements