Although you may think that you have learned to master Linux command line with bash shell, there are always some new tricks to learn to make your command line skills more efficient. This article will teach you a few more basic tricks on how to make your life with the Linux command line & bash more bearable and even enjoyable.
Bash Command History Expansion
This section will mostly deal with bash shortcuts in combination with three bash history expansion characters "!", "^" and "#". Bash Command History Expansion character "!" indicates start of history expansion. The "^" is a substitution character to modify a previously run command. The last optional character is "#", which denotes the reminder of the line as a comment.
For most of us WEP encryption has become a joke. WPA is quickly going the same way thanks to many tools such as Aircrack-ng. On top of this, wired networks are no strangers to unwanted guests as well. Anyone serious about security should have a good Intrusion Detection system in their toolbox.
There are already some very good IDS's (Intrusion Detection Systems) available. Why would anyone want to re-invent the wheel in Bash??? There are a couple of reasons for this. Obviously Bash scripts can be very light weight. Especially compared to some of the GUI programs that are out there. While programs like Etherape suck us in with pretty colors, they require constant monitoring to know when the network has changed. If you are like most of us, you only use the computer for two things, work and play. By using the system bell to alert for new clients online you can leave this script running and not have to have a constant watch. If you do decide you want to inspect what a suspicious client is doing more closely, you can always open up etherape, wireshark, or your tool of choice. But until you have a problem you can play or work on other things.
Another bonus to this program is that it will only show ip addresses on the networks connected to your computer. If you were hosting a busy server or perhaps downloading the latest Linux distro though a torrent client, an IDS may be flooded with connections. Looking for a new malicious client can be like looking for a needle in a hay stack. While this script may seem simple compared to other IDS's, simplicity can have its perks too.
What you will need
Nmap is required for this script to work. We will not be doing any port scanning. However, to make this script fast we needed something better than a regular ping. Nmap's -sP parameter will only use a ping scan to check if a clients up. There were some variations in how Nmap outputs information between versions. So far this script has only been tested using Nmap 5.00 (Debian Squeeze) and 5.21 (Debian Sid). You may have luck with other distros and versions of Nmap. However, with all the possibilities I could only support a couple at this time.
If you already have some experience as a Linux system administrator, chances are you know what cron is and what it does. If you're just starting working with Linux, it's essential knowledge that will certainly serve you later. Either way, if you already have the knowledge, this article will refresh it. If not, you will get a guide to start you up. So you're only expected to have some basic knowledge of Linux systems and, as usual, a desire to learn.
Cron's name comes from Chronos, the Greek personification of time. And it's a very inspired choice, because cron helps you schedule different tasks you want your system to perform at given times. If you used Windows systems, chances are you stumbled across the Scheduled Tasks tool. Generally speaking, the purpose is the same, the differences are...well, too many to name here. The idea is cron is more flexible and appropriate for serious system management tasks. If you need some example use cases, just think about backups : do you want to perform backup tasks when you're responsible for hundreds of machines? We thought not. You just write a simple shell script using rsync, for example, schedule it to run, say, daily and forget about it. All you have to do now is check the logs from time to time. We even know people that use cron to remind them of important personal events, like birthdays.
But cron is just a daemon running the tasks you tell it to run. Is there a tool to help us edit/add/remove those tasks? Of course, and it's called crontab (the name comes from cron table). But let us start from step one : installation.
The aim of this article is to provide an overview of the GNU R programming language. It starts a series of articles devoted to programming with R. Its objective is to present, in an organized and concise manner, the elementary components of the R programming language. It is designed to help you understand R code and write your own. It is assumed that the reader has already some basic programming knowledge of R. If you are not familiar with any of R features it is recommended that you first read A quick GNU R tutorial to basic operations, functions and data structures.
An R expression is an elementary component of R code. Expression in R can be:
Whether you would like to share your code and data with other people or simply pack up your code in a concise way, the ability of building a custom package in GNU R may come useful to you. In this article we will outline as clearly as possible the process of building a basic package in R. This does not include more advanced knowledge on building R packages. This tutorial, however, will get you started. You may also find How to install and use packages in GNU R of help if you are not familiar with using R packages at all.
Creating a package structure
Every package consists of a set of functions that are programmed to apply with a common aim. Additionally, a sample data is often provided with the package in R. Let us now propose a simple example. Below we defined four R objects: two functions div() and pow() and two data sets in a form of two vectors data1 and data2.
GNU R offers a wide variety of packages for its users. There are all kinds of packages for R, which allow to display graphics or perform statistical tests. Some packages are designed for applications specific to a given industry. Many packages are already a part of the basic R installation, however, some of them need to be additionally installed into GNU R. This article will describe how to install and use packages under R.
What is a Package
A package is a set of functions, help files and data files that have been linked together. In order to use a package in R you need to first make sure that it is installed in the local library. In general, the one system-level library is used for storing the default R packages. You can, however, add additional libraries. You also need to remember about loading packages into your current R session. This is very important when using R. It is recommended that you do not load too many packages at the time. Loading a large number of packages may result in errors due to clashes of function names coming from two different packages.
In this quick GNU R tutorial to statistical models and graphics we will provide a simple linear regression example and learn how to perform such basic statistical analysis of data. This analysis will be accompanied by graphical examples, which will take us closer to producing plots and charts with GNU R. If you are not familiar with using R at all please have a look at the prerequisite tutorial: A quick GNU R tutorial to basic operations, functions and data structures.
Models and Formulas in R
We understand a model in statistics as a concise description of data. Such presentation of data is usually exhibited with a mathematical formula. R has its own way to represent relationships between variables. For instance, the following relationship y=c0+c1x1+c2x2+...+cnxn+r is in R written as
which is a formula object.
Linear regression example
Let us now provide a linear regression example for GNU R, which consists of two parts. In the first part of this example we will study a relationship between the financial index returns denominated in the US dollar and such returns denominated in the Canadian dollar. Additionally in the second part of the example we add one more variable to our analysis, which are returns of the index denominated in Euro.
In the last two articles we have learned how to install and run GNU R on the Linux operating system. The purpose of this article is to provide a quick reference tutorial to GNU R that contains introduction to the main objects of the R programming language . We will learn about basic operations in R, functions and variables. Moreover, we will introduce R data structures, objects and classes.
Basic Operations in R
Let us start with a simple mathematical example. Enter, for instance, addition of seven and three into your R console and press enter, as a result we obtain:
> 7+3  10
To explain in more detail what just happened and what is the terminology we use when running R, we say that the R interpreter printed an object returned by an expression entered into the R console. We should also mention that R interprets any number as a vector. Therefore, "" near our result means that the index of the first value displayed in the given row is one. This can be further clarified by defining a longer vector using the c() function. For example:
GNU R can be run on the Linux operating system in a number of ways. In this article we will describe running R from the command line, in an application window, in a batch mode and from a bash script. You will see that these various options for running R in Linux will suit a specific task. Some of them are more suitable for simple statistical analysis that can be done in one line of code, others for more sophisticated programs that require executions of a larger number of R expressions. Finally, we may want to run a program that will take a day or two to run on a Linux cluster. In this case we will run R in a background, which allows us for logging out from the cluster.
Running R from the Linux command line
Probably, the simplest way to run R under Linux is to run it from the Linux command line. That is,
As a result of this command the following appears:
R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.
This article will deal mainly with the installation of R on Linux, but also will provide a simple example on how to use R for plotting. This is the first article of the series of R articles so subscribe to our RSS feed for regular updates. Everyone, who is interested in using R for their work or is simply interested in this software is invited to follow this series of articles. The main objective of these articles is to provide a quick reference to R with illustrative examples.
What is GNU R?
R is an open source programming language (software package) and environment used mainly for statistical data analysis. It is licensed under the GNU General Public License (GPL). R is a very intuitive programming language. You can do in a few lines of R code a lot, mainly because there is a large number of packages available for R, which means a large number of preprogrammed functions for you to use. You can get R packages through Comprehensive R Archive Network (CRAN).
R's strengths are: graphical visualization of data such as plots, data analysis, statistical data fits.
R's weaknesses are: complex structured data storage, querying data, dealing with large data sets, which do not fit in the computer's memory.
Installing GNU R on Linux/Unix.
Package Management System
Debian / Ubuntu / Mint
On Debian like Linux systems such as Debian, Ubuntu or Linux Mint you can install R from standard repositories. This is a preferred way of getting R installed on your system. The command bellow will download and install R along with all its prerequisites:
First and foremost, a word of warning: while the previousarticles were centered around the beginner, this article is for more advanced users, that already "speak" a programming language or two, and want to customize their editor towards it being ideal for the task. So you are expected to be more or less proficient in the ways of emacs, to be able to use it for day to day tasks and have the ability and desire to learn something new. After all, it will be for your own reward, and your programming tasks will become more efficient. Our approach will be to take a few popular languages, show you how to configure emacs for the perfect development environment, then move on to the next language. Emacs configuration is made in a Lisp dialect called Elisp, but don't worry if you don't know it yet, we'll tell you what you need.
First, some background. This article is about emacs, not about any derivative like mg or jed that might or might not offer the desired functionality. That's because many derivatives were born from the need of creating a smaller emacs, since the original is pretty big, admittedly. So in the process of removing functionality there might just be just some functionality that's getting removed and we probably will need here. In short, emacs-only. Second, the files. In our examples, besides customizing the ~/.emacs file, we will create a directory named ~/.emacs.d/ where we will place our modes. Just as emacs knows what kind of syntax highlighting, indentation, etc. to use for several types of text, like HTML, TeX, C source code, and others, via modes, we can add/modify modes to our liking, to this is what we'll do. Practically speaking, a mode is a file with a .el extension (from Elisp) that will be dropped in ~/.emacs.d, then ~/.emacs will be altered for the editor to "know" about the new extension. You'll see in a few moments, depending on how fast you read.
Of course, we wouldn't have had it any other way: we wanted to be fair, as pledged, so here is the vim article, which is a counterpart of our last one on how to make your editor the perfect programming environment. So you must have the following profile for this article to be really useful to you: you know your way around programming, so you subsequently know what you would like in an editor, and you also know your way around vim, preferably more than what we talked about in the article dedicated to it. If you read the customizing emacs article, you already have a good idea on how this article is going to be structured. If you were directed here from somewhere else, here's what we're gonna do: we'll take some popular programming language (space permitting) and show you how to tweak vim so it will became more fit for coding in that language.
Although vim is written entirely in C, there is something named vimscript that makes creating/editing settings, sort of like Elisp in emacs, although this is a loose comparison. Please remember that whatever will be talked about here is only about vim. Not BSD vi, not some vi extension for another editor, just vim. That is because although you can learn the basics on, say, nvi, the things that interest us (since you already know the basics) will only work on vim. Of course, some recent version, not older than 7.3.x. Many things will probably work on 7.x or maybe even 6.x, but there's no guarantee.
Just as before, a little advice: although this is influenced by personal preference, experience says it works; namely, install scripts/addons/color schemes directly from the source, regardless if your distro offers it as well. That's because many maintainers tend to package stuff with respect to their personal preference, which might or might not be in concordance with yours. Installing such addons is as simple as copying a file to a location, nothing more. And, for your convenience, we'll tell you how to install via your package manager anyway.
The distributions I have available to me at this point are Debian, Fedora, Gentoo and Arch. I will do a search for the 'vim' keyword on each of them and give you some tips and pointers on what you can install, then we'll go language-specific.