Pages

Wednesday, January 21, 2009

Ubuntu Tricks: Disk Space Usage and Mount

Disk Usage and Size
Its simple, and I got it even working via ssh onto one of my work servers to check how much space was being used by a mounted USB drive. Just type the shell command: df

Of course this is going to give you the default output in bytes. This is more human readable using the switch -h provides the output in megabytes, while uppercase as -H shows the output in gigabytes.

Example #1: $ df -h
Output:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/foo--bar-root
3.2T 2.5T 604G 81% /
tmpfs 1012M 0 1012M 0% /lib/init/rw
varrun 1012M 408K 1011M 1% /var/run
varlock 1012M 0 1012M 0% /var/lock
udev 1012M 2.9M 1009M 1% /dev
tmpfs 1012M 0 1012M 0% /dev/shm
lrm 1012M 2.0M 1010M 1% /lib/modules/2.6.27-9-generic/volatile
/dev/sda1 236M 52M 172M 24% /boot
//192.168.0.1/usbdrive
2.7T 2.3T 430G 85% /home/foo/storage


Example #2: $df -H
Output:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/foo--bar-root
3.5T 2.7T 648G 81% /
tmpfs 1.1G 0 1.1G 0% /lib/init/rw
varrun 1.1G 418k 1.1G 1% /var/run
varlock 1.1G 0 1.1G 0% /var/lock
udev 1.1G 3.0M 1.1G 1% /dev
tmpfs 1.1G 0 1.1G 0% /dev/shm
lrm 1.1G 2.1M 1.1G 1% /lib/modules/2.6.27-9-generic/volatile
/dev/sda1 247M 55M 181M 24% /boot
//192.168.0.1/usbdrive
3.0T 2.6T 461G 85% /home/foo/storage


Subdirectory Size
What if you just wanted to see the size of a particular directory and subdirectories underneath it in the tree? Simply use the the command: du

Naturally, similar to df its going to default to bytes so just use the -h switch and you'll be fine.


Mount Shares
There are also several ways to mount a network share. Whats important is that the share needs to be configured for the permissions you need whether read/write/both/etc. Make sure that you've installed smbfs as using smbclient is rather the old way to do this:

mount -t smbfs //ip_address/path1/path2/... -o username=yourusername,password=yourpassword

Example: mount -t smbfs //192.168.0.2/foo/bar -o username=foo,password=bar

If you're trying to mount an external USB drive, then there's no better way than as explained here.

Of course, what comes on should be easy to come off. Enter umount:

umount -lfr /mount_point/samba_share

Example: umount -lfr /dev/sda1

The above syntax switches lets you remove the drive or whatever share no matter if its "busy" or if a network share that's "requiring administrative privilege" aka offline.

Have fun!

No comments:

Post a Comment