How can I see if the usb device has been dismounted? Because when I did
fdisk -l the information is the same, before and after the ran command
You can use
lsblk to achieve what you are trying to do, in a somewhat roundabout fashion.
The purpose of lsblk is to list attached block devices and provide some basic data about them. Two pieces of data that are of interest that it prints by default is the device node and the mount point.
Assuming that you know the device node of the USB drive, you can simply look at the lsblk output. If the
MOUNTPOINT column is empty, then the device is not mounted. It looks like lsblk reads this information from /proc/mounts, which holds the same information that you would get out of running
mount without any parameters (and is often mirrored at /etc/mtab).
fdisk -l reports whether a block device is visible for the kernel, which has nothing to do with whether one or more file systems that are contained in the device, are actually mounted. You can review the current state of mounted devices with
mount. You could write a script that either looks in the system logs, or compares the output of the
mount command with