12/18/24, 7:11 AM command line - How to access a usb flash drive from the terminal?
- Ask Ubuntu
Sign in to Stack Exchange with Google
How to access a usb flash drive from
prs nortin
the terminal?
prsnortin@gmail.com
Asked 13 years, 7 months ago Modified 3 years, 2 months ago Viewed 1.8m times
Continue as prs
I only have access to the command line. To create your account, Google will share your
name,
I need to backup my data (on the user folder) to aemail address,
pen (USB DOK).and profile picture with Stack
Exchange. See Stack Exchange's privacy policy and
329
How can I mount a flash drive manually?
terms of service.
What should be the copy command?
command-line mount usb-drive
Share Follow edited Jul 25, 2017 at 11:21 asked Apr 29, 2011 at 0:26
Yaron MEM
13.3k 8 45 56 11.2k 12 39 42
This was helpful for me to see a list of files and their sizes: askdavetaylor.com/… – Ryan Aug 18, 2022 at
19:06
7 Answers Sorted by: Highest score (default)
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
463
(ranked in order of my preference):
lsblk
sudo blkid
sudo fdisk -l
By clicking “Accept all cookies”, you agree Stack Exchange
can store cookies on your device and disclose information in
accordance with our Cookie Policy.
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.
Accept all cookies Necessary cookies only
2. Create a mount
Customizepoint
settings (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:
https://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal 1/8
12/18/24, 7:11 AM command line - How to access a usb flash drive from the terminal? - Ask Ubuntu
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.
Share Follow edited Jul 25, 2017 at 12:58 answered Apr 29, 2011 at 0:43
Oli ♦
297k 119 692 844
2 the main disadvantage of this method is that it mounts the device as root. if the device is FAT formatted
then the user won't be able to write to it. the /media/$USER/device mountpoint will also always be the
same – eMBee May 30, 2018 at 19:49
1 All answers assume that there magically appears a /dev/sdX after putting in the USB stick. What if it
doesn't? I see in the logs that it is detected, but no new /dev. lsusb show all the gory details too. Ie sudo
lsusb -vs 15:2 | grep id gives idVendor 0x090c Silicon Motion, Inc. - Taiwan
(formerly Feiya Technology Corp.) idProduct 0x1000 Flash Drive – Carlo Wood May 18,
2020
By clicking at 4:31all cookies”, you agree Stack Exchange
“Accept
can store cookies on your device and disclose information in
@CarloWood
accordance I have faced
with our Cookie Policy.a similar situation. In some logs, i think dmesg or something, I found that the
drive was unable to power itself up. I just ended up using a different port for the drive. As far as i know
there is not a way to mount a drive, whose device driver hasnt created a device file in /dev/
– Harish Ganesan Nov 10, 2022 at 6:12
pmount / pumount
https://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal 2/8
12/18/24, 7:11 AM command line - How to access a usb flash drive from the terminal? - Ask Ubuntu
55 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.
Share Follow edited Apr 2, 2020 at 17:18 answered Nov 6, 2013 at 1:39
Pablo Bianchi Sepero
16.8k 4 85 122 4,597 3 34 53
This worked when mount insisted on mounting my drive read-only. – Jonathan E. Landrum Jun 16, 2018 at
0:05
Use udisksctl from package= udisks2 (in both Ubuntu and Debian). Procedure is:
1. Find the ID of the block device you want to mount, using lsblk :
19
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
By clicking ├─sdb1
“Accept all8:17 0 you
cookies”, 37M 0 part
agree Stack Exchange
├─sdb2 8:18 0 15.9G 0 part [SWAP]
can store cookies on your device and disclose information in
└─sdb3 8:19 0 915.7G 0 part /
accordancesdcwith our Cookie
8:32 Policy.
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.
2. Use udisksctl to mount the device. Note that -b == --block-device (to reduce typing) but
I prefer long options for documentation:
https://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal 3/8
12/18/24, 7:11 AM command line - How to access a usb flash drive from the terminal? - Ask Ubuntu
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.
Share Follow edited May 7, 2018 at 5:01 answered Dec 28, 2016 at 15:34
TomRoche wecac
123 4 301 2 4
In addition to using the standard mount command (which requires root) you can mount drives
using udisks and dbus with your standard user.
12
To do this it is useful (but not required) to know a few things about the drive first:
1. What device it is (i.e. /dev/sdb1 )
2. what filesystem it uses.
Knowing these you can use a simple command to mount a drive from the command line.
gdbus call --system --dest org.freedesktop.UDisks --object-path
/org/freedesktop/UDisks/devices/<device> --method
org.freedesktop.UDisks.Device.FilesystemMount "<filesystem>" []
this call should echo the path it is mounted at if the mount succeeds.
By clicking “Accept all cookies”, you agree Stack Exchange
canTo
store cookies drives
unmount on yourmounted
device andindisclose information
this way you can in
run:
accordance with our Cookie Policy.
gdbus call --system --dest org.freedesktop.UDisks --object-path
/org/freedesktop/UDisks/devices/<device> --method
org.freedesktop.UDisks.Device.FilesystemUnmount []
https://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal 4/8
12/18/24, 7:11 AM command line - How to access a usb flash drive from the terminal? - Ask Ubuntu
N.B. the <device> is simply the end of the path to it. So for example if what you want to mount is
at /dev/sdb2 then you would put sdb2 in place of <device> .
If you do not know which device it is or what filesystem it uses do not fear. You can easily print
out all that information with this little command:
gdbus introspect --system --dest org.freedesktop.UDisks --object-path
/org/freedesktop/UDisks/devices --recurse --only-properties | grep -E "(readonly .+
(IdLabel|IdType|Device(IsMounted|IsDrive|File) ).*|\}|.*\{)"
This will print out something like this:
node /org/freedesktop/UDisks/devices {
node /org/freedesktop/UDisks/devices/sda {
interface org.freedesktop.UDisks.Device {
readonly s IdLabel = '';
readonly s IdType = '';
readonly s IdUsage = '';
readonly b DeviceIsMounted = false;
readonly s DeviceFile = '/dev/sda';
};
};
node /org/freedesktop/UDisks/devices/sda1 {
interface org.freedesktop.UDisks.Device {
readonly s IdLabel = 'SYSTEM';
readonly s IdType = 'ntfs';
readonly s IdUsage = 'filesystem';
readonly b DeviceIsMounted = false;
readonly s DeviceFile = '/dev/sda1';
};
};
node /org/freedesktop/UDisks/devices/sda2 {
interface org.freedesktop.UDisks.Device {
readonly s IdLabel = 'Windows7';
readonly s IdType = 'ntfs';
readonly s IdUsage = 'filesystem';
readonly b DeviceIsMounted = true;
readonly s DeviceFile = '/dev/sda2';
};
};
node /org/freedesktop/UDisks/devices/sda3 {
interface org.freedesktop.UDisks.Device {
readonly s IdLabel = 'Recovery';
readonly s IdType = 'ntfs';
By clicking “Accept all cookies”,
readonly you =agree
s IdUsage Stack Exchange
'filesystem';
can store cookies on your device and disclose= information
readonly b DeviceIsMounted false; in
readonly s DeviceFile
accordance with our Cookie Policy. = '/dev/sda3';
};
};
node /org/freedesktop/UDisks/devices/sda4 {
Those that have IdUsage = 'filesystem' may be mounted using the above command.
This means that, for example, if i wanted to mount the device 'USB DRIVE' i would run the
command
https://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal 5/8
12/18/24, 7:11 AM command line - How to access a usb flash drive from the terminal? - Ask Ubuntu
gdbus call --system --dest org.freedesktop.UDisks --object-path
/org/freedesktop/UDisks/devices/sdb1 --method org.freedesktop.UDisks.Device.FilesystemMount
"vfat" []
These commands all work using the dbus messaging system, the same way that Nautilus and
other file managers auto-mount things. In these commands we are sending various objects (i.e.
/org/freedesktop/... messages asking them to mount and unmount certain devices. They might
or might not do this depending on the permissions one has been given in PolicyKit .
Using similar commands one can control almost every aspect of ones experience in Ubuntu and
simulate most system programs and functions (i.e. shutdown, volume change, etc.).
Share Follow edited Aug 29, 2012 at 15:54 answered Aug 29, 2012 at 15:42
Alex L.
3,438 1 20 22
1 The 2015 way is gdbus introspect --system --dest org.freedesktop.UDisks2 --object-path
/org/freedesktop/UDisks2/drives --recurse --only-properties – nvja Jun 10, 2015 at 22:09
You can also automatically mount USB devices on Ubuntu Server with the help of USBmount.
Make sure you run apt-get update/upgrade before starting the installation:
5
sudo apt-get update && sudo apt-get upgrade
Now install USBmount from the repositories:
sudo apt-get install usbmount
USBmount mounts all USB drives in /media/usb* (usb0, usb1, usb2 ...)
Now plug a USB drive and wait for it to be detected and mounted. As long as the host OS
supports the File System it should be mounted.
By clicking “Accept all cookies”, you agree Stack Exchange
To verify whether the USB drive was mounted correctly you can use df -h to view all available
can store cookies on your device and disclose information in
drives and
accordance withtheir respective
our Cookie Policy.mount points
To un-mount a drive you can use umount.
sudo umount /media/usb0
Share Follow answered May 14, 2016 at 16:35
https://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal 6/8
12/18/24, 7:11 AM command line - How to access a usb flash drive from the terminal? - Ask Ubuntu
Sandro
61 1 3
2 E: Unable to locate package usbmount – Ryan Jun 26, 2023 at 0:45
That's simple. When I want to use a usb drive in terminal I do this:
Create a folder in /media with:
4
mkdir /media/mountDrive
This folder will be used for the mount point. Use this command:
sudo mount /dev/sdd1 /media/mountDrive
sdd1 is the first partition of my USB. Then you can navigate to folder you already mounted with
cd /media/mountDrive
If you want to list the files in drive you can use the ls command.
To unmount the drive you can use
sudo umount /dev/sdd1
Note that in my system the usb drive is /dev/sdd1 , but in your system it may be something
different. To find out what it is use the df command to see all disks connected at the present
time.
Share Follow edited Aug 27, 2013 at 19:22 answered Aug 29, 2012 at 14:08
Braiam ThePoet
68.6k 32 181 271 172 3
By clicking “Accept all cookies”, you agree Stack Exchange
canIstore
will not addon
cookies about how toand
your device mount theinformation
disclose drive. However
in since the asker also asked what the best
command
accordance withto use
our to copy
Cookie the data over, I will answer that since it was not answered as far as I can
Policy.
0 tell.
I would recommend first creating a folder on the drive (even if it is empty) to back your stuff into
to provide organization. Something along the lines of mkdir <mountpath>/mybackup should do it.
Second, I would use rsync to copy everything over. Do something along the lines of rsync -r ~/*
<mountpoint>/mybackup . You can also use cp -r if you want, however, I have found that doing so
https://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal 7/8
12/18/24, 7:11 AM command line - How to access a usb flash drive from the terminal? - Ask Ubuntu
doesn't do quite everything that you would expect all of the time.
Share Follow answered Sep 21, 2021 at 22:18
Minecraftchest1
75 1 6
Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question.
The reputation requirement helps protect this question from spam and non-answer activity.
By clicking “Accept all cookies”, you agree Stack Exchange
can store cookies on your device and disclose information in
accordance with our Cookie Policy.
https://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal 8/8