One of the fun things about Koha is being open source, anyone can download and install it on their own local server or PC. However, this does require you to have a certain level of knowledge about using Linux, particularly Debian or Ubuntu, since that’s where Koha runs best. I live in the Linux world. Not only do I work every day on Linux servers, but all my home PCs run Linux (in case you’re wondering, my distro of choice at home is Ubuntu). Being an enthusiast, I love learning about Linux commands I may not have used much before, or new command options, or different ways of doing things. No matter how much you know about an OS, there’s always more to learn. Therefore, I thought I’d share a few of the commands I frequently use day to day. If you’ve used Linux much, most of these are probably familiar to you, but hopefully you may find one or two new ones.
Since most of my work is done in the terminal window (even on my home PCs), these are all terminal commands, and they’re in no particular order. Some of these need to be done as the root user, and where that’s the case, I’ve prefaced the command with ‘sudo’. If you’ve used Linux much, you should already be well familiar with ‘sudo’. Enjoy.
Checking the version of Debian:
Checking the version of Ubuntu:
(Note – Right there is a command you may not have used much. Most people use ‘more’ or ‘less’ to view the contents of a file. I like to use ‘cat’, as it outputs the entire file at once. For short files, there’s not much difference between ‘more’ and ‘cat’ but for medium length files, I find ‘cat’ to be quicker for me, than using ‘more’ and having to page through the file.)
Apt is the package management program for Debian/Ubuntu, and if you’ve done much in those, you’ve probably used ‘sudo apt-get update’ and ‘sudo apt-get install’ to install a package. But if you want to see what a package would install, without actually installing it, you can use the ‘-s’ option, e.g.
sudo apt-get -s install koha-common
This will tell what would have been installed along with Koha, and then you can decide whether to do it for real or not. It also “simulates” the install, so you can see whether you might run into problems, say with package dependencies, before you actually do it.
To search for available packages, you can use:
apt-cache search <portion-of-package-name>
aptitude search <portion-of-package-name>
apt-cache search mysql
aptitude search mysql
I like the second one more because for me the information is more useful. A ‘p’ in the first column means the package is available, and an ‘i’ means it’s already installed.
To see what version of a package is available (and whether a new version is available, if it’s already installed), you can enter:
sudo apt-get update
apt-cache policy <package-name>
This is handy if you’ve installed the Koha package, and want to see if the new update has been uploaded to the repository, e.g. ‘apt-cache policy koha-common’.
Renaming a Linux user in three easy steps:
sudo usermod -d /home/newname -m oldname
sudo usermod -l newname oldname
sudo groupmod -n newname oldname
Most Linux users are familiar with ‘top’ for checking memory usage. You can also check available memory with ‘free’, which will give you output like this:
total used free shared buffers cached Mem: 4108192 4043612 64580 0 67892 3425768 -/+ buffers/cache: 549952 3558240 Swap: 8388604 5800 8382804
The actual free memory is in the ‘-/+ buffers/cache’ line, not the ‘Mem’ line. Linux always takes unused RAM and uses it to buffer/cache data for quicker recall, but when a program actually needs RAM, it drops the cached data and uses the RAM for the application. In this case, the total available memory is 4G, and of that, appx. 3.4G are available to applications to use (the output is in kilobytes; you can see the output in megabytes by using the ‘-m’ option, e.g. ‘free -m’).
Most Linux users have probably used ‘ps -ef’ or ‘ps uawx’, or some other variation of ‘ps’ to see what processes are running. However, if you want to get a good handle on how much actual memory your processes are using, and who’s the worst offender, you can use:
ps -ylA --sort:rss
The ‘RSS’ column in the output gives you the memory usage in kilobytes, and the ‘‐‐sort:rss’ sorts by memory usage, ascending. So the last item in the list is the one using the most memory. You can use ‘‐‐sort:cmd’ to sort by process name.
If you want to just check on specific applications, you can use:
ps -ylC <process_name> --sort:rss
ps -ylC apache2 --sort:rss
Occasionally every Linux user will need to “kill” a process. The usual method for doing this is to get the process ID via ‘ps’, and then enter ‘sudo kill -9 <process_id>’. But you can also kill processes by process name, using ‘pkill’. For example, let’s say you have done a ‘ps’ and see these apache processes:
root 5599 1 0 Mar09 ? 00:00:18 /usr/sbin/apache2 -k restart
www-data 6552 5599 0 Mar12 ? 00:00:00 /usr/sbin/apache2 -k restart
www-data 6593 5599 0 Mar12 ? 00:00:00 /usr/sbin/apache2 -k restart
www-data 6598 5599 0 Mar12 ? 00:00:00 /usr/sbin/apache2 -k restart
Instead of messing with process IDs, you could kill all of them at once with:
sudo pkill -9 apache2
However, there’s a problem with ‘pkill’, which is that it only matches on the first 15 characters of the process name. In some cases, that’s not enough to uniquely identify a process by its name. Where I’ve personally run into this is if there are a large number of Koha processes running amok, say for example, you have a search bot pounding your server with opac search hits. You may have already stopped Apache, but the other Perl processes launched by Apache are still hanging on. If you do a ‘ps -ef’, the opac search process looks like this:
1000 9081 9080 25 16:40 ? 00:00:02 /usr/bin/perl /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
And ‘pkill’ is not going to be able to match on that process name. However, you can use the ‘-f’ option, which will kill processes by matching the string you enter against the entire process name. So you could kill all the opac-search processes at once with:
sudo pkill -9 -f opac-search
Okay, that’s just a few of commands I use on a regular basis. If you’re a Linux user, I hope you found at least some of them useful. Until next time,