how to copy file to pendrive in ubuntu

File Transfer and Removable Media in Linux

This entry details methods for transferring files to and from removable storage devices, such as USB flash drives, within a Linux environment. Understanding the file system hierarchy and command-line tools is crucial for efficient data management.

Identifying Removable Media

Before initiating a file transfer, the removable device must be identified. Upon insertion, the device typically mounts automatically, assigning it a mount point (directory) within the file system. This mount point can be identified through the graphical file manager or via the command line using tools such as lsblk, which displays block devices, and df -h, which shows disk space usage. The mount point will usually be a directory under /media//, where `` represents the current user's account. Alternatively, use the system's graphical user interface (GUI) file manager to locate the drive.

Using the Command Line Interface (CLI)

The command-line interface provides efficient and versatile control over file transfers. The cp command (copy) is fundamental for copying files and directories.

Copying Files

  • Basic Copy: cp source_file target_location. For example, to copy `document.txt` to the removable device mounted at `/media/user/USBDRIVE`, the command would be: cp document.txt /media/user/USBDRIVE/
  • Recursive Copy (for directories): cp -r source_directory target_location. The `-r` option ensures that the entire directory structure is copied recursively.
  • Preserving Attributes: cp -p source_file target_location. The `-p` option preserves file permissions, timestamps, and ownership information during the copy operation.

Using `rsync` for Advanced Copying

The rsync command offers more advanced features such as incremental backups, error handling, and progress reporting, particularly beneficial for larger files or directories. Its syntax is similar to cp, but with additional options for specifying transfer modes and other parameters.

Using the Graphical User Interface (GUI)

Most Linux distributions include file managers with drag-and-drop functionality, providing a visual interface for copying files. Simply locate the file or directory you want to copy, and drag it to the icon representing the mounted removable device in the file manager window.

Unmounting the Device

Before removing the removable storage device, it is crucial to unmount it to prevent data corruption. This can be done through the GUI file manager or by using the umount command, specifying the mount point. For example: umount /media/user/USBDRIVE. Failure to properly unmount may result in data loss or file system inconsistencies.