Tutorials

Tutorials

An introduction to the Unix terminal – part 2

Tutorials

An introduction to the Unix terminal – part 2

introduction Unix terminal - we'll look into some more advanced commands to accomplish administrative tasks on your PC from the Unix terminal.

The previous tutorial focused on basic file management commands that were useful in the Unix terminal. If you haven’t read the first tutorial, we’d recommend you do so now. Now we’ll look into some more advanced commands to accomplish administrative tasks on your PC from the Unix terminal.

Linux also includes some nifty tools and packages to get information about your computer, install updates and change settings. We’ll look at ifconfig, sudo and apt-get.

ifconfig is the Linux equivalent of ipconfig in Windows. It lets you see the IP address of your computer (if it’s connected to a network) and will helpfully throw a list of all your connected (or otherwise) network adapters on-screen. ifconfig without flags will show every adapter, whilst typing it as above with “eth0” (for Ethernet) and “wlan0” (for WiFi) will show only those adapter’s details.

1. Let’s try with all adapters. In a terminal window type ifconfig -a and press enter.

You’ll notice the details for the Ethernet port (including IP addresses and data usage) but also a “lo”. This is the loopback address, the “return to sender” localhost address. It’s a special address (127.0.0.1) that always maps to the computer itself.

introduction Unix terminal

The terminal output of the command ifconfig

To get details about running programs, memory usage and to see how much CPU each app is hogging, we’ll use top.

3. In any terminal window, just type top and press enter. you’ll see system resource usage similar to Task Manager in Windows (although Resource Monitor in Ubuntu is the GUI version of top).

introduction Unix terminal

The output of the “top” command

System Administration and Package Installation

If you’re familiar with Windows, you’ll remember the nag screen that got all up in your face every time you’d want to rummage around in Windows system settings. In Linux, you’ve got the same sort of thing in sudo. Every time you sniff near a terminal command that might muck about with system files, you’ll probably get denied. Prepend sudo in front of a command to “elevate” it and gain superuser access as you would in Windows by clicking “Yes” to a UAC prompt.

We’ll demonstrate the behaviour by combining it with another command: apt-get. The latter is the package manager which allows you to easily install apps, packages, and other dependencies. The Ubuntu software centre runs these commands too, just wrapped in a friendly GUI.

For this example, let’s install files to let our Ubuntu machine talk to Windows-networked PC’s. For this we need a package called samba.

4. Start by typing apt-get install samba and pressing enter. You’ll notice an error – because you don’t have permission to access the directory!

5. Let’s try again, with sudo. Type sudo apt-get install samba. You’ll be asked for your password; type it in. It may not show up as if you’ve typed anything, but that’s for security, so keep typing and press enter to confirm.

The progress of installing samba with apt-get

6. You’ll see it automatically run through everything it needs to, and will inform you how much space the operation will take. Once it’s done, it’ll automatically return to the terminal prompt, and our tools will have installed correctly. To remove them later, just use sudo apt-get remove samba.

Thought of any other useful commands that would be good for a Linux starter? Comment with your views on this article in the comments section below, and follow Hyperion Hub developments in the future if you’d like to see more articles like these for the South African market.

Programming 101 – learning Python

Tutorials

Programming 101 – learning Python

Learning Python - we introduce you to programming in this tutorial using a programming language called Python, a fairly easy-to-learn language.

Programming is an important and highly sought-after skill. It’s a great asset to have for any professional knowledge-worker in this information age. Aside from the career benefits, you can also learn programming to improve your logical thought processes, build the next awesome mobile app, or just have fun with something new. We introduce you to programming in this tutorial using a programming language called Python.

Introduction to Programming Languages

There are various programming languages out there – Visual Basic, Java, C, Python and PHP, amongst others. We use a programming language to write out a set of instructions that define how a computer program must function. Therefore, programming is the science and the art of telling the computer what to do. The language that a programmer may choose to use depends on a number of things; their past experience with programming, the type of problem they need to solve and the environment that the program will be running in. Different programming languages are designed for solving specific problems within a certain environment.

Why Python?

Since there so many programming languages around, designed for such diverse purposes, why should we choose to learn Python instead of something else? As the Python designers say on their website: “Python is a programming language that lets you work quickly and integrate systems more effectively.” As a new programmer, you want to start building interesting programs as soon as possible, and Python will not burden you with unnecessary complications that might quench your enthusiasm for learning this new skill. It’s an easy-to-use, and easy-to-learn language that will have you writing powerful code in no time! Let’s dive into it so you can experience it for yourself.

Getting Python

We’ll assume that you’ve got Python installed and ready to go before we begin. If you haven’t gotten around to installing Python yet or run into issues, read our handy guide to Installing Python first, then come back here and keep reading!

Getting Your Feet Wet!

The Python shell is an interactive environment where we write Python code and immediately see the results of the statements when we execute them. This is a great way to learn how to program because you receive immediate feedback on what you do. Now let’s introduce a few programming concepts using the interactive shell so that you can get acquainted with the language.

We’ll begin with some basic arithmetic.

  1. Type out the following on the shell and press the Enter key.

>>> 5 + 10

learning Python

Python calculates the result of the addition and displays it.

It’s all well and good that Python can compute mathematical results, but what happens if we want to save the output of our computations? Well, storage in Python is done via variables. A variable is an alphanumeric (letters and numbers) label that we give a storage space which keeps any values we put in it.

  1. To create a variable and store the first number in it type:

>>> numOne = 5

  1. Create a second variable called numTwo and store value 10 in it.
  2. To view the contents of the variables we have created, we simply type out their labels and execute the statement by pressing Enter.

In the statement above, we retrieved the contents of the variable numOne and numTwo by writing them out in the line of code to be executed. This is called referencing a variable.

  1. Create a third variable called numThree and store the sum of numOne and numTwo in it.
  2. Display the contents of numThree to see it the answer is correct.
learning Python
  1. Python performs all mathematical operations, we’re not limited to addition only.
  2. We can also store words in a variable. To create a variable with a word in it, execute the following line of code:

>>> string = “Hyperion Hub”

A word or collection of words written between quotation marks in Python is called a string. All programming languages use this term to refer to series of characters that are stored as a single complete unit. The terms is used because the letters are stored as a string of characters in the computer’s memory.

Note that we have to use quotation marks around the string we want to store in the variable. If we don’t add the quotation marks around the words, we get an error.

learning Python

Error messages are displayed in red font on the shell. This message is simply telling us that we have written code that doesn’t conform to the rules of the language.

  1. Create a variable called firstName and assign your first name to it.
  2. Create another variable called lastName and assign your last name to it.
  3. Check the contents of these variables to see that contents stored in them.
  4. Now create a variable named fullName by joining the first two strings together:

>>> fullName = firstName + lastName

The process of joining strings is called string concatenation.

  1. Check the contents of fullName. Do you notice anything wrong?

We write our full names with a space between the first and last name. Python doesn’t put in the space automatically for you. You need to be explicit, by concatenating a space after the first name.

>>> space = “ “.

  1. Rewrite the last statement and add the space between your first and last name.

The process of putting contents within a variable is called assignment. We assigned the value of the calculation to the variable second.

So we now know how to write arithmetic statements for Python to compute. We’ve also learnt how to assign a value to a variable through assignment, and later use the value through referencing. Finally, we learnt how to display the contents of a variable by simply writing out the label we gave it and executing that statement.

We also learnt that we can store different types of contents in variables. A string of characters can be stored in them and joined together, through concatenation. When we don’t follow the rules of Python when writing statements in the shell, we get an error message. These messages may seem cryptic at the moment, but as you gain experience with the language, you’ll learn what they mean and how they can help you fix your mistakes.

You’ve now grasped the absolute basics of Python through the interactive shell. Next we’ll learn how to do more interesting stuff with the language.

Comment with your views on this article in the comments section below, and follow Hyperion Hub developments in the future if you’d like to see more articles like these for the South African market. Here’s more information about HyperionDev’s Python short course. Alternatively, you could do the Full Stack Web Development course, which includes Python.

Programming 101 – installing Python

Tutorials

Programming 101 – installing Python

Installing Python - Before you learn how to program, you need to first download and install a copy of Python. This tutorial will show you how.

Before you learn how to program, you need to first download and install a copy of Python on your computer. This tutorial will walk you through that process. These instructions are for installing Python 3 onto a computer running Windows 8 using the stock Internet Explorer browser that comes bundled with the operating system. Note that this process should be identical or very similar if you are running another version of Windows, such as Windows 7 or 10, or a different browser such as Chrome or Firefox.

Downloading and Installing Python

  1. Firstly, navigate to the Python downloads page here, using your browser.
Installing Python

Python downloads page in Internet Explorer.

On the downloads page you are presented with the option of downloading the latest version of Python 2 or Python 3 via the two large yellow buttons. We will be using Python 3 in this series of tutorials. So click on the yellow button on the left to download the Windows installer.

  1. After clicking on the left download button, Internet Explorer will display a pop-up at the bottom of the window. It gives you the options to run, save or cancel. Select the run option to execute the web installer.

Internet Explorer download pop-up.

  1. After pressing the run button, Internet Explorer will firstly scan the file for viruses, then it will download and run it. This will result in the dialog box, shown below, to pop-up onto your screen.
Installing Python

Python installer application.

Before we click on Install Now, you need to ensure that you’ve checked the Add Python 3.5 to PATH option at the bottom of the dialog box.

Ensure option to add Python to the PATH is checked.

Checking this option automatically configures your system so that you can run Python through your terminal without any hassles.

  1. Now, hover your mouse on the Install Now option and click on it. The setup program will cause Windows to present a dialog box asking if you want to allow the program to make changes to your computer. Press yes to continue with the installation process. When the installation is complete, the setup program will present this success message to you:
Installing Python

Successful installation message.

You have successfully installed Python! Click on the close button to dismiss the window.

  1. Python comes bundled with an interactive shell application. This is an environment where you can write Python code, execute it, and immediately see the results of the code you’ve written. To test that we’ve successfully installed Python and everything is working perfectly, we’re going open this shell program and execute one line of code.

Search for “IDLE” in your applications and execute the program named IDLE (Python 3.5 32-bit). This is the shell we’re going to be working in. The decimal number immediately after the name Python tells you the version of Python you downloaded. It may be different if you’re viewing this tutorial after subsequent releases have been made by the Python developers. Running IDLE will present you with the shell window like the one displayed below:

Python interactive shell.

  1. Type out the following statement in the shell and press Enter:
>>> print('Hello world!')

This line of Python code tells the shell to print out the phrase “Hello world!” (Note that we don’t type out the three “>” characters that preceded the statement. That’s just a convention we use in the tutorials, along with the this font style, to indicate that this is a line of code in the shell). Python will respond by displaying the message Hello world! in blue font below the line of code you write.

Executing your first line of Python code!

Congratulations! You have not only downloaded and installed Python successfully, but you’ve also executed your first line of Python code.

Comment with your views on this article in the comments section below, and follow Hyperion Hub developments in the future if you’d like to see more articles like these for the South African market. Find out more about HyperionDev’s Python Software Developer course.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Still have questions?

Contact our Admissions Team, and a real person will get back to you.

Events

Stay tuned for live online sessions and in-person events. Discover more from our bootcamps experience with insights from our team and dedicated spaces to ask questions. Lucky attendees might get a chance to get a hold of limited discount codes.

No items found.