How to access a usb flash drive from the terminal?
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.
pmount
/ pumount
Install pmount
. Mounts disks in /media/
pmount /dev/sdb1
pumount /dev/sdb1
No sudo
needed.
Replace "sdb1" with your specific device path. For more information see the manpage:
pmount ("policy mount") is a wrapper around the standard mount program
which permits normal users to mount removable devices without a match-
ing /etc/fstab entry.
pmount is invoked like this:
pmount device [ label ]
This will mount device to a directory below /media if policy is met
(see below). If label is given, the mount point will be /media/label,
otherwise it will be /media/device.
Use udisksctl
from package=udisks2
(in both Ubuntu and Debian). Procedure is:
Find the ID of the block device you want to mount, using
lsblk
:user@machine:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 1.8T 0 disk ├─sda1 8:1 0 19.1M 0 part /boot/efi ├─sda2 8:2 0 1.8T 0 part └─sda3 8:3 0 16G 0 part [SWAP] sdb 8:16 0 931.5G 0 disk ├─sdb1 8:17 0 37M 0 part ├─sdb2 8:18 0 15.9G 0 part [SWAP] └─sdb3 8:19 0 915.7G 0 part / sdc 8:32 1 14.4G 0 disk └─sdc1 8:33 1 14.4G 0 part sdd 8:48 0 1.8T 0 disk └─sdd1 8:49 0 1.8T 0 part
From its size,
/dev/sdc1
seems to be the USB drive I want to mount.Use
udisksctl
to mount the device. Note that-b
==--block-device
(to reduce typing) but I prefer long options for documentation:user@machine:~$ udisksctl mount --block-device /dev/sdc1 ==== AUTHENTICATING FOR org.freedesktop.udisks2.filesystem-mount === Authentication is required to mount Kingston DT microDuo 3C (/dev/sdc1) Multiple identities can be used for authentication: 1. XXXXX,,, (user) 2. ,,, (YYYYY) Choose identity to authenticate as (1-2): 1 Password: ==== AUTHENTICATION COMPLETE === Mounted /dev/sdc1 at /media/user/USBDRIVELABEL.
Addressing Hans Deragon's comment below: you can also tell udisksctl
to do --no-user-interaction
. It does not attempt to authenticate the user, which usually "just works":
user@machine:~$ udisksctl mount --block-device /dev/sdc1 --no-user-interaction
# possibly some complaining here about I/O charset or need to run `fsck`
Mounted /dev/sdc1 at /media/user/USBDRIVELABEL.