Category Archives: Linux

Over 80% is running on some form of Linux – so does your Mac and you iPhone. Sometimes we have to get our hands dirty on the command line – it makes you feel like a proper hacker.

Here are some pointers I picked up on my journey.

How to read command line parameters in PHP Shell Scripts

We can access parameters passed via the command line in our PHP shell scripts. Those are stored as an array in the variable $argv. Consider this:

The first part of the script prints out all parameters that have been given, while the second part checks if the parameter was “x” or not. Note that the first item in the array ($argv[0]) will be the the first item on the command line, i.e. the file name and path to this very script. $argv[1] is the first parameter, $argv[2] the second, and so forth.

We can call the script with

to give it one parameter, or with

to give it three parameters.

  • http://php.net/manual/en/reserved.variables.argv.php

How to extract files from a bz2 archive in Linux

If you’ve ever tried to decompress a file that ends in tar.bz2 using the tar command with the standard -x option, you’ll have noticed that it doesn’t work. That’s because some versions of tar don’t understand the bzip2 codec used in these archives.

However, you can tell tar to use this option by specifying the -j parameter, like so:

If this still doesn’t work, we can use the dedicated bzip2 command like so:

The -d switch stands for “decompress”. Notice that this will extract all files and delete the original .bz2 file by default. Very convenient indeed! If you’d like to keep it, just pass the -k switch (for “keep”), like this:

Checkout man bzip2 for more details, or pass the –help for as quick overview.

How to remove duplicate packages with yum

I’m working on a handful of servers that all have the same problem: when running yum, an error message appears that tells me a package called ntpupdate needs to be upgraded, but somehow this doesn’t work and the package is being skipped. Then follows a huge list of duplicate packages that are installed on those systems (probably installed by the automatic package updater within Plesk).

Let’s see how we can fix such issues. Continue reading How to remove duplicate packages with yum

Format a Linux system drive on Windows

The other day I tried to format a USB drive for use with Windows. I had previously tried this on my Mac to no avail. But now even Windows was telling me that it too could not format my drive.

I was stumped! I had in fact never seen anything like it before. Was that USB drive broken? Had I turned stupid overnight? Well perhaps… but more importantly, it dawned on me what I had used this USB drive prior to this formatting nightmare: it was a Linux installation that could run directly from the stick.

This is important, because as part of the installation, a protected EFI system partition is installed. This is used for booting if I understand correctly, and hence rather important. So important in fact that the ordinary user tools in both macOS and Windows do not allow us users (even Administrators) to erase such partitions.

Lucky for us, the friendly folks at WinAbility have provided a detailed guide on how to remove such a protected partition on Windows. Enjoy the article!

  • http://www.winability.com/delete-protected-efi-disk-partition/

What’s the difference between the Logitech M325 and the M325c

The Logitech M325 and M325c are both wireless USB mice. Their design appears to be identical (except for the many different colourful variations of course), and their prices vary from anything between $12 and $60 – depending the layout and seller. Even the packaging is identical.

So what’s the difference between these two models? Is it precision?¬†Is it the build quality? Is it the year of production? Is it something else?

Actually no, the two mice are absolutely identical and both work with Windows, macOS and Linux. The only difference is in the wireless receiver that Logitech give you with each model.

The difference is the wireless receiver

The M325 comes with a Logitech Unifying Receiver. You can tell by the little “sunshine” logo on the side. This type of receiver allows us to use the Logitech Unifying Software to operate several devices over a single receiver (say a mouse and a keyboard). It’s a little clunky to setup more than one device, but it certainly saves valuable USB slots on your machine.

Note that for this to work, all decides must be Logitech unifying devices, and all must display that little sunshine logo.

The M325c on the other hand does NOT come with a unifying receiver, and instead comes with a standard USB receiver. Only this one device will work with said receiver. As you can imagine, the receiver does not bear the unifying logo on the side. Therefore you may find the M325c a little cheaper than the M325.

Note however that the M325c mouse itself IS a unifying device, and it DOES bear the unifying logo on the underside. Hence you can use the M325c mouse with another unifying receiver just fine.

So there you have it – that’s the big secret difference between these two mice. I have both, and I couldn’t tell the difference at first. The mice are identical, just the USB receiver is a little different. Just in case this question was driving you crazy too ūüôā

How to check which web server is running on a domain

Sometimes we must know what web server is running on a particular domain. Usually web hosts should be able to tell a client this, but if the client is afraid to ask, there is a way to ask the web server directly for this information.

Just to clarify: the web server is the process that serves files (HTML, PHP, ASP, images, etc) from a remote machine to your local web browser. The most likely choices in this day and age (2017) are Apache, NGINX or IIS. The latter is used by Windows servers, and the two former are used by Linux servers. There are other web servers too, such as¬†lighttpd, but they’re used less commonly.

By asking the web server for this information, we can tell exactly who’s serving those files.

How to ask the Web Server

Let’s open a Terminal or Command Line Prompt window and utilise the good old fashioned Telnet protocol. Replace yourserver.com with the actual domain in question: Continue reading How to check which web server is running on a domain

How to reset the admin password in Plesk Onyx

It’s not pretty when it happens, but it happens to the best of us: you forget the admin password for your Plesk Onyx installation.

In previous versions there was an option to retrieve this password via the command line, but that special command has been removed in Onyx for security reasons.

So what can we do? Well luckily it’s relatively easy to reset the password to something else, or gain temporary access to the server quickly. Let me show you how. Continue reading How to reset the admin password in Plesk Onyx

How to fix duplicate packages in yum

From time to time, the yum package manager may encounter issues with duplicate packages that are erroneously installed on a system. This manifests in a yum update going awry, telling us something along the lines of this:

You may at times install all other packages via yum update –skip-broken, but it will still leave some trouble on the system. Best to take care of it.

Here’s how I’ve managed to do it on many occasions:
Continue reading How to fix duplicate packages in yum

How to print the current date and time in BASH shell scripts

Sometimes it’s useful to print the current time and date in a BASH script. We can make use of the date command for that. By default, and if called without any parameters, it’ll print something like this:

We can shorten this to just the date by using a formatting shortcut like this:

or just the time using this format:

Formatting shortcuts can also be used together, like so:

For a complete list of shortcuts, try “man date” from the command line.

  • https://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/

How to use functions in a BASH shell script

BASH can deal with simple functions, and they are defined like this:

As far as I know, BASH functions cannot take or return parameters.