Monthly Archives: August 2017

Today is a Good Day to Learn Python | Linux.com


The cool thing about Linux and FOSS is also an aggravating thing, which is that sometimes there’s too much of a good thing. There is such an abundance of goodies that it can be overwhelming. So I am here to help you decide which programming language you should learn next, and that is Python. Oh, yes, it is.

Why Python? I like it because it is clean and straightforward. It’s a great introduction to object-oriented languages. The Python world is beginner-friendly and, as a general-purpose language, Python can be used for all sorts of things: quick simple scripts, games, Web development, Raspberry Pi — anything you want. It is also in demand by employers if you’re thinking of a career.

There are numerous excellent Python books and tons of online documentation. I want to show off Python’s coolness for beginners so you will get excited and go “Yes! I too must love Python!”

But what about all the other languages? Don’t worry, they won’t get lonesome, and everything you learn in Python is applicable to many other languages as well.

What Stuff Means

I think most of us learn terminology better with hands-on exercises, but there are four things to know from the start.

The first is Python is strongly typed. As you study Python, you will see this repeated a gazillion times. What does this even mean? Who uses a typewriter? Fortunately, it has nothing to do with typewriters, but rather with how Python handles data types. All computer programs are made of two things: data, and operating on that data. Data comes in different types, and the types determine how your programming language will handle them. Data types include characters or strings, which are literal numbers and letters, like names and addresses; integers and floating point numbers that are used in calculations; Boolean values (true/false); and arrays, which are lists of data of all the same data types.

Python enforces data types and relies on you to define them. Weakly typed languages decide for themselves what your data types are, so the data type can change depending on context.

For example, most any programming language will add the integers 1 + 2 + 3. A weakly typed language may also let you add integers and text strings, for example 5 + helloworld. If you try to do this in Python, your code will fail and you will get an error message. Weakly typed languages don’t do this randomly; this is a feature intended to add speed and flexibility by not requiring you to define your data types.

However, weak typing can lead to strange errors. One of the most common errors involves converting strings of numbers to integers when you really want them to be a literal string, like 221B Baker Street, 10,000 Maniacs, or 23andMe. In my modest opinion, it is better to learn the discipline and structure of a strongly typed language, and then try out weakly typed languages after you have experience and good grounding in the basics.

The second thing to know is what the heck is object oriented programming (OOP)? An object is a clump of data and procedures grouped into a single reusable entity. If you were coding a car racing game you might have a car object, an obstacle object, and a driver object. So, you say, objects are just like functions, right? Yes. If you already understand how to organize code into properly grouped functions and variables, then you already understand OOP. There are finer points to OOP such as classes, inheritance, and polymorphism; again, if you think in terms of sensible organization these things are easier to understand.

Third, white space has meaning in Python. You have to get your white spaces right or your code won’t work.

Fourth, Python is an interpreted language. You don’t have to compile and link your Python programs. If you’re experienced with the Bash shell, then you already know about interpreted languages, how fast they are to code in, and how you can test out your programs interactively before writing them into a script.

The downside to interpreted languages is the overhead of the interpreter. Usually, programs written in compiled languages run faster. However, you can link your Python programs to functions written in many other languages, including C/C++, Lisp, Fortran, Java, and Perl, and many more so you can mix and match to get the results you want.

Try It

Python is included in most Linux distributions, and usually the python package installs the base components and Python command interpreter. The text in bold is what you type.

$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help()

Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/2.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> topics

Here is a list of available topics.  Enter any topic name to get more help.

ASSERTION  DEBUGGING LITERALS SEQUENCEMETHODS2
ASSIGNMENT DELETION  LOOPING  SEQUENCES
[...]
help> quit

Of course we must do the traditional Hello World! Strings must be enclosed in single or double quotes.

>>> 'Hello, world!'
'Hello, world!'
>>> hell = "Hello, world!"
>>> hell
'Hello, world!'

Now create the simplest possible Python script, save it as hello.py, and run it from your normal Linux shell:

#!/usr/bin/python

print "Hello World!";

carla@studio:~$ python hello.py
Hello World!

Let’s go back to the Python interpreter and play with data types.

>>> 2 + 2
4
>>> 2 + foo
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'foo' is not defined
>>> foo = 5
>>> 2 + foo
7

Now try a short interactive script. It asks you to input your age, responds according to the age you type, and checks if your response is in the correct data type. This is a great little script to tweak in different ways. For example, you could limit the acceptable age range, limit the number of incorrect tries, and get creative with your responses. Note that raw_input is for Python 2.x, and 3.x uses input.

Watch your indentation; the indented lines must be four spaces. If you are using a proper code editor, it should take care of this for you.

#!/usr/bin/python

while True:
    try:
        age = int(raw_input("Please enter your age: "))
    except ValueError:
        print("I'm so very sorry, that does not compute. Please try again.")
        continue
    else:
        break
if age >= 18: 
    print("Very good, you are old enough to know better, but not too old to do it anyway.")
else:
    print("Sorry, come back when you're 18 and try again.")

Modules and Learning

There are a great number of Python modules, and you can learn to write your own. The key to writing good Python programs and making them do what you want is learning where to find modules. Start at Python.org because of the abundant documentation and good organization. Plan to spend a lot of time here, because it contains the best and authoritative information. It even has an interactive shell you can practice with.

Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.

Guide to Linux App Is a Handy Tool for Every Level of Linux User | Linux.com


Remember when you first started out with Linux? Depending on the environment you’re coming from, the learning curve can be somewhat challenging. Take, for instance, the number of commands found in /usr/bin alone. On my current Elementary OS system, that number is 1,944. Of course, not all of those are actual commands (or commands I would use), but the number is significant.

Because of that (and many other differences from other platforms), new users (and some already skilled users) need a bit of help now and then.

For every administrator, there are certain skills that are must-have:

When you seek out assistance, sometimes you’ll be met with RTFM (Read the Fine/Freaking/Funky Manual). That doesn’t always help when you have no idea what you’re looking for. That’s when you’ll be glad for apps like Guide to Linux.

Unlike most of the content you’ll find here on Linux.com, this particular article is about an Android app. Why? Because this particular app happens to be geared toward helping users learn Linux.

And it does a fine job.

I’m going to give you fair warning about this app—it’s not perfect. Guide to Linux is filled with broken English, bad punctuation, and (if you’re a purist) it never mentions GNU. On top of that, one particular feature (one that would normally be very helpful to users) doesn’t function enough to be useful. Outside of that, Guide to Linux might well be one of your best bets for having a mobile “pocket guide” to the Linux platform.

With this app, you’ll enjoy:

  • Offline usage.

  • Linux Tutorial.

  • Details of all basic and advanced Linux commands of Linux.

  • Includes command examples and syntax.

  • Dedicated Shell Script module.

On top of that, Guide to Linux is free (although it does contain ads). If you want to get rid of the ads, there’s an in-app purchase ($2.99 USD/year) to take care of that.

Let’s install this app and then take a look at the constituent parts.

Installation

Like all Android apps, installation of Guide to Linux is incredibly simple. All you have to do is follow these easy steps:

  1. Open up the Google Play Store on your Android device

  2. Search for Guide to Linux

  3. Locate and tap the entry by Essence Infotech

  4. Tap Install

  5. Allow the installation to complete

Once installed, you’ll find the launcher for Guide to Linux in either your App Drawer or on your home screen (or both). Tap the icon to launch the app.

Usage

Let’s take a look at the individual features that make up Guide to Linux. You will probably find some features more helpful than others, and your experience will vary. Before we break it down, I’ll make mention of the interface. The developer has done a great job of creating an easy-to-use interface for the app. 

From the main window (Figure 1), you can gain easy access to the four features.

Tap any one of the four icons to launch a feature and you’re ready to learn.

Tutorial

Let’s start out with the most newbie-friendly feature of the app—Tutorial. Open up that feature and you’ll be greeted by the first section of the tutorial, “Introduction to the Linux Operating System” (Figure 2).

If you tap the “hamburger menu” (three horizontal lines in the top left corner), the Table of Contents are revealed (Figure 3), so you can select any of the available sections within the Tutorial.

Unless you haven’t figured it out by now, the Tutorial section of Guide to Linux is a collection of short essays on each topic. The essays include pictures and (in some cases) links that will send you to specific web sites (as needed to suit a topic). There is no interaction here, just reading. However, this is a great place to start, as the developer has done a solid job of describing the various sections (grammar notwithstanding).

Although you will see a search option at the top of the window, I haven’t found that feature to be even remotely effective—but it’s there for you to try.

For new Linux users, looking to add Linux administration to their toolkit, you’ll want to read through this entire Tutorial. Once you’ve done that, move on to the next section.

Commands

The Commands feature is like having the man pages, in hand, for many of the most frequently used Linux commands. When you first open this, you will be greeted by an introduction that explains the advantage of using commands.

Once you’ve read through that you can either tap the right-facing arrow (at the bottom of the screen) or tap the “hamburger menu” and then select the command you want to learn about from the sidebar (Figure 4).

Tap on one of the commands and you can then read through the explanation of the command in question. Each page explains the command and its options as well as offers up examples of how to use the command.

Shell Script

At this point, you’re starting to understand Linux and you have a solid grasp on commands. Now it’s time to start understanding shell scripts. This section is set up in the same fashion as is the Tutorial and Commands sections.

You can open up a sidebar Table of Contents to take and then open up any of the sections that comprise the Shell Script tutorial (Figure 5).

Once again, the developer has done a great job of explaining how to get the most out of shell scripting. For anyone interested in learning the ins and outs of shell scripting, this is a pretty good place to start.

Terminal

Now we get to the section where your mileage may vary. The developer has included a terminal emulator with the app. Unfortunately, when installing this on an unrooted Android device, you’ll find yourself locked into a read-only file system, where most of the commands simply won’t work. However, I did install Guide to Linux on a Pixel 2 (via the Android app store) and was able to get a bit more usage from the feature (if only slightly). On a OnePlus 3 (not rooted), no matter what directory I change into, I get the same “permission denied” error, even for a simple ls command.

On the Chromebook, however, all is well (Figure 6). Sort of. We’re still working with a read-only file system (so you cannot actually work with or create new files).

Remember, this isn’t actually a full-blown terminal, but a way for new users to understand how the terminal works. Unfortunately, most users are going to find themselves frustrated with this feature of the tool, simply because they cannot put to use what they’ve learned within the other sections. It might behoove the developer to re-tool the terminal feature as a sandboxed Linux file system, so users could actually learn with it. Every time a user would open that tool, it could revert to its original state. Just a thought.

In the end…

Even with the terminal feature being a bit hamstrung by the read-only filesystem (almost to the point of being useless), Guide to Linux is a great tool for users new to Linux. With this guide to Linux, you’ll learn enough about Linux, commands, and shell scripting to feel like you have a head start, even before you install that first distribution.

Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.

Building a New Storage Roadmap


It’s safe to say that we haven’t had this much happening in enterprise data storage for three decades. Things are evolving on every front, from software to networks, from drive interfaces to drives themselves and the vendor landscape is rapidly changing, with many new players and some signs of struggle among the old leaders.

The Dell-EMC merger is one of the waves of change flooding through what had once been the steadiest and slowest-evolving segment of IT. Here was the giant of the storage industry recognizing that business fundamentals such as hardware platforms were becoming commodities and that failing to adopt a software and services worldview was a recipe for disaster.

Who would have thought the mighty RAID array would begin to lose market share so quickly? Likewise, even leading-edge pundits are surprised at the growth of public clouds, while the 100 TB 2.5 inch solid-state drives projected to arrive in 2018 have hard-drive makers a bit panicked, especially Seagate.

You might be taken aback if I say all these changes are  just a taste of what’s ahead. The next three or four years will see a much wider restructuring of storage, impacting what and how we store data in ways that will astonish, surprise and perhaps even scare you. The idea of fixed-size blocks of data has been in place for so long that it is a pillar of the storage faith. With some of the new technology, storage becomes byte-addressable and everything we know about storing an entry changes, from hardware to operating systems, compilers and applications.

Byte-addressability is on Intel’s Optane roadmap, so it’s real. Remember, Intel can do the CPU tweaks for space management; it owns the leading compilers and link editors, so that code can be created to a standard, and it has storage devices in the pipeline.  The result will be blindingly fast data storage. Instead of moving 4K bytes using a driver and SCSI software stack, data can be permanently stored with a single CPU command!

If all of this isn’t enough, servers and storage appliances are converging on a common design, where the storage bays of a server are sufficient for a set of very fast SSDs, which then can be accessed across the cluster as a pool of storage.

But there’s more! Instead of the hierarchical architectural model that has been around from the start of the computing era, new server designers, such as Gen-Z, place memory and storage at the same peer level as CPUs, GPUs, and networks on a shared fabric. Now all of these super-blocks can reach out over the fabric to other computers and read and write directly to their memory or storage. This is indeed a “pool of resources,” but managing it requires a new view of how resources are accessed and allocated.

Software-defined infrastructure is the new mantra for these virtualized systems. All the resources are virtual elements in a shared pool, with policy-driven orchestration managing the virtual resources and tying them to physical gear as needed.

Part of the SDI concept is the use of chainable microservices, with instances being created to host more copies of any service as needed to meet demand. With software services so divorced from the base hardware, the value of the system shifts to the services and the hardware becomes standardized, but very inexpensive. This underscores the wisdom of the Dell-EMC merger.

Let’s take a closer look at the changes ahead for enterprise data storage.

(Image: WIRACHAIPHOTO/Shutterstock)

 



Source link

Splitting and Re-Assembling Files in Linux | Linux.com


Linux has several utilities for splitting up files. So why would you want to split your files? One use case is to split a large file into smaller sizes so that it fits on smaller media, like USB sticks. This is also a good trick to transfer files via USB sticks when you’re stuck with FAT32, which has a maximum file size of 4GB, and your files are bigger than that. Another use case is to speed up network file transfers, because parallel transfers of small files are usually faster.

We’ll learn how to use csplit, split, and cat to chop up and then put files back together. These work on any file type: text, image, audio, .iso, you name it.

Split Files With csplit

csplit is one of those funny little commands that has been around forever, and when you discover it you wonder how you ever made it through life without it. csplit divides single files into multiple files. This example demonstrates its simplest invocation, which divides the file foo.txt into three files, split at line numbers 17 and 33:

$ csplit foo.txt 17 33
2591
3889
2359

csplit creates three new files in the current directory, and prints the sizes of your new files in bytes. By default, each new file is named xxnn:

$ ls
xx00
xx01
xx02

You can view the first ten lines of each of your new files all at once with the head command:

$ head xx*

==> xx00 <==
Foo File
by Carla Schroder

Foo text

Foo subheading

More foo text

==> xx01 <==
Foo text

Foo subheading

More foo text

==> xx02 <==
Foo text

Foo subheading

More foo text

What if you want to split a file into several files all containing the same number of lines? Specify the number of lines, and then enclose the number of repetitions in curly braces. This example repeats the split 4 times, and dumps the leftover in the last file:

$ csplit foo.txt 5 {4}
57
1488
249
1866
3798

You may use the asterisk wildcard to tell csplit to repeat your split as many times as possible. Which sounds cool, but it fails if the file does not divide evenly:

$ csplit foo.txt 10 {*}
1545
2115
1848
1901
csplit: '10': line number out of range on repetition 4
1430

The default behavior is to delete the output files on errors. You can foil this with the -k option, which will not remove the output files when there are errors. Another gotcha is every time you run csplit it overwrites the previous files it created, so give your splits new filenames to save them. Use --prefix=prefix to set a different file prefix:

$ csplit -k --prefix=mine foo.txt 5 {*}  
57
1488
249
1866
993
csplit: '5': line number out of range on repetition 9
437

$ ls
mine00
mine01
mine02
mine03 
mine04
mine05

The -n option changes the number of digits used to number your files:

 
$ csplit -n 3 --prefix=mine foo.txt 5 {4}
57
1488
249
1866
1381
3798

$ ls
mine000
mine001
mine002
mine003
mine004
mine005

The “c” in csplit is “context”. This means you can split your files based on all manner of arbitrary matches and clever regular expressions. This example splits the file into two parts. The first file ends at the line that precedes the line containing the first occurrence of “fie”, and the second file starts with the line that includes “fie”.

$ csplit foo.txt /fie/ 

Split the file at every occurrence of “fie”:

$ csplit foo.txt /fie/ {*}

Split the file at the first 5 occurrences of “fie”:

$ csplit foo.txt /fie/ {5}

Copy only the content that starts with the line that includes “fie”, and omit everything that comes before it:

$ csplit myfile %fie% 

Splitting Files into Sizes

split is similar to csplit. It splits files into specific sizes, which is fabulous when you’re splitting large files to copy to small media, or for network transfers. The default size is 1000 lines:

$ split foo.mv
$ ls -hl
266K Aug 21 16:58 xaa
267K Aug 21 16:58 xab
315K Aug 21 16:58 xac
[...]

They come out to a similar size, but you can specify any size you want. This example is 20 megabytes:

$ split -b 20M foo.mv

The size abbreviations are K, M, G, T, P, E, Z, Y (powers of 1024), or KB, MB, GB, and so on for powers of 1000.

Choose your own prefix and suffix for the filenames:

$ split -a 3 --numeric-suffixes=9 --additional-suffix=mine foo.mv SB
240K Aug 21 17:44 SB009mine
214K Aug 21 17:44 SB010mine
220K Aug 21 17:44 SB011mine

The -a controls how many numeric digits there are. --numeric-suffixes sets the starting point for numbering. The default prefix is x, and you can set a different prefix by typing it after the filename.

Putting Split Files Together

You probably want to reassemble your files at some point. Good old cat takes care of this:

$ cat SB0* > foo2.txt

The asterisk wildcard in the example will snag any file that starts with SB0, which may not give the results you want. You can make a more exact match with question mark wildcards, using one per character:

$ cat SB0?????? > foo2.txt

As always, consult the relevant and man and info pages for complete command options.

Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.

SQL Server Comes to RHEL; OpenShift Comes to Azure » Linux Magazine


Red Hat and Microsoft have expanded their partnership this week by bringing some of their core technologies to each other’s platforms. The two companies have worked together to support Windows Server containers natively on Red Hat OpenShift, a Kubernetes-based container application platform.

According to Red Hat, OpenShift will be the first container application platform built from the open source Kubernetes project to support both Linux and Windows container workloads in a single platform across the multiple environments of the hybrid cloud. Red Hat will offer a technology preview of the technology in 2018. Red Hat is also bringing its OpenShift and OpenShift Dedicated to Azure, Microsoft’s cloud platform.

The companies also plan to collaborate on delivering enterprise performance standards and integrated support for Red Hat Enterprise Linux workloads running in Microsoft Azure Stack, an extension of Azure that brings cloud computing to on-premises environments.

The two companies are bringing .NET Core 2.0 as a container in OpenShift and Microsoft’s SQL Server for Linux to Red Hat Enterprise Linux and Red Hat OpenShift.

Red Hat said in a press release that the two companies will extend the integrated, co-located Microsoft and Red Hat support to enable these new offerings across platforms.



Source link