Category: Linux Toggle Comment Threads | Keyboard Shortcuts

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.

  • Jay Versluis 10:35 am on September 26, 2017 Permalink | Reply
    Tags:   

    Categories: Linux ( 96 )

    How to find out which version of GNOME you’re using 

    In the GNOME desktop, there is no obvious way to tell which version you’re running by way of the GUI. Instead, we need to consult the command line and try out a couple of commands to find out more. Here’s how.

    Let’s open a Terminal session and do some hacking.

    GNOME 2.x

    If you’re running GNOME 2.x (under CentOS 6 for example), you need to run the following command:

    gnome-session --version
    
    gnome-session 2.28.0

    You may need to prefix this command with sudo, otherwise it will tell you that you’re alrady running a GNOME session.

    Should the above not work, you’re likely on GNOME 3 (see next).

    GNOME 3.x

    GNOME 3 uses a different command, namely this one:

    gnome-panel --version
    
    gnome-panel 3.24.2

    If you don’t know which version of the GNOME panel you’re using (which is likely), try both commands. One of them will work, the other one won’t.





     
  • Jay Versluis 3:11 pm on June 25, 2017 Permalink | Reply
    Tags: Command Line   

    Categories: Linux ( 96 )

    How to rename a batch of files in Linux 

    Bulk renaming files can be done with the rename command. It shares many similarities with cp and mv, but its simplicity can be so staggering that its difficult to figure out how to use it.

    If we just type “rename” at the command prompt, all we get is the message

    rename
    call: rename from to files...

    While technically correct, what on earth does it mean? How do we use rename?

    Let’s do a little exercise. Imagine we had a batch of files, perhaps something like “Title 101.mp4” to “Title 110.mp4”. Let’s create some empty files with those names in a test directory:

    mkdir test
    cd ./test
    touch 'Title '{101..110}.mp4
    ls

    So far so good. Now we’d like to rename those files so they read “New Title 101.mp4” to “New Title 110.mp4”. Here’s how it works:

    rename 'Title' 'New Title' *.mp4

    Technically, this follows what the command showed us earlier: “rename from to files…”. Still I feel a little explanation is in order.

    For the rename command to work, we don’t need to specify the full file name, nor that we want to rename a batch of files. The command will rename anything that it encounters. All it needs to know is which string to replace with which other string. Those are the first two parameters we give it, in our case wrapped in single quotes because we have a space character in our titles.

    The third parameter tells rename where the files live that we want to rename. In our example it was here in the current directory, but it could be anywhere on the system. By specifying *.mp4, only files with that ending will be renamed, all other files will be left in peace.

    I hope this helps to understand rename a little better.





     
  • Jay Versluis 12:01 pm on June 18, 2017 Permalink | Reply
    Tags:   

    Categories: Linux ( 96 )

    How to exit VI with or without saving 

    Although many alternatives exist, I like using vi for all my command line editing needs. To save changes, I usually use SHIFT + Z + Z, exiting vi under most circumstances.

    But sometimes, this trick doesn’t work because of write permission problems. In such cases, vi doesn’t close with the above command. Instead, we must either stash our changes in another file, or quit the session without saving. Here’s how to do that.

    Quit vi without saving:
    :q!

    Save current file under a different name:
    :w newfile





     
  • Jay Versluis 4:36 pm on June 17, 2017 Permalink | Reply
    Tags:   

    Categories: Linux ( 96 )

    How to read command line parameters in BASH Scripts 

    Shell Scripts (BASH Scripts) can access command line parameters using the the variables $1, $2, $2 and so forth, up to $9. In fact, more parameters can be accessed by using curly brackets, like ${10}, ${187} and so forth.

    Here’s an example:

    #!/bin/bash
    
    if [[ $1 == "x" ]]; then
      echo "Statement is true"
    else
      echo "Statement is false"
    fi
    

    If we run the script with like this

    script.sh x
    

    it will tell us the statement is true. Otherwise, it’ll tell us the opposite.

    Note the whitespace around the evaluation: [[ ]] is actually a command (much like the == operator) and therefore needs to be surrounded with whitespace.





     
  • Jay Versluis 3:10 pm on June 17, 2017 Permalink | Reply
    Tags:   

    Categories: Linux ( 96 )

    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:

    #!/usr/bin/php
    <?php
    
    echo var_dump($argv);
    echo "\n";
    
    if ($argv[1] == 'x') {
      echo "The parameter is x.";
    } else {
      echo "The parameter was something else.";
    }
    

    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

    script.php x
    

    to give it one parameter, or with

    script.php x y z
    

    to give it three parameters.





     
  • Jay Versluis 11:29 am on June 17, 2017 Permalink | Reply
    Tags: tar   

    Categories: Linux ( 96 )

    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:

    tar -xjf yourfile.tar.bz2
    

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

    bzip2 -d yourfile.tar.bz2
    

    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:

    bzip2 -dk yourfile.tar.z2
    

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





     
  • Jay Versluis 9:11 am on May 4, 2017 Permalink | Reply
    Tags:   

    Categories: Linux ( 96 )

    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. (More …)





     
  • Jay Versluis 6:02 pm on April 14, 2017 Permalink | Reply
    Tags: EFI   

    Categories: Bookmarks, Linux, Windows ( 18 )

    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!





     
  • Jay Versluis 4:54 pm on April 12, 2017 Permalink | Reply
    Tags:   

    Categories: Linux, Mac OS X, Windows ( 96 )

    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 🙂





     
    • me 6:32 pm on May 26, 2017 Permalink | Reply

      thank you for this simple and complete explanation

      • Jay Versluis 4:28 pm on May 27, 2017 Permalink | Reply

        You’re very welcome – it has been bugging me too 🙂

    • KY 11:50 pm on September 8, 2017 Permalink | Reply

      Thank you so much. Your article helped clear up the difference.

    • zulker 9:56 pm on November 25, 2017 Permalink | Reply

      Thanks you so much for the details! It was bugging me so much and literally was making me nuts! 🙂

  • Jay Versluis 11:51 am on April 8, 2017 Permalink | Reply
    Tags: ,   

    Categories: Linux, Windows ( 96 )

    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: (More …)





     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel