5 Linux Speed Tips - page 2
Quick Launchers, File Manager Shortcuts
Viewing Available Disk SpaceI work with audio and digital photo files, so I need to keep an eye on how much disk space I have. This little command-line incantation spits it out long before graphical file managers finish adding it all up:
$ df -h | grep ^/dev Filesystem Size Used Avail Use% Mounted on /dev/sdb1 19G 3.3G 15G 19% / /dev/sdb2 54G 3.8G 47G 8% /home /dev/sda1 193G 118G 66G 65% /home/carla/sda1df is the "disk-free" command. -h means "human-readable". Piping it through grep weeds out the temp, udev, and other filesystems that have nothing to do with available disk space. The caret, ^, means "beginning of the line matches only." Without using grep to filter the results it looks like this:
Filesystem Size Used Avail Use% Mounted on /dev/sdb1 19G 3.3G 15G 19% / tmpfs 506M 0 506M 0% /lib/init/rw udev 10M 740K 9.3M 8% /dev tmpfs 506M 0 506M 0% /dev/shm /dev/sdb2 54G 3.8G 47G 8% /home /dev/sda1 193G 118G 66G 65% /home/carla/sda1Without ^, it would still display the udev and tempfs filesystems.
Finding Biggest DirectoriesThis little du (disk used) incantation sorts directories by size, so you can quickly find disk hogs. This example displays all directories one gigabyte or larger, starting from the current working directory, sorted with the biggest last:
$ du -h | grep ^[0-9.]*G | sort -n [...] 23G ./sda1/carla 36G ./sda1/photos/2007 39G ./sda1/Photos 53G ./sda1/photos 118G ./sda1 121G .Again, -h means "human-readable", instead of in bytes with no commas. grep ^[0-9.]*G means "show lines beginning with any number that also ends in capital G", and then sort -n puts them in order. To see the largest values first, use rn, reverse numbering. You can specify any directory like this:
$ du -h /home/carla/* | grep ^[0-9.]*G | sort -nYou need the asterisk wildcard, which means "everything", to display subdirectories.
This finds the ten biggest directories:
$ du -h |grep ^[0-9.]*G | sort -rn| head -n 10If you don't have directories that take up gigabytes, M is megabytes and K is kilobytes.
# find top ten biggest directories
alias topten='du -h |grep ^[0-9.]*G | sort -rn| head -n 10'
~/.bashrc is read after new logins, so to get instant gratification open a new terminal and type in your new alias:
$ topten 121G . 118G ./sda1 53G ./sda1/photos 39G ./sda1/Photos 36G ./sda1/photos/2007 23G ./sda1/carla 17G ./sda1/photos/2008 16G ./sda1/Photos/2007-sept-montana 16G ./sda1/photos/2007/2007-sept-montana 5.4G ./sda1/carla/picturesType alias to see your existing aliases.
- 1Linux Top 3: Fedora 24, Peppermint 7 and Solus 1.2
- 2Linux Top 3: Alpine Linux 3.4, deepin 15.2 and Linux Lite 3.0
- 3Linux 4.7 Set to Boost Live Patching, Security and Power Management
- 4Linux 4.6 Charred Weasel adds USB 3.1 Support
- 5Linux Top 3: OpenIndiana 2016.04, Ubuntu 16.04 and Debian's New Leader