Using the terminal, how can I see the directory (and files) in an external HDD attached via USB port?
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).
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.
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
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
)