16

Using the terminal, how can I see the directory (and files) in an external HDD attached via USB port? (I am a beginner so would appreciate simple instructions. I have tried to find the answer through "search" - there are similar questions with answers that I tried to bend to my needs but could not - sorry).

4 Answers 4

15

USB media are normally mounted at /media go there in your terminal with cd /media && ls now you should see all storage mounted in that directory. If your device is in the list use cd to change in that directory and use ls or ll to list the files in your hdd.

If the hdd is not listed open your file Browser and usectrl+ l to go in the adress bar. There you can see the path of your hdd.

3
  • Thank you - I really appreciate your help. Unfortunately mine was not listed under media.
    – Duncan
    Jan 22, 2016 at 16:25
  • I just plugged in my USB external drive and was wondering about the same question. It took a minute or so until it showed up in <pre>media</pre>.
    – Norbert S
    Oct 30, 2019 at 0:56
  • It's /media only for "normal" USB (USB stick or drive) . If you connect a smartphone per USB it appears in /run/user/<UID>/gvfs/. In this case some other commands are used for mounting than udisksctl: baeldung.com/linux/mounting-mtp-devices. Jan 4 at 15:20
12

The topic that you're looking for is mounting . In the file manager you just click on the button to open it or detach the drive, but behind the scenes it uses udisksctl . Big advantage of this command is that it mounts as your user, and you don't have to specify whole lot of options, unlike the classic mount command.

For instance, to mount your usb drive, find device path with either lsblk or sudo blkid and then mount like so, for example,

udisksctl mount -b /dev/sdb1

Of course remember to replace sdb1 with the actual device name you want to mount.

Once the device is mounted successfully, it will be reported where it is mounted. For example,

skolodya@ubuntu:$ udisksctl mount -b /dev/sdb5
Mounted /dev/sdb5 at /media/xieerqi/0ca7543a-5463-4a07-8bbe-233a7b0bd625.

Then you could navigate to /media/$USER/folder-name and start exploring files and folders

1
  • It just tells me that the disk is not mountable filesystem. The disk works just fine, I just used it on another linux machine. Oct 20, 2020 at 13:48
5

Just a small addition to previous answer : If you started on a command line machine, or a headless system (like a rpi for example), device will probably not mount automatically.

You then should first search for his device name (sudo fdisk -l) and then mount it in an empty folder (sudo mount /dev/sdb1 /media/myNewlyCreatedFolder)

0
0

sudo mount /dev/sdb1 /media/root lets you mount, but you don't have permission to copy it to another place yet

To do that follow https://stackoverflow.com/questions/23520744/cp-failed-to-preserve-ownership-error-when-mounted-manually

TLDR: mount using this sudo mount -o uid=1000,gid=1000 /dev/sdc1 /mnt/boot and copy using sudo cp -Rrf --preserve=all <source> <destination>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .