Linux Commands for 99 Bottles of Beer and Disk Space
99 Bottles of Beer, df commandLinux server admins need good scripting skills and command-line chops, but who says they can't be fun? Learn Bash Karaoke with 99 Bottles of Beer on the Wall, quickly find disk hogs, and display used/free disk space.
I haven't had time to finish setting up my Arch Linux backup server to do automatic wakeups, backups, and shutdowns, so here are some fun command-line hacks instead.
99 Bottles of Beer on the WallHow about a bit of geek Karaoke? Just copy and paste this into a Bash session, and it will look like this:
99 bottles of beer on the wall, 99 bottles of beer. Take one down pass it around, 98 bottles of beer on the wall
98 bottles of beer on the wall, 98 bottles of beer. Take one down pass it around, 97 bottles of beer on the wall
97 bottles of beer on the wall, 97 bottles of beer. Take one down pass it around, 96 bottles of beer on the wall
And so on, until it finishes. You can adjust the tempo by changing the sleep value, which in this example is 3 seconds. This can also be preserved in a script. Copy it into any text editor and save it under whatever name you like, like beer.txt. You have probably read that you need to enter #!/bin/bash as the first line, and then make the script executable with the command chmod +x beer.txt. Then run the script like this:
You need the dot-slash when you're running the script from the current working directory. Don't use them if you're running it from a different directory, like this:
But that's a lot of work when you're just fooling around, or testing some new stuff. Skip the #!/bin/bash line, skip the chmod stuff, skip the dot-slash, and run your nice new script like this:
$ sh beer.txt
You could even name it plain old "beer" and not have a file extension at all, because Linux is smart and reads inodes instead of file extensions, so it cannot be fooled by bogus file extensions like poor old dumb Windows.
This is a great little script for learning a number of fundamental Bash operations, which I leave as your homework.
Disk Space and File SizesGraphical file managers like Dolphin and Nautilus are ghastly slow at calculating disk space, and never display the information I want all at once. I'm old and I don't have time to waste while they faff around, so I use the df command:
$ df -h | egrep -i "file|^/" Filesystem Size Used Avail Use% Mounted on /dev/sdb1 19G 3.2G 15G 19% / /dev/sdb2 54G 4.4G 47G 9% /home /dev/sda1 193G 118G 66G 65% /home/carla/sda1The -h option means use human-readable numbers instead of bytes, like 3.2G instead of 3322416. Piping the output to the egrep incantation displays only your root and data filesystems, and not all the weird little temp and virtual filesystems, and it retains the header that shows what each column represents. Add the T option to see the filesystem types:
$ df -hT | egrep -i "file|^/" Filesystem Type Size Used Avail Use% Mounted on /dev/sdb1 ext3 19G 3.2G 15G 19% / /dev/sdb2 ext3 54G 4.4G 47G 9% /home /dev/sda1 ext4 193G 118G 66G 65% /home/carla/sda1df shows only filesystems, not individual directories or files. For these we want du.
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: GNOME 3.12 and New Betas for Ubuntu 14.04 and OpenMandriva Lx 2014.0
- 2Linux Top 3: Linus Lashes out, Linux 3.14 Gets PIE and Ubuntu One is Done.
- 3Linux Top 3: Ubuntu 14.04, Debian Gives Squeeze More Life and Red Hat Goes Atomic
- 4Linux Top 3: CoreOS, Oracle Enterprise Linux 7 and Ubuntu 14.10
- 5Linux Top 3: Linux from Scratch, Ubuntu 14.01 Beta and Arch Updates