LinuxCommandLibrary

mt

Control magnetic tape drives

TLDR

Check the status of a tape drive

$ mt -f [/dev/nstX] status
copy

Rewind the tape to beginning
$ mt -f [/dev/nstX] rewind
copy

Move forward a given files, then position the tape on first block of next file
$ mt -f [/dev/nstX] fsf [count]
copy

Rewind the tape, then position the tape at beginning of the given file
$ mt -f [/dev/nstX] asf [count]
copy

Position the tape at the end of valid data
$ mt -f [/dev/nstX] eod
copy

Rewind the tape and unload/eject it
$ mt -f [/dev/nstX] eject
copy

Write EOF (End-of-file) mark at the current position
$ mt -f [/dev/nstX] eof
copy

SYNOPSIS

mt [-f device] operation [count]

PARAMETERS

-f device
    Specifies the tape device to use. If omitted, the environment variable TAPE is consulted. Common values include /dev/st0, /dev/nst0 (non-rewinding), etc. The exact device name depends on the system configuration.

rewind
    Rewinds the tape to the beginning.

offline
    Rewinds the tape and puts the drive offline.

rewoffl
    Same as offline, rewinds the tape and puts the drive offline.

erase
    Erases the entire tape. Use with extreme caution!

fsf count
    Forward space count files. Defaults to 1 if count is omitted.

bsf count
    Backward space count files. Defaults to 1 if count is omitted.

fsr count
    Forward space count records. Defaults to 1 if count is omitted.

bsr count
    Backward space count records. Defaults to 1 if count is omitted.

weof count
    Write count end-of-file marks. Defaults to 1 if count is omitted.

eom
    Space to end of recorded media.

status
    Displays the status of the tape drive.

tell
    Displays the current block number of the tape drive.

DESCRIPTION

The mt command is a fundamental utility for interacting with magnetic tape drives in Linux and other Unix-like systems. It allows users to perform a wide array of operations, including rewinding, skipping files or records, writing end-of-file marks, and determining the status of the tape drive.

It is a crucial tool for backing up and restoring data to and from tape, as well as for archiving and data exchange. Proper use of mt requires understanding the specific tape drive being used and the format of the data on the tape. Incorrect usage can lead to data loss or corruption.

The command's behavior is often influenced by environment variables like TAPE, which specifies the default tape device to use if one isn't explicitly given on the command line. Because of the potential for serious data manipulation, it is important to exercise caution when using mt.

CAVEATS

Using mt incorrectly can lead to data loss. Always double-check the device name and the operation being performed before executing the command. Non-rewinding devices are often preferred for scripted operations to avoid unintended rewinds.

DEVICE NAMING CONVENTIONS

Tape devices are usually accessed through device files in the /dev directory. Rewinding devices (e.g., /dev/st0) automatically rewind the tape after each operation. Non-rewinding devices (e.g., /dev/nst0) leave the tape at its current position after each operation, which is useful for sequential operations.

ERROR HANDLING

The mt command can return different exit codes to indicate the success or failure of an operation. Consult the mt man page for details on the meaning of specific exit codes. Check the standard output/standard error for error messages.

HISTORY

The mt command has been a standard utility in Unix-like operating systems for many years, evolving alongside the development of magnetic tape technology. Its origins trace back to the early days of Unix, when tape drives were a primary means of data storage and backup. Over time, the command has been adapted and extended to support various tape drive models and formats. While tape usage has declined with the rise of disk-based storage, mt remains relevant for archival and specialized applications.

SEE ALSO

tar(1), cpio(1), dd(1)

Copied to clipboard