Tuesday, December 19, 2017

command line - How to access a usb flash drive from the terminal?



I only have access to the command line.
I need to backup my data (on the user folder) to a pen (USB DOK).




  • How can I mount a flash drive manually?

  • What should be the copy command?




1. Find what the drive is called



You'll need to know what the drive is called to mount it. To do that fire off one of the following (ranked in order of my preference):



lsblk
sudo blkid
sudo fdisk -l



You're looking for a partition that should look something like: /dev/sdb1. The more disks you have the higher the letter this is likely to be. Anyway, find it and remember what it's called.



2. Create a mount point (optional)



This needs to be mounted into the filesystem somewhere. You can usually use /mnt/ if you're being lazy and nothing else is mounted there but otherwise you'll want to create a new directory:



sudo  mkdir /media/usb


3. Mount!




sudo mount /dev/sdb1 /media/usb


When you're done, just fire off:



sudo umount /media/usb






This answer is almost 6 years old and while the core of it still works, things like fdisk -l aren't the most user-friendly options. There are also new mechanisms in higher stacks for mounting devices in a sane and standard way which might not always be available.



So I've added some polish from the other answers. While you're reading this footnote and you're doing this on a desktop system, there definitely are arguments for using udisksctl, per wecac's answer. This mounts in the same way the desktop does —creating your own /media/$USER/device directory— but I think there are still arguments for a static mountpoint, especially when you don't want the path to change.



Udisks also relies on D-Bus, so might not be available everywhere.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...