So far I haven't found a simple alternative to "safely eject" in the file manager, so this is my justification for using command line here.
First , you'd need to find out your external hard-drives device id or block id. Then you can use either udisks
or udisksctl
to unmount and actually power off the device. I have answered related question some time ago , when just started out with ubuntu, so I suggest you refer to it as well. Basically , i use udisks --unmount /dev/sdb1 && udisks --detach /dev/sdb
where sdb1 is the mount-point and sdb is the actual disk.
You can use lsblk
and identify it by mount-point and size; on the other hand, you can use udisksctl status
. For instance, I have a Sandisk Cruiser usb drive connected right now. The output of the commands is the following:

As you can see both report that my usb drive is identified as /dev/sdc. Each time you pugin a usb device it will be identified with different letters, sdb, sdc,sdf and so forth, while sda is always your hard-drive.
So in my case , I would eject the usb with udisks --unmount /dev/sdc1 && udisks --detach /dev/sdc
or alternatively with what Fabby suggested. With the one-liner I use, I've noticed that the device id is preserved, i.e, if i eject the usd and reconnect it, it still gives the device sdc
name.
TIP: you can use udisksctl status | grep -i wd
to show only information for the external hard drive.
Now, here's something I've done purely for fun, but you could find it useful and adapt to your own needs. What if we could write a script to do the safe-ejecting for us ?
We'd need to let the shell know the block id of out external hdd or usb. What would be the output of this command : udisksctl status | grep -i sandisk | xargs echo
? It would be this: SanDisk Cruzer Glide 1.27 2005425573077FA0AA67 sdd
, or in other words information about the usb , delimited by spaces, with the device id being last argument, or the 6th one. Here we can use cut command to extract it like so: udisksctl status | grep -i sandisk | xargs echo | cut -d' ' -f6
Of course for you, you'd have to use udisksctl status | grep -i wd | xargs echo
and count which element is your block id is, and then use appropriate number on cut -d' ' -fx
Next , I've put together the script remove-usb.sh. Here it is:
#!/bin/sh
DEVICE=$( udisksctl status | grep -i sandisk | xargs echo | cut -d' ' -f6 )
udisks --unmount /dev/$(echo $DEVICE)1 && udisks --detach /dev/$DEVICE
Next, placed it in my /home/user/bin folder, chmod +x /home/user/bin/remove-usb.sh. Don't forget to have that bin folder to be added to your path. Now you can also create a .desktop file or make script executable in the file manager
And here's the script in action
