Sunday 30 September 2018

How to use variables in shell Scripting

In every programming language variables plays an important role , in Linux shell scripting we are using two types of variables : System Defined Variables & User Defined Variables.

A variable in a shell script is a means of referencing a numeric or character value. And unlike formal programming languages, a shell script doesn’t require you to declare a type for your variables

Shell Scripting, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Certification

In this article we will discuss variables, its types and how to set & use variables in shell scripting.

System Defined Variables :


These are the variables which are created and maintained by Operating System(Linux) itself. Generally these variables are defined in CAPITAL LETTERS. We can see these variables by using the command “$ set“. Some of the system defined variables are given below :

System Defined Variables Meaning
BASH=/bin/bash  Shell Name 
BASH_VERSION=4.1.2(1)  Bash Version
COLUMNS=80   No. of columns for our screen 
HOME=/home/lpicentral   Home Directory of the User 
LINES=25   No. of columns for our screen 
LOGNAME=LPICentral LPICentral Our logging name 
OSTYPE=Linux   OS type 
PATH=/usr/bin:/sbin:/bin:/usr/sbin   Path Settings 
PS1=[\u@\h \W]\$   Prompt Settings 
PWD=/home/lpicentral Current Working Directory 
SHELL=/bin/bash   Shell Name
USERNAME=lpicentral User name who is currently login to system 

To Print the value of above variables, use echo command as shown below :

# echo $HOME
# echo $USERNAME

We can tap into these environment variables from within your scripts by using the environment variable’s name preceded by a dollar sign. This is demonstrated in the following script:

$ cat myscript

#!/bin/bash
# display user information from the system.
echo “User info for userid: $USER”
echo UID: $UID
echo HOME: $HOME

Notice that the environment variables in the echo commands are replaced by their current values when the script is run. Also notice that we were able to place the $USER system variable within the double quotation marks in the first string, and the shell script was still able to figure out what we meant. There is a drawback to using this method, however. Look at what happens in this example:

$ echo “The cost of the item is $15”
The cost of the item is 5

That is obviously not what was intended. Whenever the script sees a dollar sign within quotes, it assumes you’re referencing a variable. In this example the script attempted to display the variable $1 (which was not defined), and then the number 5. To display an actual dollar sign, you must precede it with a backslash character:

$ echo “The cost of the item is \$15”
The cost of the item is $15

That’s better. The backslash allowed the shell script to interpret the dollar sign as an actual dollar sign, and not a variable.

User Defined Variables:


These variables are defined by users. A shell script allows us to set and use our own variables within the script. Setting variables allows you to temporarily store data and use it throughout the script, making the shell script more like a real computer program.

User variables can be any text string of up to 20 letters, digits, or an underscore character. User variables are case sensitive, so the variable Var1 is different from the variable var1. This little rule often gets novice script programmers in trouble.

Values are assigned to user variables using an equal sign. No spaces can appear between the variable, the equal sign, and the value (another trouble spot for novices). Here are a few examples of assigning values to user variables:

var1=10
var2=-57
var3=testing
var4=“still more testing”

The shell script automatically determines the data type used for the variable value. Variables defined within the shell script maintain their values throughout the life of the shell script but are deleted when the shell script completes.

Just like system variables, user variables can be referenced using the dollar sign:

$ cat test3
#!/bin/bash
# testing variables
days=10
guest=”Katie”
echo “$guest checked in $days days ago”
days=5
guest=”Jessica”
echo “$guest checked in $days days ago”
$

Running the script produces the following output:

$ chmod u+x test3
$ ./test3
Katie checked in 10 days ago
Jessica checked in 5 days ago
$

Each time the variable is referenced, it produces the value currently assigned to it. It’s important to remember that when referencing a variable value you use the dollar sign, but when referencing the variable to assign a value to it, you do not use the dollar sign. Here’s an example of what I mean:

$ cat test4
#!/bin/bash
# assigning a variable value to another variable
value1=10
value2=$value1
echo The resulting value is $value2
$

When you use the value of the value1 variable in the assignment statement, you must still use the dollar sign. This code produces the following output:

$ chmod u+x test4
$ ./test4
The resulting value is 10
$

If you forget the dollar sign, and make the value2 assignment line look like:

value2=value1
you get the following output:
$ ./test4
The resulting value is value1
$

Without the dollar sign the shell interprets the variable name as a normal text string, which is most likely not what you wanted.

Use of Backtick symbol (`) in shell variables :


The backtick allows you to assign the output of a shell command to a variable. While this doesn’t seem like much, it is a major building block in script programming.You must surround the entire command line command with backtick characters:

testing=`date`

The shell runs the command within the backticks and assigns the output to the variable testing. Here’s an example of creating a variable using the output from a normal shell command:

$ cat test5
#!/bin/bash
# using the backtick character
testing=`date`
echo “The date and time are: ” $testing
$

The variable testing receives the output from the date command, and it is used in the echo statement to display it. Running the shell script produces the following output:

$ chmod u+x test5
$ ./test5
The date and time are: Mon Jan 31 20:23:25 EDT 2011

Note: In bash you can also use the alternative $(…) syntax in place of backtick (`),which has the advantage of being re-entrant.

Example : $ echo ” Today’s date & time is :” $(date)
Today’s date & time is : Sun Jul 27 16:26:56 IST 2014

Thursday 27 September 2018

25 useful find command examples for Linux beginners

Find command is one of the most useful & important command used in Linux. Its available & installed by default on almost all the versions of Linux. Everything on Linux is in the form of files, & we should be able to locate a file when required.

Find Command, Linux Command, Linux Tutorial and Material, LPI Certification

With the use of find command, we can look for the files that are needed based on a number of search criteria, we can use single or combine a number of criteria & then we can perform actions on the result obtained. In this tutorial, we are going to discuss find command with the help of some examples,

1) Lists all the files in current directory & its sub-directories


To list all the files in current directory & the sub-directories, we can use

$ find

Alternatively, we can also use ‘find . ’ which will also provide the same result as above.

2) Find all the files or directories of your present working directory


To look only for directories, we can use

$ find . -type d

To search all the files only & not directories, use

$ find . -type f

3) Lists all the files of a specific directory


To find all the files in a particular directory, we can use

$ find /root

This command will look for all the files in /root directory.

4) Find a file with name in a directory


To look for a file by its name in a particular directory, command is

$ find /root -name "lpicentral.txt"

This will look for lpicentral.txt file in /root folder. We can also look for all the files with .txt extension,

$ find /root -name "*.txt"

5) Find a file in multiple directories


To find a file by its name in multiple directories, we can use

$ find /root /etc -name "lpicentral.txt"

With this command, we can look for lpicentral.txt file in /root & /etc directories.

6) Find a file with name ignoring case


To look for file with its name irrespective of the case i.e. whether its upper case or lower case, we can use ‘-iname‘ option in find command

$ find /root -iname "lpicentral.txt"

The result of the command will provide all the files that are named lpicentral.txt, whether its in lower case or upper case or in mixed cases.

7) Find all file types other than the mentioned type


Let’s suppose we want to find all the files that are not the mentioned type, to achieve this we can use,

$ find /root -not -name "*.txt"

8) Find files with multiple conditions


We can also combine more than one condition to search the files , Let’s suppose we want to search files of ‘.txt’ and ‘.html’ extensions

$ find . -regex ".*\.\(txt\|html\)$"

9) Find files with using OR condition


We can also combine multiple search criteria & then look for the files based on the fulfillment of any of the one condition using OR operator,

$ find -name "*.txt" -o -name "lpicentral*"

10) Find all the files based on their permissions


To look for files based on the permissions, use -perm option in find command

$ find /root -type f -perm 0777

11) Find all the hidden files


To search for all the hidden files in a directory, command is

$ find  ~ -type f name ".*"

12) Find all the files with SGID


To locate all the files with SGID bits, we can use

$ find . -perm /g=s

13) Find all the files with SUID


To locate all the files with SUID bits, we will use

$ find . -perm /u=s

14) Find all executable files


To only look for the files that are executable, command is

$ find . -perm /a=x

15) Find all the read-only files


We can also look for only read-only files using find command,

$ find /root -perm /u=r

16) Find all the files owned by a user


To locate all the file that are owned by a particular user, for example lpicentral, we will use the following  command,

$ find . -user lpicentral

17) Find all the files owned by a group


To locate all the files that are owned by a particular group, use

$ find . -group apache

18) Find files of particular size


If we want want to search a file for which we know the exact size, then we can use ‘-size‘ option with find command to locate the file

$ find / -size -2M

19) Find all the files of size range


If we are looking for a file for which we don’t know the actual size but know a range of size or just want to locate all the files within a size range, then we can also locate the file using that criteria

$ find / -size +2M -size -5M

We can also use find command to locate all the files whose size is greater than 50 MB

$ find / -size +50M

20) Find files that are modified N days ago


For example, we want to locate all the files that have been modified 8 days ago. We can accomplish that using ‘-mtime‘ option in find command

$ find / -mtime 8

21) Find files that have been accessed N days ago


Similarly like above example, we can also locate files that have been accessed 8 days ago using ‘-atime’,

$ find / -atime 8

22) Find all the empty files or directories


To locate all the empty files on the system, we will use beneath command

$ find / -type f -empty

Similarly, to locate all the empty directories

$ find ~/ -type d -empty

23) Find largest and smallest files


To list largest or smallest file, we will combine ‘sort‘ command with find command & if we further want to list top three of those largest files, we will combine ‘head‘ command.

To list top three files in the current directory, command is

$ find . -type f -exec ls -s {} \; | sort -n -r | head -3

We can similarly find the smallest files in the current directory,

$ find . -type f -exec ls -s {} \; | sort -n | head -3

24) Find all the files with specific permissions & change them to 644 (or other permissions)


With find command, we can also achieve some advanced functionalities. For example, we can list all the files that have permission 644 and then change those permissions to 777. To do this, run

$ find / -type f -perm 644 -print -exec chmod 777 {} \;

25) Find all the files matching a criteria & delete them


We might be required to locate & delete files matching a criteria. To do this with find command, run

$ find / -type f -name 'lpicentral.*' -exec rm -f {} \;

These were some simple examples demonstrating the functionality of find command & it can be used to perform tedious, repetitive search/locate task more easy.

Sunday 23 September 2018

Linux vs. Unix

Linux Certification, Unix Certification, Linux vs Unix
Linux is an open source, free to use operating system widely used for computer hardware and software, game development, tablet PCS, mainframes etc. Unix is an operating system commonly used in internet servers, workstations and PCs by Solaris, Intel, HP etc.

Comparison Chart


Linux  Unix 
Cost  Linux can be freely distributed, downloaded freely, distributed through magazines, Books etc. There are priced versions for Linux also, but they are normally cheaper than Windows. Different flavors of Unix have different cost structures according to vendors
Development and Distribution  Linux is developed by Open Source development i.e. through sharing and collaboration of code and features through forums etc and it is distributed by various vendors.  Unix systems are divided into various other flavors, mostly developed by AT&T as well as various commercial vendors and non-profit organizations. 
Manufacturer  Linux kernel is developed by the community. Linus Torvalds oversees things.  Three bigest distributions are Solaris (Oracle), AIX (IBM) & HP-UX Hewlett Packard. And Apple Makes OSX, an unix based os. 
User  Everyone. From home users to developers and computer enthusiasts alike.  Unix operating systems were developed mainly for mainframes, servers and workstations except OSX, Which is designed for everyone. The Unix environment and the client-server program model were essential elements in the development of the Internet 
Usage  Linux can be installed on a wide variety of computer hardware, ranging from mobile phones, tablet computers and video game consoles, to mainframes and supercomputers.  The UNIX operating system is used in internet servers, workstations & PCs. Backbone of the majority of finance infastructure and many 24x365 high availability solutions. 
File system support   Ext2, Ext3, Ext4, Jfs, ReiserFS, Xfs, Btrfs, FAT, FAT32, NTFS  jfs, gpfs, hfs, hfs+, ufs, xfs, zfs format 
Text mode interface  BASH (Bourne Again SHell) is the Linux default shell. It can support multiple command interpreters.  Originally the Bourne Shell. Now it's compatible with many others including BASH, Korn & C. 
What is it?  Linux is an example of Open Source software development and Free Operating System (OS).  Unix is an operating system that is very popular in universities, companies, big enterprises etc. 
GUI  Linux typically provides two GUIs, KDE and Gnome. But there are millions of alternatives such as LXDE, Xfce, Unity, Mate, twm, ect.  Initially Unix was a command based OS, but later a GUI was created called Common Desktop Environment. Most distributions now ship with Gnome. 
Price  Free but support is available for a price.  Some free for development use (Solaris) but support is available for a price. 
Security  Linux has had about 60-100 viruses listed till date. None of them actively spreading nowadays.  A rough estimate of UNIX viruses is between 85 -120 viruses reported till date. 
Threat detection and solution  In case of Linux, threat detection and solution is very fast, as Linux is mainly community driven and whenever any Linux user posts any kind of threat, several developers start working on it from different parts of the world  Because of the proprietary nature of the original Unix, users have to wait for a while, to get the proper bug fixing patch. But these are not as common. 
Processors  Dozens of different kinds. x86/x64, Sparc, Power, Itanium, PA-RISC, PowerPC and many others. 
Examples  Ubuntu, Fedora, Red Hat, Debian, Archlinux, Android etc.  OS X, Solaris, All Linux 
Architectures Originally developed for Intel's x86 hardware, ports available for over two dozen CPU types including ARM  is available on PA-RISC and Itanium machines. Solaris also available for x86/x64 based systems.OSX is PowerPC(10.0-10.5)/x86(10.4)/x64(10.5-10.8) 
Inception Inspired by MINIX (a Unix-like system) and eventually after adding many features of GUI, Drivers etc, Linus Torvalds developed the framework of the OS that became LINUX in 1992. The LINUX kernel was released on 17th September, 1991 In 1969, it was developed by a group of AT&T employees at Bell Labs and Dennis Ritchie. It was written in “C” language and was designed to be a portable, multi-tasking and multi-user system in a time-sharing configuration.

Saturday 22 September 2018

How to define and use functions in Linux Shell Script

Linux Shell Script, LPI Certification, LPI Guides, LPI Tutorial and Material

In this article we’ll discuss more about functions and recipes. For demonstration purpose I’ll be using Bourne Again SHell(Bash) on Ubuntu machine.

Calling function


In Shell calling function is exactly same as calling any other command. For instance, if your function name is my_func then it can be execute as follows:

$ my_func

If any function accepts arguments then those can be provided from command line as follows:

$ my_func arg1 arg2 arg3

Defining function


We can use below syntax to define function:

 function function_name {
            Body of function
 }

Body of function can contain any valid command, loop constrain, other function or script. Now let us create simple function which displays message on screen.

 function print_msg {
       echo "Hello, World"
 }

Now let us execute this function:

 $ print_msg
 Hello, World

As expected, this function displays message on screen.

In above example we have created function directly on terminal. We can store this function in file as well. Below example demonstrates this.

 #! /bin/bash
 function print_msg {
       echo "Hello, World"
 }
 print_msg

We have defined this function inside function.sh file. Now let us execute this script:

 $ chmod +x function.sh
 $ ./function.sh
 Hello, World

If you observe, above output is exactly identical to previous one.

More about functions


In previous section we have defined very basic function. However during software development we need more advanced functions which can accept various parameters and return values. In this section we’ll discuss such functions.

Passing arguments to function

We can provide arguments to function same as other commands. We can access these arguments from function using dollar($) symbol. For instance, $1 represents first argument, $2 represents second argument and so on.

Let us modify above function to accept message as an argument. Our modified function will look like this:

 function print_msg {
       echo "Hello $1"
 }

In above function we are accessing first argument using $1. Let us execute this function:

 $ print_msg "lpicentral"

When you execute this function, it will generate following output:

 Hello LPICentral

Returning value from function

Like other programming languages, Bash provides return statement using that we can return value to the caller. Let us understand this with example:

Linux Shell Script, LPI Certification, LPI Guides, LPI Tutorial and Material

function func_return_value {
      return 10
 }

Above function returns value 10 to its caller. Let us execute this function:

 $ func_return_value
 $ echo "Value returned by function is: $?"

When you execute above function, it will generate following output:

 Value returned by function is: 10

NOTE: In bash we have to use $? to capture return value of function

Function recipes


So far we got fair idea about bash functions. Now let us create some useful bash functions which can be used to make our lives easier.

Logger

Let us create logger function which will print date and time along with log message.

 function log_msg {
        echo "[`date '+ %F %T'` ]: $@"
 }

Let us execute this function:

 $ log_msg "This is sample log message"
When you execute this function, it will generate following output:

 [ 2018-08-16 19:56:34 ]: This is sample log message

Display system information

Let us create a function to display information about GNU/Linux system

 function system_info {
       echo "### OS information ###"
       lsb_release -a

       echo
       echo "### Processor information ###"
       processor=`grep -wc "processor" /proc/cpuinfo`
       model=`grep -w "model name" /proc/cpuinfo  | awk -F: '{print $2}'`
       echo "Processor = $processor"
       echo "Model     = $model"

       echo
       echo "### Memory information ###"
       total=`grep -w "MemTotal" /proc/meminfo | awk '{print $2}'`
       free=`grep -w "MemFree" /proc/meminfo | awk '{print $2}'`
       echo "Total memory: $total kB"
       echo "Free memory : $free kB"
 }

When you execute above function it will generate following output:

### OS information ###
No LSB modules are available.
Distributor ID:           Ubuntu
Description:   Ubuntu 18.04.1 LTS
Release:         18.04
Codename:    bionic

### Processor information ###
Processor = 1
Model     =  Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz

### Memory information ###
Total memory: 4015648 kB
Free memory : 2915428 kB

Find file or directory from current directory

Below function searches file or directory from current directory:

 function search {
      find . -name $1
 }

Let us search directory namely dir4 using below command:

$ search dir4

When you execute above command, it will generate following output:

./dir1/dir2/dir3/dir4

Digital clock

Below function creates a simple digital clock on terminal

 function digital_clock {
            clear
            while [ 1 ]
            do
                  date +'%T'
                  sleep 1
                  clear
            done
 }

Creating library


Library is a collection of functions. To create library – define functions in a file and import that file in current environment.

Let us suppose we have defined all functions in utils.sh file then use below command to import functions in current environment:

$ source utils.sh

Hereafter you can execute any function from library just like any other bash command.

Thursday 20 September 2018

Essential Linux/Unix Commands

Unix is the now one of the most commonly used Operating System used for various purposes such as Personal use, Servers, Smartphones and many more.

LPI Linux Essentials, Linux, Linux Command, UNIX, Unix Command

◈ You’ll be surprised to know that the most popular programming language C came into existence to write the Unix Operating System.

◈ Linux is Unix-Like operating system.

◈ The most important part of the Linux is Linux Kernel which was first released in early 90’s by Linus Torvalds.There are several Linux distros available (most are open-source and free to download and use) such as Ubuntu, Debian, Fedora, Kali, Mint, Gentoo, Arch and much more.

◈ Now coming to the Basic and most usable commands of Linux/Unix part. (Please note that all the linux/unix commands are run in the terminal of a linux system.Terminal is like command prompt as that of in Windows OS)

◈ Linux/Unix commands are case-sensitive i.e Hello is different from hello.

Basic unix commands:


1. who : The ‘$ who’ command displays all the users who have logged into the system currently.As shown above on my system i am the only user currently logged in.The thing tty2 is terminal line the user is using and the next line gives the current date and time

$ who
Output: harssh tty2 2017-07-18 09:32 (:0)

2. pwd : The ‘$pwd’ command stands for ‘print working directory’ and as the name says,it displays the directory in which we are currently (directory is same as folder for Windows OS users).
In the output we are harssh directory(folder for Windows OS that are moving to Linux),which is present inside the home directory

 $ pwd
Output: /home/harssh

3. mkdir : The ‘$ mkdir’ stands for ‘make directory’ and it creates a new directory.We have used ‘$ cd’ (which is discussed below) to get into the newly created directory and again on giving ‘$ pwd’ command,we are displayed with the new ‘newfolder’ directory.

$ mkdir newfolder
$ cd newfolder
$ pwd
Output: /home/harssh/newfolder

4. rmdir : The ‘$ rmdir’ command deletes any directory we want to delete and you can remember it by its names ‘rmdir’ which stands for ‘remove directory’.

$ rm dir newfolder

5. cd : The ‘$ cd’ command stands for ‘change directory’ and it changes your current directory to the ‘newfolder’ directory.You can understand this a double clicking a folder and then you do some stuff in that folder.

$ cd newfolder (assuming that there is a directory named 'newfolder' on your system)

6. ls : The ‘ls’ command simply displays the contents of a directory.

$ ls
Output: Desktop Documents Downloads Music Pictures Public Scratch Templates Videos

7. touch : The ‘$ touch’ command creates a file(not directory) and you can simple add an extension such as .txt after it to make it a Text File.

$ touch example
$ ls
Output: Desktop Documents Downloads Music Pictures Public Scratch Templates Videos example

Note: It is important to note that according to the Unix File structure,Unix treats all the stuff it has as a ‘file’, even the directories(folders) are also treated as a file.You will get to know more about this as you will further use Linux/Unix based OS

8. cp : This ‘$ cp ‘ command stands for ‘copy’ and it simply copy/paste the file wherever you want to.In the above example we are copying a file ‘file.txt’ from the directory harssh to a new directory new.

$ cp /home/harssh/file.txt /home/harssh/new/

9. mv : The ‘$ mv’ command stands for ‘move’ and it simply move a file from a directory to anothe directory.In the above example a file named ‘file.txt’ is being moved into a new directory ‘new’

$ mv /home/harssh/file.txt /home/harssh/new

10. rm : The ‘$ rm ‘ command for remove and the ‘-r’ simply forcibly deletes a file without prompting the user.Try ‘$ rm filename.txt’ at your terminal

$ rm -r file.txt

11. chmod : The ‘$ chmod’ command stands for change mode command.As there are many modes in Unix that can be used to manipulate files in the Unix environment.Basically there are 3 modes that we can use with the ‘chmod’ command
1. +w (stands for write and it changes file permissions to write)
2. +r (stands for read and it changes file permissions to read)
3. +x (generally it is used to make a file executable)

$ chmod +w file.txt
$ chmod +r file.txt
$ chmod +x file.txt

12. cal : The ‘$ cal’ means calendar and it simply display calendar on to your screen.

$ cal
Output : July 2017
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

13. file : The ‘$ file’ command displays the type of file.As i mentioned earlier linux treats everything as file so on executing the command file on a directory(Downloads) it displays directory as the output

$ ls
Output: Desktop Documents Downloads Music Pictures Public Scratch Templates Videos
$ file Downloads
Output: Downloads: directory

14. sort : As the name suggests the ‘$ sort’ sorts the contents of the file according to the ASCII rules.

$ sort file

15. grep : grep is an acronym for ‘globally search a regular expression and print it’.The ‘$ grep’ command searches the specified input fully(globally) for a match with the supplied pattern and displays it.

In the example, this would search for the word ‘picture’ in the file newsfile and if found,the lines containing it would be displayed on the screen.

$ grep picture newsfile

16. man : The ‘$ man’ command stands for ‘manual’ and it can display the in-built manual for most of the commands that we ever need.In the above example we can read about the ‘$ pwd’ command.

$ man pwd

17. lpr : The ‘$ lpr’ command send a file to the printer for printing.

$ lpr new.txt

18. passwd : The ‘$ passwd’ command simply changes the password of the user.In above case ‘harssh’ is the user.

$ passwd
Output: Changing password for harssh.
(current) UNIX password:

19. clear : The ‘$ clear’ command is used to clean up the terminal so that you can type with more accuracy

$ clear

At last, I want to say that these are most basic and most essential commands that are used the Linux operating system. You will need them even if you get advance the Unix.If you want to master them just keep on practicing them.

Also it is not possible to cover all the Unix commands because they are so much in number. You can find more, just google it and you will find most of them. Also if you want to master Unix operating system, Learn Unix Shell Scripting/Bash Scripting. Trust me there are many awesome tutorials on the internet for them.

Compile your C/C++ program in the Unix terminal


First reach the directory where your .c or .cpp file is present (assume its name is new.c or new.cpp). Please note that in order to compile C you will need gcc compiler and in order to compile C++ you will need g++ . I will tell you below how to install them.

For C:

$ gcc new.c -o new
$ ./new

For C++:

$ g++ new.cpp -o new
$ ./new

In this way you can compile you programs of C and C++. You can even compile many more that i will cover in my coming articles.

Getting gcc, g++

For deb based Linux such as Ubuntu,Debian,Kali etc:

$ sudo apt-get install gcc
$ sudo apt-get install g++

For rpm based Linux such as Fedora,Oracle Linux etc:

$ dnf install gcc
$ dnf install g++
 OR 
$ yum install gcc
$ yum install g++

Tuesday 18 September 2018

10 Useful Linux Networking Commands

Networking Commands, Linux Certification, Linux Tutorial and Material, Linux Command

In this article, I will show you useful Linux networking commands, which will help you in troubleshooting.

1. Ifconfig


ifconfig utility is used to configure network interface parameters.

Mostly we use this command to check the IP address assigned to the system.

[root@localhost ~]# ifconfig -a
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
       ether 00:0c:29:c5:a5:61 txqueuelen 1000 (Ethernet)
       RX packets 0 bytes 0 (0.0 B)
       RX errors 0 dropped 0 overruns 0 frame 0
       TX packets 0 bytes 0 (0.0 B)
       TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
       inet 127.0.0.1 netmask 255.0.0.0
       inet6 ::1 prefixlen 128 scopeid 0x10<host>
       loop txqueuelen 0 (Local Loopback)
       RX packets 2 bytes 140 (140.0 B)
       RX errors 0 dropped 0 overruns 0 frame 0
       TX packets 2 bytes 140 (140.0 B)
       TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]#

2. traceroute


traceroute print the route packets take to network host.

Destination host or IP is mandatory parameter to use this utility

[root@localhost ~]# traceroute lpicentral.blogspot.com
traceroute to lpicentral.blogspot.com (162.159.243.243), 30 hops max, 60 byte packets
1 172.16.179.2 (172.16.179.2) 0.154 ms 0.074 ms 0.074 ms
2 * * *
3 * * *

3. dig


dig (Domain Information Groper) is a flexible tool for interrogating DNS name servers.

It performs DNS lookups and displays the answers that are returned from the name servers.

[root@localhost ~]# dig lpicentral.blogspot.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> lpicentral.blogspot.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18699
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; MBZ: 0005 , udp: 4000
;; QUESTION SECTION:
;lpicentral.blogspot.com.                                   IN        A
;; ANSWER SECTION:
lpicentral.blogspot.com.                        5          IN        A          162.159.244.243
lpicentral.blogspot.com.                        5          IN        A          162.159.243.243
;; Query time: 6 msec
;; SERVER: 172.16.179.2#53(172.16.179.2)
;; WHEN: Sun May 01 23:28:19 PDT 2016
;; MSG SIZE rcvd: 74
[root@localhost ~]#

4. telnet


telnet connect destination host:port via a telnet protocol if connection establishes means connectivity between two hosts is working fine.

[root@localhost ~]# telnet lpicentral.blogspot.com 443
Trying 162.159.244.243...
Connected to lpicentral.blogspot.com.
Escape character is '^]'.

5. nslookup


nslookup is a program to query Internet domain name servers.

[root@localhost ~]# nslookup lpicentral.blogspot.com
Server:                        172.16.179.2
Address:         172.16.179.2#53
Non-authoritative answer:
Name: lpicentral.blogspot.com
Address: 162.159.243.243
Name: lpicentral.blogspot.com
Address: 162.159.244.243
[root@localhost ~]#

6. netstat


Netstat command allows you a simple way to review each of your network connections and open sockets.

netstat with head output is very helpful while performing web server troubleshooting.

[root@localhost ~]# netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address        State 
tcp       0     0 172.16.179.135:58856   mirror.comp.nus.ed:http TIME_WAIT
tcp       0     0 172.16.179.135:34444   riksun.riken.go.jp:http ESTABLISHED
tcp       0     0 172.16.179.135:37948   mirrors.isu.net.sa:http TIME_WAIT
tcp       0     0 172.16.179.135:53128   ossm.utm.my:http       TIME_WAIT
tcp       0     0 172.16.179.135:59723   103.237.168.15:http     TIME_WAIT
tcp       0     0 172.16.179.135:60244   no-ptr.as20860.net:http TIME_WAIT

7. scp


scp allows you to secure copy files to and from another host in the network.

Ex:

scp $filename user@targethost:/$path

8. w


w prints a summary of the current activity on the system, including what each user is doing, and their processes.

Also list the logged in users and system load average for the past 1, 5, and 15 minutes.

[root@localhost ~]# w
23:32:48 up 2:52, 2 users, load average: 0.51, 0.36, 0.19
USER     TTY       LOGIN@   IDLE   JCPU   PCPU WHAT
chandan :0       20:41   ?xdm?   7:07 0.13s gdm-session-worker [pam/gdm-password]
chandan pts/0     20:42   0.00s 0.23s 3.42s /usr/libexec/gnome-terminal-server
[root@localhost ~]#

9. nmap


nmap is a one of the powerful commands, which checks the opened port on the server.

Usage example:

nmap $server_name

10. Enable/Disable Network Interface


You can enable or disable the network interface by using ifup/ifdown commands with ethernet interface parameter.

To enable eth0

#ifup eth0

To disable eth0

#ifdown eth0

Sunday 16 September 2018

Top command usages and examples in Unix/Linux

Top command has an important role in Unix/Linux system/server administration side. The command “top” displays a dynamic view of process that are currently running under the system. Here I’m  explaining some of the useful usage of top command for my Admin friends.

Top command is simple in usage and very interesting also. The simple top command output is shown below.

1. top

Top Command, Unix Command, Linux Command, Linux Study Material

An important thing that we can observe is the dynamic view of Load Average from “top” command and also uptime, total users logged in to the system, cpu & free memory details etc..

Some useful switches 


2. “-d” switch with top command

d means delay time. The syntax for ‘d’ is “top -d ss.tt”(seconds.tenths).

For example top -d 05.00 that means the top command’s output screen have a dynamic change with 5 second time interval. You can speedup or slowdown the top display frequency by using this switch.

3. top command’s output field description.

PID : Process ID.
USER : The user name who runs the process.
PR : Priority
NI : Nice value
%CPU : CPU usage
TIME : CPU Time
%MEM : Memory usage (RES)
VIRT : Virtual Image (kb)
SWAP : Swapped size (kb)
RES : Resident size (kb)
S : Process Status
The status of the task which can be one of:
'D' = uninterruptible sleep
'R' = running
'S' = sleeping
'T' = traced or stopped
'Z' = zombie

4. Interactive commands for top

Several single-key commands are recognised while top is running. Some of the useful hotkeys are explained below:

4.1 space

Immediately updates the display.

4.2 h or ?

This will display the help page (q for quit).

4.3 k :

For kill a process.

Top Command, Unix Command, Linux Command, Linux Study Material

In the image change PROCESS ID with the pid of process which you want to kill.

4.4 i

Ignore idle and zombie processes. This is a toggle switch.

4.5 I (shift i)

Toggle between Solaris (CPU percentage divided by total number of CPUs) and Irix (CPU percentage calculated solely by amount of time) views. This is a toggle switch that affects only SMP systems.

4.6 n or #

Change the number of processes to show. You will be prompted to enter the number. This overrides automatic determination of the number of processes to show, which is based on window size measurement. If 0 is specified, then top will show as many processes as will fit on the screen; this is the default.

4.7 q

Quit.

4.8 M (shift m)

sort tasks by resident memory usage.

Top Command, Unix Command, Linux Command, Linux Study Material

4.9 T (shift t)

sort tasks by time / cumulative time.

Top Command, Unix Command, Linux Command, Linux Study Material

4.10 c or P(shift p)

sort tasks by CPU usage (default).

Top Command, Unix Command, Linux Command, Linux Study Material

4.11 A (shift a)

sort tasks by age (newest first).

Top Command, Unix Command, Linux Command, Linux Study Material

4.12 N (shift n)

sort tasks by pid (numerically).

Top Command, Unix Command, Linux Command, Linux Study Material

These are some interesting usage of top command under UNIX/LINUX.

Thursday 13 September 2018

Linux Commands to manage Local Accounts – useradd, usermod, chage & passwd

User administration is one of the important task of Linux system administrator. Local accounts or users in Linux like operating system is managed by useradd, usermod, userdel, chage and passwd commands.

◈ useradd command is used to create new accounts in Linux
◈ usermod command used to modify the existing accounts in linux
◈ userdel command is used to delete local account in linux
◈ passwd command used assign password to local accounts or users.
◈ chage comamnd is used to view & modify users password expiry information

Syntax of ‘useradd’ command


# useradd <options> <username_or_login>

Options used in useradd command :

Linux Command, LPI Guides, LPI Certification, LPI Learning, LPI Tutorial and Materials

Syntax of usermod command :


# usermod <options> <username_or_login>

Options used in usermod command.

Linux Command, LPI Guides, LPI Certification, LPI Learning, LPI Tutorial and Materials

Syntax of userdel command:


# userdel <options> <username_or_login>

Options used in userdel command :

Linux Command, LPI Guides, LPI Certification, LPI Learning, LPI Tutorial and Materials

Syntax of chage:


# chage <options> <username_or_login>

Options used in chage command :

Linux Command, LPI Guides, LPI Certification, LPI Learning, LPI Tutorial and Materials

Syntax of passwd Command:


# passwd <username_or_login>

In this article we will discuss different examples of user administration on CentOS 7 & RHEL 7.

Example:1 Create a local account & assign password.


User the below syntax to create and assign to the username.

# useradd <username> ; echo -e "<newpassword>\n<newpassword>" | passwd username

Let’s create a username ‘harry’ and assign password.

[root@lpicentral ~]# useradd harry ; echo -e "Roxicant@123#\nRoxicant@123#" | passwd harry
Changing password for user harry.
New password: Retype new password: passwd: all authentication tokens updated successfully.
[root@lpicentral ~]#

Note : When a user is created in Linux followings are updated:

◈ A home directory is created under ‘/home/<username>’
◈ User info is updated in ‘/etc/passwd’ file
◈ Group Information is stored in ‘/etc/group’
◈ password info is updated in ‘/etc/shadow’ file.
◈ File for user’s email is created under ‘/var/spool/mail/<username>’

Example:2 Create a user with customize settings


Let’s create a user with following options :

UID = 2000
GID = 5000
Comments = ‘Admin Account of SAP’
Home Directory = /opt/sap
Shell = /bin/ksh
Username = john
password = xxxxxx

[root@lpicentral ~]# useradd -u 2000 -g 5000 -c "Admin Account of SAP" -d /opt/sap -s /bin/ksh john
[root@lpicentral ~]#
[root@lpicentral ~]# echo -e "Sapcant@123#\nSapcant@123#" | passwd john
Changing password for user john.
New password: Retype new password: passwd: all authentication tokens updated successfully.
[root@lpicentral ~]#

Verify the above settings from /etc/passwd file.

[root@lpicentral ~]# grep john /etc/passwd
john:x:2000:5000:Admin Account of SAP:/opt/sap:/bin/ksh
[root@lpicentral ~]#

Example:3 Modify the Existing User


usermod command is used to modify the existing local accounts in Linux.

Let’s make the existing user “harry” part of Secondary group “sap” and change its home directory from ‘/home/harry’ to ‘/opt/sap’ and login shell from ‘/bin/bash’ to ‘/bin/sh’

[root@lpicentral ~]# usermod -G sap -d /opt/sap -s /bin/sh harry
[root@lpicentral ~]#
[root@lpicentral ~]# grep harry /etc/passwd
harry:x:1000:1000::/opt/sap:/bin/sh
[root@lpicentral ~]#

Example:4 Create a user and force to change the password at first login.


Let’s create a user ‘mark’ with secondary group ‘sap’, home directory as ‘/opt/sap’ and force him to change his password at the first login.

We can force users to change its password at first login by using command ‘chage -d 0 <username>‘.

[root@lpicentral ~]# useradd -c "sap user" -G sap -d /opt/data mark
[root@lpicentral ~]# echo -e "Sapdata@123#\nSapdata@123#" | passwd mark ; chage -d 0 mark
Changing password for user mark.
New password: Retype new password: passwd: all authentication tokens updated successfully.
[root@lpicentral ~]#

Now try to login as mark and see whether user is getting a prompt to change password or not.

Linux Command, LPI Guides, LPI Certification, LPI Learning, LPI Tutorial and Materials

Note: Use ‘chage -l <username>‘ command to view the user’s password expiry info.

Example:5 Delete a User along with its home directory


userdel command is used to delete local accounts or users in Linux. Let’s delete a user lpicentral along with its related its files (home directory).

[root@lpicentral ~]# userdel -r lpicentral
[root@lpicentral ~]# grep lpicentral/etc/passwd
[root@lpicentral ~]#

Tuesday 11 September 2018

Linux/UNIX xargs command examples

xargs is a command in UNIX like System that reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored.

xargs Command, Linux Command, Unix Command, LPI Study Materials

xargs command is very handy when combined with other commands. By default it expects input from STDIN.xargs is basically used to enhance the output of the initial command and utilize the output for performing numerous operations.

In this post we will discuss 10 practical examples of xargs command :

Example:1 Basic Usage of xargs


Type xargs , it will expect an input from us , start typing with enter for next line and then do a ctrl+d to see the output as below.

lpicentral@mail:~$ xargs
hello
john
this is me ( ctrl+d)
hello john this is me
lpicentral@mail:~$home/Downloads#

Example:2 Use of Delimiters


Here we specify a delimiter using the option -d , with \n as the delimiter. It echoes the string back to the screen when we press the ctrl+d

lpicentral@mail:~$ xargs -d\n
Hi
Welcome here
Now press Ctrl+D

lpicentral@mail:~$ xargs -d\n
Hi
Welcome hereHi
Welcome here
Now press Ctrl+D
lpicentral@mail:~$

Example:3 Limiting output per line


We can limit the output as per requirement using -n option in xargs command, for example to display only 2 items per line ,

lpicentral@mail:~$ echo a1 b2 c3 d4 e45
a1 b2 c3 d4 e5

lpicentral@mail:~$ echo a1 b2 c3 d4 e5 | xargs -n 2
a1 b2
c3 d4
e5
lpicentral@mail:~$

Example:4 Enable User Prompt before execution


Using the option -p in xargs command , user will be prompted before the execution with y (means yes) and n (means no) options.

lpicentral@mail:~$ echo a1 b2 c3 d4 e5 | xargs -p -n 2
/bin/echo a1 b2 ?…y
/bin/echo c3 d4 ?…a1 b2
y
/bin/echo e5 ?…c3 d4
n

lpicentral@mail:~$ echo a1 b2 c3 d4 e5 | xargs -p -n 2
/bin/echo a1 b2 ?…y
/bin/echo c3 d4 ?…a1 b2
y
/bin/echo e5 ?…c3 d4
y
e5
lpicentral@mail:~$

Example:5 Deleting files using find and xargs


lpicentral@mail:~$ find /tmp -name ‘abc.txt’ | xargs rm

Example:6 Using grep to query files


we can use the grep command with xargs to filter the particular search from the result of find command. An example is shown below :

lpicentral@mail:~$ find . -name “stamp” | xargs grep “country”
country_name
lpicentral@mail:~$

Example:7 Handle space in file names


xargs can also handle spaces in files by using print0 and xargs -0 arguments to find command.

lpicentral@mail:~$ find /tmp -name “*.txt” -print0 | xargs -0 ls
/tmp/abcd asd.txt /tmp/asdasd asdasd.txt /tmp/cdef.txt

lpicentral@mail:~$ find /tmp -name “*.txt” -print0 | xargs -0 rm
lpicentral@mail:~$

Example:8 Use xargs with cut command


First create a cars.txt with below conetnts :

lpicentral@mail:~$ cat cars.txt
Hundai,Santro
Honda,Mobilio
Maruti,Ertiga
Skoda,Fabia

To display data in first column as shown below.

lpicentral@mail:~$ cut -d, -f1 cars.txt | sort | xargs
Honda Hundai Maruti Skoda
lpicentral@mail:~$

Example:9 Count the number of lines in each file.


lpicentral@mail:~$ ls -1 *.txt | xargs wc -l
4 cars.txt
13 trucks.txt
17 total
lpicentral@mail:~$

Example:10 Move files to a different location


lpicentral@mail:~$ pwd
/home/lpicentral
lpicentral@mail:~$ ls -l *.sh
-rw-rw-r– 1 lpicentral lpicentral 0 Sep 15 22:53 abcde.sh
-rw-rw-r– 1 lpicentral lpicentral 0 Sep 15 22:53 abcd.sh
-rw-rw-r– 1 lpicentral lpicentral 0 Sep 15 22:53 fg.sh

lpicentral@mail:~$ sudo find . -name “*.sh” -print0 | xargs -0 -I {} mv {} backup/
lpicentral@mail:~$ ls -ltr backup/
total 0
-rw-rw-r– 1 lpicentral lpicentral 0 Sep 15 22:53 abcd.sh
-rw-rw-r– 1 lpicentral lpicentral 0 Sep 15 22:53 abcde.sh
-rw-rw-r– 1 lpicentral lpicentral 0 Sep 15 22:53 fg.sh
lpicentral@mail:~$

Sunday 9 September 2018

Linux/UNIX wget command with practical examples

wget command, Linux/UNIX, Linux Tutorial and Material, Linux Study Materials

wget is a Linux/UNIX command line file downloader.Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.Wget is non-interactive, meaning that it can work in the background, while the user is not logged on.

In this post we will discuss different examples of wget command.

Example:1 Download Single File


# wget http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso

This command will download the CentOS 7 ISO file in the user’s current working directtory.

Example:2 Resume Partial Downloaded File


There are some scenarios where we start downloading a large file but in the middle Internet got disconnected , so using the option ‘-c’ in wget command we can resume our download from where it got disconnected.

# wget -c http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso

wget command, Linux/UNIX, Linux Tutorial and Material, Linux Study Materials

Example:3 Download Files in the background


We can download the file in the background using the option ‘-b’ in wget command.

lpicentral@localhost:~$ wget -b http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/
CentOS-7.0-1406-x86_64-DVD.iso
Continuing in background, pid 4505.
Output will be written to ‘wget-log’.

As we can see above that downloading progress is capture in ‘wget-log’ file in user’s current directory.

lpicentral@localhost:~$ tail -f wget-log
2300K ………. ………. ………. ………. ………. 0% 48.1K 18h5m
2350K ………. ………. ………. ………. ………. 0% 53.7K 18h9m
2400K ………. ………. ………. ………. ………. 0% 52.1K 18h13m
2450K ………. ………. ………. ………. ………. 0% 58.3K 18h14m
2500K ………. ………. ………. ………. ………. 0% 63.6K 18h14m
2550K ………. ………. ………. ………. ………. 0% 63.4K 18h13m
2600K ………. ………. ………. ………. ………. 0% 72.8K 18h10m
2650K ………. ………. ………. ………. ………. 0% 59.8K 18h11m
2700K ………. ………. ………. ………. ………. 0% 52.8K 18h14m
2750K ………. ………. ………. ………. ………. 0% 58.4K 18h15m
2800K ………. ………. ………. ………. ………. 0% 58.2K 18h16m
2850K ………. ………. ………. ………. ………. 0% 52.2K 18h20m

Example:4 Limiting Download Speed .


By default wget command try to use full bandwidth , but there may be case that you are using shared internet , so if you try to download huge file using wget , this may slow down Internet of other users. This situation can be avoided if you limit the download speed using ‘–limit-rate‘ option.

#wget --limit-rate=100k http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso

In the above example,the download speed is limited to 100k.

Example:5 Download Multiple Files using ‘-i’ option


If you want to download multiple files using wget command , then first create a text file and add all URLs in the text file.

# cat download-list.txt
url1
url2
url3
url4

Now issue issue below Command :

# wget -i download-list.txt

Example:6 Increase Retry Attempts.


We can increase the retry attempts using ‘–tries‘ option in wget. By default wget command retries 20 times to make the download successful.

This option becomes very useful when you have internet connection problem and you are downloading a large file , then there is a chance of failures in the download.

# wget --tries=75 http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso

Example:7 Redirect wget Logs to a log File using -o


We can redirect the wget command logs to a log file using ‘-o‘ option.

#wget -o download.log http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso

Download.log file will be created in the user’s current directory.

Example:8 Download Full website for local viewing.


# wget --mirror -p --convert-links -P ./<Local-Folder> website-url

Whereas

◈ –mirror : turn on options suitable for mirroring.
◈ -p : download all files that are necessary to properly display a given HTML page.
◈ –convert-links : after the download, convert the links in document for local viewing.
◈ -P ./Local-Folder : save all the files and directories to the specified directory.


Example:9 Reject file types while downloading.


When you are planning to download full website , then we can force wget command not to download images using ‘–reject’ option .

# wget --reject=png Website-To-Be-Downloaded

Example:10 Setting Download Quota using wget -Q


We can force wget command to quit downloading when download size exceeds certain size using ‘-Q’ option

# wget -Q10m -i download-list.txt

Note that quota will never affect downloading a single file. So if you specify wget -Q10m ftp://wuarchive.wustl.edu/ls-lR.gz, all of the ls-lR.gz will be downloaded. The same goes even when several URLs are specified on the command-line. However, quota is respected when retrieving either recursively, or from an input file. Thus you may safely type ‘wget -Q10m -i download-list.txt’ download will be aborted when the quota is exceeded.

Example:11 Downloading file from password protected site.


# wget --ftp-user=<user-name> --ftp-password=<password> Download-URL

Another way to specify username and password is in the URL itself.

Either method reveals your password to anyone who bothers to run “ps”. To prevent the passwords from being seen, store them in .wgetrc or .netrc, and make sure to protect those files from other users with “chmod”. If the passwords are really important, do not leave them lying in those files either edit the files and delete them after Wget has started the download.

Thursday 6 September 2018

The Best Linux Certifications for 2018

In the IT world, Linux certifications are the determining factor on how far your career goes seeing that more than half of the world’s servers run on Linux Operating Systems and virtually every IT expert is expected to have certain certificates to bank a job placement.

Linux Certifications, Linux Command, LPIC-1 Certifications, LPIC-2 Certifications

Today, we bring you the list of the most important Linux certifications arranged into 2 groups, Administration and Engineering.

Linux Administration Certifications


1. RHCSA (Red Hat Certified System Administrator)


The Red Hat Certified System Administrator Certificate is the basis for all the other Red Hat certificates because it handles the basics such the Linux command line, simple configuration, system administration skills and a lot more.

2. LFCS (Linux Foundation Certified System Administrator)


The Linux Foundation Certified System Administrator is a certification earned by taking a test that is based on administrative performance.

The Linux Foundation is responsible for the performance-based tests and is the only one offering such exams. At the time of writing, the Operating Systems used for this test are Ubuntu 16 or CentOS 7.

3. SUSE Certified Administrator


SUSE Certified Administrator (SCA) in Enterprise Linux trains its holders on advanced-level administration tasks in the open-source environment, specifically OpenSUSE.

Here, coursework isn’t required as all you will need to do is pass the organized exams. Nevertheless, it is important that you go through all the course objectives and put their task solutions to long-term memory.

4. CompTIA Linux+


CompTIA Linux+ gives you the know-how of administrative tasks which exponentially increases your chances of getting a job.

It is also a one-time test and doesn’t have to be renewed – allowing you to work with virtually any distro out there like a pro. If you’re pursuing a career in Linux (or server administration don’t skip it.

5. GIAC Certified UNIX System Security Administrator


The number one reason you should obtain a GIAC Certified UNIX System Security Administrator Certificate is to educate yourself on security and inspection of Linux OS and UNIX systems. With it, you would have learned how to install, configure and monitor Linux and UNIX systems.

6. LPIC-1: Linux Administrator


LPIC-1 for Linux Administrators vaildates holders’ ability to carry out maintenance tasks via the command line as well as configure basic networking achitectures on Linux distros.

You must pass 2 exams before becoming LPIC-1 certified after covering topics ranging from GNU and Unix Commands, System Architecture, Linux filesystems, to Networking Fundamentals and Essential System Services.

It has no prerequisites and is valid for a period of 5 years.

Linux Engineer Certifications


7. RHCE (Red Hat Certified Engineer)


RHCE (Red Hat Certified Engineer) is also a necessary certificate to have under your belt because its senior-level great for grabbing the attention of potential employees.

In order to obtain the RHCE (Red Hat Certified Engineer), you must first obtain the Red Hat Certified System Administrator (RHCSA) credential. After which follows an approximately 4-hour test.

With it, you can apply to work as a Linux administrator, IT analyst, Senior Systems Engineer, and Senior UNIX Administrator, among other job titles. It isn’t easy but certainly worth it.

8. LFCE (Linux Foundation Certified Engineer)


A Linux Foundation Certified Engineer (LFCE) is the Engineering certificate equivalent of LFCS. Engineers with this certificate are tasked with the duties of designing and implementing various system architectures.

Users with this certificate are a step closer to their educational goals and can serve as Subject Matter Experts (SMEs) for the next generation of system administration professionals.

9. SUSE Certified Engineer (SCE)


SUSE Certified Engineer certification covers higher-level day-to-day engineering level tasks particular to the SUSE Linux Enterprise Server Environment.

Students are to perform real-time exams on at least 2 live systems via a remote online examination environment which is hosted by ExamsLocal.

10. Oracle Linux OCA & OCP

The Oracle Linux OCA & OCP is a certification that is built on the self-named Operating System. It also is about gaining all the necessary skills and knowledge in order to operate Oracle technology and products.

For you to earn this particular certification, you must have to pass two examinations which will test you on your knowledge of GNU/Linux OSes and of Oracle.

Bear in mind that there are 6 levels, namely:

◈ Oracle Certified Junior Associate (OJA)
◈ Oracle Certified Associate (OCA)
◈ Oracle Certified Professional (OCP)
◈ Oracle Certified Master (OCM)
◈ Oracle Certified Expert (OCE) and
◈ Oracle Certified Specialist (OCS)

So make sure to take enough time to study and gain enough knowledge to past test after test.

11. LPIC-2: Linux Engineer


The LPIC-2 is an engineer certification meant specifically or Linux Engineers. In order to obtain this certificate, you must first and foremost pass the LPIC-2 201 and the LPIC-2 202. Similar to the LPIC-1, this certificate is distro independent.

There are other certificates worth mentioning such as the Certified Novell Linux Engineer, the Certified Novell Identity Manager Administrator, and the IBM Admin Certifications.