Showing posts with label Linux Command. Show all posts
Showing posts with label Linux Command. Show all posts

Tuesday, 20 July 2021

Top 5 Linux Certifications in 2021

Top 5 Linux Certifications in 2021, LPI Exam Prep, LPI Tutorial and Material, LPI Certification, LPI Prep, LPI Learning, LPI Preparation, Linux Certification

Top 5 Linux Certifications to Get in 2021

Best Linux Certifications are what you should aim for in 2021. Well, this is what the experts believe! But definitely, it might be a tough decision to make about choosing the right Linux certifications to boost up your career. Especially, the beginners, right? But, we here have simplified it for you. And, here is the list of those top 5 Linux certifications that you must go for in this year.

Top 5 Linux Certifications in 2021, LPI Exam Prep, LPI Tutorial and Material, LPI Certification, LPI Prep, LPI Learning, LPI Preparation, Linux Certification

1. LINUX+ CompTIA


It has almost been two decades that employers have used this certification as their skills benchmark for employing any professional in the IT world. And, so attaining this has become the utter need for every individual who is looking forward to entering into this area of IT.

CompTIA Linux+ is one of the Linux certifications that tests the essential usage and managerial tasks that are common to all Linux distributors. Yes, UNIX flavors need it too! So, to attain this Linux+ certification, you are ought to get through these two tests, which are CompTIA Linux Certification (LX0-103) and CompTIA Linux Certification (LX0-104), which actually shares the similar content to LPIC-1 (LPI Level 1 – Linux Administrator certification. Of course, this has to be done through any Linux Professional Institute to list yourself among all those who are actually eligible to enter into the field of Linux.

Let’s know more about these two Linux certifications here:

CompTIA Linux Certification (LX0-103) – Explained

This test covers these few domains, which are:

◉ GNU and UNIX Commands
◉ System Architecture
◉ Linux Installation and Package Management
◉ Devices, Linux Filesystems, Filesystem Hierarchy Standard

CompTIA Linux Certification (LX0-104) – Explained

This test covers these few domains, which are:

◉ Security
◉ Shells, Scripting, and Data Management
◉ User Interfaces and Desktops
◉ Administrative Tasks
◉ Essential System Services
◉ Networking Fundamentals

Both these tests have 60 MCQs, which needs to be done within a time limit of 90 minutes. The passing score is 500 on the scale of 200-800 and all questions are weight based. Both the tests are to be passed to get the certification.

Why should you go for these Linux Certifications?

These Linux Certifications are important for every Linux oriented professional because of these following reasons:

a) Brand Recognition – CompTIA Linux+ will give you brand recognition, which most of the HR departments and IT managers are already aware of. All of them know, if any certification in Linux is ending with a + sign, then that’s surely going to be a good skill benchmark for any IT professional. So, yes, brand recognition is something you will achieve after becoming a CompTIA Linux+ professional.

b) Foundation of all Linux Jobs - For almost every job that involves the word ‘Linux’, you can consider this certification as a foundation. As this certification edifies you about all the general administration tasks, which most of the organizations would generally seek, your chances of getting hired almost doubles. Basically, it allows you to gain knowledge of all the administration concepts and tasks, which are generally expected in any organization.

So, get yourself educated about CompTIA Linux+ seems to quite helpful in getting all those important tasks done in the Linux department.

2. RHCE- RED HAT CERTIFIED ENGINEER


In the dominion of Linux world and Linux certifications, there is another important certification called RHCE- Red Hat Certified Engineer. Red Hat Certifications really stand out amongst all the Linux certifications and surely it has the power to make you too stand out from the bunch of professionals as well.

Among all the Red Hat Certifications, Red Hat’s more senior-level certifications are quite popular. So, go for the senior-level ones for getting hired in those top organizations. And, in case you hold this certification, there are different roles in the Linux world which you may try for. Some of these job roles are senior Linux administrator, senior systems engineer, IT analyst, senior UNIX administrator, and the like.

How tough is it to attain this certification?

Well, if we believe those sitting at the top positions in the IT world, this is one of the best Linux certifications, which any Linux professional must go for. And, that’s why it is not easy to obtain. So, for becoming a Red Hat Certified Engineer, you must first obtain the Red Hat Certified System Administrator (RHCSA) credential, which is then followed by passing a three and a half hour test, hands-on, and an exam that is performance-based including both demanding and intense questions.

In case, you have earned RHCE, you become eligible for RHCA (Red Hat Certified Architect) credentials including:

◉ RHCA: Application development
◉ RHCA: Datacenter
◉ RHCA: Cloud
◉ RHCA: DevOps
◉ RHCA: Application platform

So, in short, if you are looking for a better position and payout in any IT organization, we recommend you to go for this certification in 2021.

3. GCUX: GIAC CERTIFIED UNIX SECURITY ADMINISTRATOR


GIAC Certified UNIX System Administrators secures and audit Linux and UNIX systems. It is one of the Linux certifications that is done to attain the skills and abilities to do so. The main motive of this certification is to train individuals in installing, configuring, and monitoring both these systems. So, like any other Linux certification test, this one too has a few requirements, which are as follows:

◉ 75 questions
◉ 1 proctored exam
◉ Time Limit- 2 hours
◉ Minimum passing score of 68%

Basically, the candidate understands the physical security issues and password security with respect to both the UNIX and Linux systems. This exam even tests the capability of the candidate to understand Chroot- how to configure its services, its environment, how to configure scponly with chroot, and everything else about Chroot. Apart from this, some others areas of the UNIX and Linux are also touched including OS Install and Patching, Physical, User Account, and Password Access Control, Boot Services, Post-Exploitation and AIDE, SUDO, and many other important sections, without which UNIX and Linux, both are incomplete.

Being a part of SANS, this Linux certification is highly recommended to every Linux professional in 2021.  It encompasses more than 35 security certifications across different categories, which we mentioned above. Such an administrator falls under the Cyber Defense category. Also, their certifications need renewal after every four hours by earning 36 continuing professional experience which is also known as CPE.

4. ORACLE LINUX OCA & OCP


This Linux certification is all about attaining skills and abilities related to Oracle products and technologies. For passing the test to get the certification, the professional needs to pass the combination of passing exams and training and performance-based assignments, which depend on the level of certification.

With 6 levels of Oracle Certification Credentials- 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), a candidate needs to master all such stages to be hired by a reputed IT company.

Certifications comprise of two exams, which are:

◉ OCA - 1Z0-100 Oracle Linux 5 and 6 System Administration, needs 61% to pass, and 80 questions to attempt

◉ OCP - 1Z0-105 Oracle Linux 6 Advanced System Administrator, requires 61% to pass, and has a total of 97 questions.

5. LPI (LINUX PROFESSIONAL INSTITUTE) CERTIFICATIONS


Started back in 1999 by Linus Torvalds, these Linux certifications today has become important for any Linux professional. This program is available in three distinct levels, which are:


It is a junior-level Linux certification with no perquisites. The candidate needs to pass 2 exams, which covers all basic Linux skills that even include installing and configuring Linux on a workstation, performing maintenance tasks, making LAN or internet connections, and more. Obtain CompTIA Linux+ powered by LPI credential first; which will make you qualified both for Linux+ and LPIC-1 credentials.


This is an advanced level Linux Certification, which requires an active LPIC-1 certification. It has two exams- First covers the file system and devices, kernel, system startup, network configuration, system maintenance, storage administration, and even capacity planning and the second exam covers email services, network client management, domain name servers, system security and troubleshooting, and the like tasks.


It is a senior-level Linux certification, which needs an active LPIC-2 besides passing any single exam in the 300 series. This certification includes exam IDs, which are:

◉ 300: Mixed Environment
◉ 303: Security
◉ 304: Virtualization and High Availability

300: Mixed Environment covers Samba, work with Linux & windows client, and even plus OpenLDAP.

303: Security covers operations, application security, and the network are covered under the security exam besides cryptography and access controls.

304: Virtualization and High Availability covers virtualization and high availability cluster storage and engagement.

Latest Certification in LPIC

LPI’s latest certification is the LPIC-OT DevOps Tools Engineer, which allows the Linux professionals to utilize the tools for collaboration during software and system development. The exam has 60 questions and it lasts for about 90 minutes.

Linux professionals, thus, have a whole new set of Linux certifications to attain in 2021. We believe that this guide is helpful for all the Linux professionals in finding some of the best Linux certifications and finding a new way in the world of Linux thereafter.

Source: whizlabs.com

Tuesday, 29 June 2021

apmsleep - Unix, Linux Command

LPI Exam Prep, LPI Tutorial and Material, LPI Certification, LPI Guides, LPI Preparation, LPI Learning, LPI Career

NAME

apmsleep - go into suspend or standby mode and wake-up later

SYNOPSIS

apmsleep [-sSnwhVd] [--suspend] [--standby] [--noapm] [--wait] [--precise] [--help] [--version] [--debug] [+]hh:mm

More Info: 010-160: LPI Linux Essentials (Linux Essentials 010)

DESCRIPTION

Some computers, especially laptops, can wake-up from a low-power suspend to DRAM mode using the Real-time-clock (RTC) chip. Apmsleep can be used to set the alarm time in the RTC and to go into suspend or standby mode. An interrupt from the RTC causes the computer to wake-up. The program detects this event, by waiting for a leap in the kernel time and terminates successfully. If no time leap occurs within one minute, or something goes wrong, the exit value will be non-zero.

The wake-up time can be specified in two formats:

+hh:mm specifies a relative offset to the current time. The computer will suspend for exactly hh hours and mm minutes plus a few seconds to wake up. On some laptops, the timing is not completely accurate so it may be a few minutes (or more?) late.

hh:mm specifies absolute local time in 24-hour format. The time stored in the RTC is not important. You may change the time zone used, with the TZ environment variable as usual. Daylight saving time is not obeyed in this version, but might be in a future release. WARNING: Do not close cover of laptop after suspending the laptop with apmsleep. Most laptops overheat when running with closed cover.

Energy conservation with APM is little for a desktop. Turning of the screen will save 1/2, going into standby with drives turned off will save another 1/6th of the current.

Tag Description 
-V, --version  
  Print the apmsleep program version and exit immediately.
-s, --suspend   
  Put the machine into suspend mode if possible (default). On my laptop, suspend mode turns off everything except the memory. 
-S, --standby   
  Put the machine into standby mode if possible. On my laptop, standby mode turns off screen, hard disk, and CPU. 
-w, --wait  Wait indefinitely for the time leap. 
-p, --precise   
  Wait for alarm time to match actual time. Do not wait for time leap. This might be useful even without APM. 
-n, --noapm   
  Do not call apm bios to suspend computer, just set the alarm clock and wait for time leap indefinitely. 
-d, --debug  
  Print some information about what is going on.

REQUIRED SYSTEM CONFIGURATION

Tag Description 
Kernel The special character device /dev/rtc must exist and the kernel needs to be compiled with APM and RTC support.
BIOS  The computer must have the ’suspend to RAM’ feature enabled in the BIOS; ’suspend to Disk’ will not work, because the computer is turned off completely. You do not need to enable the ALARM timer, it will be activated by apmsleep. On some boards, you can configure which interrupts can be used to awake from suspend mode. If you have such a board, you might want to make sure that keyboard (IRQ 1) and RTC (IRQ 8) are among those interrupts. If your computer does not wake up, try to enable ’modem ring’ in the BIOS, even if you do not have a modem.
Privileges  
  The program must be run as root or have the SUID attribute set (see chmod(1)).

BUGS

Apmsleep cannot detect which event terminated the suspension. Possible events are: keyboard or mouse activity, modem ring, alarm from RTC, any other interrupt. Sometimes, the time leap is not detected properly (causing a wrong exit value).

Should use APM BIOS calls to set alarm clock (not yet supported by kernel).

This program was tested on a Winbook XL laptop (Pentium) only. It may not function on your hardware.

Source: tutorialspoint.com

Saturday, 5 June 2021

Basic Linux Commands

Basic Linux Commands, Linux Exam Prep, Linux Preparation, Linux Certification, LPI Preparation, LPI Guides, LPI Career

Basic Linux Commands

Now, let us look at the most important 20 commands in Linux. Linux commands are case sensitive hence you need to be careful about what you are keying in.

1. ls –

List directory contents. If you know windows you would know that the command dir is used to list the contents in a directory. In Linux, the ls command is used to list out files and directories. Some versions may support color-coding. The names in blue represent the names of directories.

More Info: LPIC-3 300: Linux Enterprise Professional Mixed Environment

ls -l | more – this helps to paginate the output so you can view page by page. Otherwise the listing scrolls down rapidly. You can always use ctrl c to go back to the command line.

$ ls -l filename

2. cd /var/log –

Change the current directory. The forward slash is to be used in Linux. The example is a Linux directory that comes with all versions of Linux.

When you use ls –I you will be able to see more details of the contents in the directory

It will list down the

◉ Permissions associated with the file

◉ The owner of the file

◉ The group associated with the file

◉ The size of the file

◉ The time stamp

◉ The name of the file

$ cd /var/log

3. grep –

Find text in a file. The grep command searches through many files at a time to find a piece of text you are looking for.

grep PATTERN [FILE]

grep failed transaction.log

The above command will find all of the words in the files that matched the word ‘failed’.

$ grep ‘failed’ transaction.log

4. su / sudo command –

There are some commands that need elevated rights to run on a Linux system. So you run them as a System Administrator which normal users cannot do.

su command changes the shell to be used as a super user and until you use the exit command you can continue to be the super user

sudo – if you just need to run something as a super user, you can use the sudo command. This will allow you to run the command in elevated rights and once the command is executed you will be back to your normal rights and permissions.

Example – shutdown command the shutdown command safely turns off the computer system.

◉ sudo shutdown 2 – shutdown and turns of the computer after 2 minutes

◉ sudo shutdown –r 2 – shuts down and reboots in 2 minutes

◉ Using ctrl C or shutdown –c helps in stopping the shutdown process.

$ sudo shutdown 2

$ sudo shutdown –r 2

5. pwd – Print Working Directory

One way to identify the directory you are working in is the pwd command

It displays the current working directory path and is useful when directory changes are often

$ pwd

6. passwd –

Though looks similar to the pwd command the role it plays is different.

This command is used to change the user account password. You could change your password or the password of other users. Note that the normal system users may only change their own password, while root may modify the password for any account.

passwd [username] - changes the password for the user.

$ passwd admin

7. mv – Move a file

To move a file or rename a file you would use the mv command.

Here the file name gets changed from first.txt to second.txt.

Type ls to view the change

$ mv first.txt second.txt

8. cp – Copy a file

cp source file destination file. In case you need a copy of the file second.txt in the same directory you have to use the cp command

$ cp second.txt third.txt

You can use ls – l to see the new file created. The two files will be exactly of the same size.

9. rm –

This command is used to remove files in a directory or the directory itself. A directory cannot be removed if it is not empty.

rm [name of the file]

rm –r removes all the contents in a directory and the directory as well.

$ rm file1

$ rm -r myproject

10. mkdir – to make a directory.

mkdir [directory name] if you would like to create a directory in the name ‘myproject’ type

mkdir myproject

$ mkdir myproject

11. chmod –

To change mode of a file system object. Files can have r – read, w- write and x-execute permissions.

For example:

◉ chmod mode FILE

◉ chmod 744 script.sh

◉ The first number stands for the user who is associated with the file

◉ The second number is for the group associated with the file

◉ The third number is associated with everyone else who is not a part of the user or group

$ chmod 744 script.sh

Octal Notation Octal Notation   Symbolic Representation 
0 No Permission --- 
Execute Permission Only  --x 
Write Permission Only  -w- 
Write and Execute Permissions (1+2)=3  -wx 
Read Permission Only  r-- 
Read and Execute Permissions (1+4)=5  r-x 
Read and Write Permissions (2+4)=6  rw- 
Read, Write and Execute Permissions, Means Full Permissions (1+2+4)=7  rwx 

From the table you will see that the rights given will be as

◉ -rwxr- - r- - rwx for user
◉ r - - for the group (read only)
◉ r - - for others (read only)

Other ways of using chmod are

◉ chmod a-w first.txt

This means all users have no write access to the file first.txt.

◉ chmod u + x script.sh

The owner of script.sh can execute the file

12. chown –

This command is used to change the ownership of a file/folder or even multiple files/folders for a specified user/group.

Basic Linux Commands, Linux Exam Prep, Linux Preparation, Linux Certification, LPI Preparation, LPI Guides, LPI Career

chown owner_name file_name

$ chown user1 script.sh

Assume that if you are a user named user1 and you want to change ownership to root use “sudo” before syntax.

$ sudo chown root script.sh

13. cat -

The cat command (short for “concatenate “) is one of the most frequently used commands in Linux. cat command allows you to create single or multiple files, view contents of file, concatenate files and redirect output in terminal or files.

$ cat file.txt
$ cat file1.txt file2.txt

Output will show the entire contents of the file(s).

14. echo –

This command is used to display a text or a string to the standard output or a file.

$ echo “This is an article on basic linux commands”

This is an article on basic linux commands

The echo –e option acts as an interpretation of escape characters that are back-slashed.

$ echo –e “This is an article is for beginners. \nIt is on basic linux commands

Will display the output as

This is an article is for beginners.
It is on basic linux commands

\n the newline character is interpreted by the echo –e command

15. wc -

The wc (word count) command in Linux operating system is used to find out the number of new lines, word count, byte and characters count in a file specified by the file arguments.

wc [options] filenames.

$ wc –l readme.txt

Shows the output as - 120 readme.txt

◉ wc -l : Prints the number of lines in a file.
◉ wc -w : prints the number of words in a file.
◉ wc -c : Displays the count of bytes in a file.
◉ wc -m : prints the count of characters from a file.
◉ wc -L : prints only the length of the longest line in a file.

16. man –

This command is used to view the on-line reference manual pages for commands/programs.

$ man grep
$ man mkdir

17. history –

This command is used to show previously used commands or to get information about the commands executed by a user.

$ history

18. clear –

This command lets you clear the terminal screen.

$ clear

19. apt –get

apt -get is a powerful and free front-end package manager for Debian/Ubuntu systems. It is used to install new software packages, remove available software packages, upgrade existing software packages as well as upgrade the entire operating system. apt – stands for advanced packaging tool.

$ sudo apt-get update

20. reboot –

This command may be used to halt, power-off or reboot a system as follows.

$ reboot

Source: hackr.io

Thursday, 15 October 2020

The Linux cancel command (cancel a print job)

The Linux "cancel" command lets you stop print requests from printing (cancel them).

Linux Cancel Command, Linux Study Materials, Linux Exam Prep, Linux Certification, Linux Guides

Linux printing requests can be canceled by either (a) using the printer-id or (b) by specifying the printer name. Here are examples of each approach.

cancel laser-101

This first command cancels the print request identified as "laser-101". (You would have gotten this identifier using an lpstat command.

cancel -u student1

This command cancels all of the print jobs that are queued for the user named "student1".

Read More:

Linux Cancel Command, Linux Study Materials, Linux Exam Prep, Linux Certification, Linux Guides
LPI is the global certification standard and career support organization for open source professionals. LPI has certified professionals in over 180 countries, delivers exams in 9 languages, and has over 400 training partners.

LPI Certifications

Thursday, 10 September 2020

uniq Command in LINUX with examples

Uniq Command, Linux Study Material, Linux Exam Prep, Linux Tutorial and Material, LPI Certification

The uniq command in Linux is a command line utility that reports or filters out the repeated lines in a file.

In simple words, uniq is the tool that helps to detect the adjacent duplicate lines and also deletes the duplicate lines. uniq filters out the adjacent matching lines from the input file(that is required as an argument) and writes the filtered data to the output file.

Syntax of uniq Command :


 //...syntax of uniq...// 
$uniq [OPTION] [INPUT[OUTPUT]]

The syntax of this is quite easy to understand. Here, INPUT refers to the input file in which repeated lines need to be filtered out and if INPUT isn’t specified then uniq reads from the standard input. OUTPUT refers to the output file in which you can store the filtered output generated by uniq command and as in case of INPUT if OUTPUT isn’t specified then uniq writes to the standard output.

Now, let’s understand the use of this with the help of an example. Suppose you have a text file named kt.txt which contains repeated lines that needs to be omitted. This can simply be done with uniq.

//displaying contents of kt.txt//

$cat kt.txt
I love music.
I love music.
I love music.

I love music of Kartik.
I love music of Kartik.

Thanks.

Now, as we can see that the above file contains multiple duplicate lines. Now, lets’s use uniq command to remove them:

//...using uniq command.../

$uniq kt.txt
I love music.

I love music of Kartik.

Thanks.

/* with the use of uniq all
the repeated lines are removed*/

As you can see that we just used the name of input file in the above uniq example and as we didn’t use any output file to store the produced output, the uniq command displayed the filtered output on the standard output with all the duplicate lines removed.

Note: uniq isn’t able to detect the duplicate lines unless they are adjacent. The content in the file must be therefore sorted before using uniq or you can simply use sort -u instead f uniq.

Options For uniq Command:


1. -c – -count : It tells how many times a line was repeated by displaying a number as a prefix with the line.

2. -d – -repeated : It only prints the repeated lines and not the lines which aren’t repeated.

3. -D – -all-repeated[=METHOD] : It prints all duplicate lines and METHOD can be any of the following:

◉ none : Do not delimit duplicate lines at all. This is the default.

◉ prepend : Insert a blank line before each set of duplicated lines.

◉ separate : Insert a blank line between each set of duplicated lines.

4. -f N – -skip-fields(N) : It allows you to skip N fields(a field is a group of characters, delimited by whitespace) of a line before determining uniqueness of a line.

5. -i – -ignore case : By default, comparisons done are case sensitive but with this option case insensitive comparisons can be made.

6. -s N – -skip-chars(N) : It doesn’t compares the first N characters of each line while determining uniqueness. This is like the -f option, but it skips individual characters rather than fields.

7. -u – -unique : It allows you to print only unique lines.

8. -z – -zero-terminated : It will make a line end with 0 byte(NULL), instead of a newline.

9. -w N – -check-chars(N) : It only compares N characters in a line.

10. – – help : It displays a help message and exit.

11. – – version : It displays version information and exit.

Examples of uniq with Options


1. Using -c option: It tells the number of times a line was repeated.

//using uniq with -c//

$uniq -c kt.txt
3 I love music.
1
2 I love music of Kartik.
1
1 Thanks.

/*at the starting of each 
line its repeated number is
displayed*/

2. Using -d option : It only prints the repeated lines.

//using uniq with -d//

$uniq -d kt.txt
I love music.
I love music of Kartik.

/*it only displayed one
 duplicate line per group*/

3. Using -D option: It also prints only duplicate lines but not one per group.

//using -D option//

$uniq -D kt.txt
I love music.
I love music.
I love music.
I love music of Kartik.
I love music of Kartik.

/* all the duplicate lines 
are displayed*/

4. Using -u option: It prints only the unique lines.

//using -u option//

$uniq -u kt.txt
Thanks.

/*only unique lines are
displayed*/

5. Using -f N option: As told above, this allows the N fields to be skipped while comparing uniqueness of the lines. This option is helpful when the lines are numbered as shown in the example below:

//displaying contents of f1.txt//

$cat f1.txt
1. I love music.
2. I love music.
3. I love music of Kartik.
4. I love music of Kartik.

//now using uniq with -f N option//

$uniq -f 2 f1.txt
1. I love music.
3. I love music of Kartik.

/*2 is used cause we needed to
compare the lines after the
numbering 1,2.. and after dots*/

6. Using -s N option: This is similar to -f N option but it skips N characters but not N fields.

//displaying content of f2.txt//

$cat f2.txt
#%@I love music.
^&(I love music.
*-!@thanks.
#%@!thanks.

//now using -s N option//

$uniq -s 3 f2.txt
#%@I love music.
*-!@thanks.
#%@!thanks.

/*lines same after skipping
3 characters are filtered*/

7. Using -w option: Similar to the way of skipping characters, we can also ask uniq to limit the comparison to a set number of characters. For this, -w command line option is used.

//displaying content of f3.txt//

$cat f3.txt
How it is possible?
How it can be done?
How to use it?

//now using -w option//

$uniq -w 3 f3.txt
How

/*as the first 3 characters
of all the 3 lines are same
that's why uniq treated all these
as duplicates and gave output 
accordingly*/

8. Using -i option: It is used to make the comparison case-insensitive.

//displaying contents of f4.txt//

$cat f4.txt
I LOVE MUSIC
i love music
THANKS

//using uniq command//
$uniq f4.txt
I LOVE MUSIC
i love music
THANKS

/*the lines aren't treated
as duplicates with simple 
use of uniq*/

//now using -i option//

$uniq -i f4.txt
I LOVE MUSIC
THANKS

/*now second line is removed
when -i option is used*/

9. Using -z option: By default, the output uniq produces is newline terminated. However, if you want, you want to have a NULL terminated output instead (useful while dealing with uniq in scripts). This can be made possible using the -z command line option.

Syntax:

//syntax of using uniq
with -z option//

$uniq -z file-name

Saturday, 25 July 2020

Read command line arguments - Unix / Linux Bash Script

Q) How to read the arguments or parameters passed to a shell script from the command line?

In general the command line arguments are passed to the bash or shell script to change the behavior of the script. In this article, I am going to provide a simple shell script to read and print the command line parameters.

Also Read: 201-450: Linux Engineer - 201 (LPIC-2 201)

Unix / Linux Bash Script, Unix Guides, LPI Study Materials, LPI Certifications

Take a look at the following unix shell script:

> cat OS_Print.sh
#!/bin/bash
echo "Script execution starts"
echo "$@"
echo "$0"
echo "$1"
echo "$2"
echo "$#"
echo "Script execution ends"

The basic functionality of the above script is to print the values stored in the $ variables. Now we will run the above script by passing some arguments.

> OS_Print.sh unix linux
Script execution starts
unix linux
OS_Print.sh
unix
linux
2
Script execution ends

You can see, the command line arguments passed here are unix and linux. Command line arguments are a list of parameters separated by space delimiters passed to the shell script.

Explanation of $ variables:


◈ $@ : contains all the arguments
◈ $0 : contains script name
◈ $1 : First argument
◈ $2 : Second argument
◈ $n : Nth argument
◈ $# : Count of arguments passed.

Examples:


1. Script to iterate through arguments.

The following script prints the parameters using for loop.

#!/bin/bash

for value in $@
do
  echo $value
done

2. Print only the last argument.

There are many ways to display the last argument. The following script shows the different ways of printing the last argument.

#!/bin/bash

echo "${@: -1}"
echo "${BASH_ARGV[0]}"
echo "${@: $#}"
echo "${!#}"

for value in $@; do :; done
echo $value

Tuesday, 21 July 2020

Record your Linux command line with the script command

Linux Tutorial and Material, Linux Guides, Linux Exam Prep, Linux Learning

Linux command line FAQ: How can I record the input and output of my Linux command line (i.e., the Linux commands I type, and the output from those commands)?

Record Linux command line input/output with the script command


Today I was installing a product from the command line on a Unix/Linux system, and they asked if I could let them know how the installation went. I said "Yes, I can let you know exactly how it goes", because I knew that I could record my entire command line login session using the Unix/Linux/BSD script command.

The script command is usually a no-brainer to use. When you're ready to start recording the input/output of your login session, just type

script

at the command line. You'll get a message back from the operating system that looks like this:

Script started, file is typescript

This is the system's way of telling you that it is now recording everything you type, and everything that is displayed on your console. When you're finished recording whatever it is that you want to record, type [Ctrl]-d or exit, and your script session will end. (Make sure you only do an exit command once to exit the script environment, because if you do it twice, the second "exit" command you issue will log you out of your system.)

When you do so, you'll see a message that looks like this:

Script done, file is typescript

If you'll now look at this file named typescript, you'll see that it contains everything you typed, and everything that the system printed out, as promised. Depending on what you do at the command line it may also contain a bunch of control characters, but those are easily weeded out so you can get back to plain ASCII text. I'll show how to do that in another blog entry.

Note that the script command should be available for recording your login session on most Unix systems, including vanilla Unix, Linux, BSD/freeBSD, Solaris, AIX, and others.

Saturday, 18 July 2020

The Linux ping command

LPI Tutorial and Material, LPI Study Materials, LPI Exam Prep, LPI Guides

Linux command FAQ: Can you share some examples of the Linux ping command?


You typically use the Linux ping command to test to see whether a remote server is up and running, or to test problems with a network. For instance, my internet connection here in Alaska tends to get flaky from time to time, and when things appear to be going bad, I use the ping command to verify the problem.

Basic ping example


In its basic use, you just issue the ping command followed by the name of a server or website, like this:

ping www.google.com

The ping command then sends little packets of information to the remote server, and if all goes well, they are acknowledged by that remote server. (From a security perspective, that remote server must also be configured to respond to ping requests. Some Linux administrators disable this feature.)

For instance, when my network connection is working fine, here's what the ping command results look like when I ping Google:

$ ping www.google.com

PING www.l.google.com (72.14.213.99): 56 data bytes
64 bytes from 72.14.213.99: icmp_seq=0 ttl=50 time=48.582 ms
64 bytes from 72.14.213.99: icmp_seq=1 ttl=50 time=48.655 ms
64 bytes from 72.14.213.99: icmp_seq=2 ttl=50 time=49.171 ms
64 bytes from 72.14.213.99: icmp_seq=3 ttl=50 time=50.554 ms
^C
--- www.l.google.com ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 48.582/49.204/50.554/0.691 ms

The thing I always look at is the "time" information, shown at the end of each line of output. For me, anything under 50 msec usually indicates that my network connection is working fine. When my network connection goes bad, the output of that time field fluctuates drastically (at which point I call my internet service provider).

One important thing to note: When you issue the ping command as shown, you normally use the [Control][c] key sequence to stop the command. That's how you do things on Linux, Unix, and Mac OS X systems; the last time I tried this on Windows the ping command ran for only a few times and then stopped itself, so things may still be different there.

The Linux ping command - Controlling the number of pings


If you remember the movie The Hunt for Red October, there's a point at which Sean Connery is in the submarine, and he tells the other man, "Give me one ping." This was a pretty funny moment for Unix administrators like myself who had used the ping command for so many years, because it was a great, real world description of the ping command.

It also demonstrated something else: There are times when you don't want the ping command to run forever, you may just want to issue one ping, five pings, or ten pings, etc. In that case, you use the -c option ("count") of the ping command to control the number of pings issued, like this:

$ ping -c 5 www.google.com

PING www.l.google.com (74.125.53.105): 56 data bytes
64 bytes from 74.125.53.105: icmp_seq=0 ttl=50 time=49.198 ms
64 bytes from 74.125.53.105: icmp_seq=1 ttl=50 time=46.662 ms
64 bytes from 74.125.53.105: icmp_seq=2 ttl=50 time=52.202 ms
64 bytes from 74.125.53.105: icmp_seq=3 ttl=50 time=50.108 ms
64 bytes from 74.125.53.105: icmp_seq=4 ttl=50 time=51.690 ms

--- www.l.google.com ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 46.662/49.972/52.202/1.975 ms

Ping a specific port


You can also use the ping command to ping a port on a Unix or Linux system. Here's the description from the Linux ping man page:

-p port

Set the base UDP port number used in probes. This
option  is  used  with the -U option. The default
base port  number  is  33434.  The  ping  utility
starts setting the destination port number of UDP
packets to this base and increments it by one  at
each probe.

Honestly, I don't know much about this, and I don't have a need for this, so I'll leave it at that. One writer suggested using a port-scanning tool named nmap if you need to "ping" a port. nmap lets you see whether ports are "open" (listening), and I use it to test open ports on firewall setups, so in regards to trying to "ping a port", that's a good suggestion.

More Unix/Linux ping command information


There are more things you can do with the Unix/Linux ping command, but far and away these are the most common ping command options I use. For more information, use the Unix man command to get more information on the ping command, like this:

man ping

One final note about the ping command: It has become much more common for Unix and Linux administrators to turn off the ping command on their servers. So, if you can't ping one of your own servers, make sure you have the ping service enabled on that server, or that a firewall isn't blocking your ping attempts.

Tuesday, 7 July 2020

Linux mail - a Linux shell script to send mail

Linux Mail, LPI Study Material, LPI Exam Prep, LPI Tutorial and Material, LPI Study Material

Here's a n example Linux shell script (Bourne shell to be specific) that I use to send a list of directories to one of our invoicers. She uses this list as part of a cross-checking process to make sure she bills each one of our customers who have a directory allocated to them. The list is sent to her automatically from a Linux crontab entry I created for her.

Also Read: 101-500: Linux Administrator - 101 (LPIC-1 101)

Without any further ado, here is the Linux shell script that sends the email. (Note that although I keep writing "Linux mail", this should also work on other Unix systems.)

Example Linux shell script - sending mail


Here's the source code for the Linux shell script that sends the email message out every day:

#!/bin/sh

cd /home/lpicentral/bin

echo "

DO NOT REPLY TO THIS EMAIL MESSAGE.

This is a list of the current customer directories installed on our server.
Please make sure they are all billed.

"                       >  listOfWebSites
ls -1 /customers        >> listOfWebSites

mail -s "Current customer directories on our server" kim@herdomain.com < listOfWebSites

That script creates a file named listOfWebSites, then sends that file via the standard Linux mail command.

Corresponding Linux crontab entry


Here is the crontab entry that I use to send this email message every day. If you're familiar with the crontab format you should be able to easily figure out the date and time this information is mailed to here.

30 7 12 * * /home/lpicentral/bin/mailWebSitesToKim

I thought this was a pretty decent use of shell scripting and the built-in Linux mail command. Notice how easy the Unix operating system and redirection operators make this.

Saturday, 6 June 2020

Sed Command in Unix and Linux Examples

Sed Command, LPI Tutorial and Material, LPI Exam Prep, LPI Guides, LPI Certification

Sed is a Stream Editor used for modifying the files in unix (or linux). Whenever you want to make changes to the file automatically, sed comes in handy to do this. Most people never learn its power; they just simply use sed to replace text. You can do many things apart from replacing text with sed. Here I will describe the features of sed with examples.

Consider the below text file as an input.

>cat file.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
unixlinux which one you choose.

Sed Command Examples


1. Replacing or substituting string

Sed command is mostly used to replace the text in a file. The below simple sed command replaces the word "unix" with "linux" in the file.

>sed 's/unix/linux/' file.txt
linux is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.

Here the "s" specifies the substitution operation. The "/" are delimiters. The "unix" is the search pattern and the "linux" is the replacement string.

By default, the sed command replaces the first occurrence of the pattern in each line and it won't replace the second, third...occurrence in the line.

2. Replacing the nth occurrence of a pattern in a line.

Use the /1, /2 etc flags to replace the first, second occurrence of a pattern in a line. The below command replaces the second occurrence of the word "unix" with "linux" in a line.

>sed 's/unix/linux/2' file.txt
unix is great os. linux is opensource. unix is free os.
learn operating system.
unixlinux which one you choose.

3. Replacing all the occurrence of the pattern in a line.

The substitute flag /g (global replacement) specifies the sed command to replace all the occurrences of the string in the line.

>sed 's/unix/linux/g' file.txt
linux is great os. linux is opensource. linux is free os.
learn operating system.
linuxlinux which one you choose.

4. Replacing from nth occurrence to all occurrences in a line.

Use the combination of /1, /2 etc and /g to replace all the patterns from the nth occurrence of a pattern in a line. The following sed command replaces the third, fourth, fifth... "unix" word with "linux" word in a line.

>sed 's/unix/linux/3g' file.txt
unix is great os. unix is opensource. linux is free os.
learn operating system.
unixlinux which one you choose.

5. Changing the slash (/) delimiter

You can use any delimiter other than the slash. As an example if you want to change the web url to another url as

>sed 's/http:\/\//www/' file.txt

In this case the url consists the delimiter character which we used. In that case you have to escape the slash with backslash character, otherwise the substitution won't work.

Using too many backslashes makes the sed command look awkward. In this case we can change the delimiter to another character as shown in the below example.

>sed 's_http://_www_' file.txt
>sed 's|http://|www|' file.txt

6. Using & as the matched string

There might be cases where you want to search for the pattern and replace that pattern by adding some extra characters to it. In such cases & comes in handy. The & represents the matched string.

>sed 's/unix/{&}/' file.txt
{unix} is great os. unix is opensource. unix is free os.
learn operating system.
{unix}linux which one you choose.

>sed 's/unix/{&&}/' file.txt
{unixunix} is great os. unix is opensource. unix is free os.
learn operating system.
{unixunix}linux which one you choose.

7. Using \1,\2 and so on to \9

The first pair of parenthesis specified in the pattern represents the \1, the second represents the \2 and so on. The \1,\2 can be used in the replacement string to make changes to the source string. As an example, if you want to replace the word "unix" in a line with twice as the word like "unixunix" use the sed command as below.

>sed 's/\(unix\)/\1\1/' file.txt
unixunix is great os. unix is opensource. unix is free os.
learn operating system.
unixunixlinux which one you choose.

The parenthesis needs to be escaped with the backslash character. Another example is if you want to switch the words "unixlinux" as "linuxunix", the sed command is

>sed 's/\(unix\)\(linux\)/\2\1/' file.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
linuxunix which one you choose.

Another example is switching the first three characters in a line

>sed 's/^\(.\)\(.\)\(.\)/\3\2\1/' file.txt
inux is great os. unix is opensource. unix is free os.
aelrn operating system.
inuxlinux which one you choose.

8. Duplicating the replaced line with /p flag

The /p print flag prints the replaced line twice on the terminal. If a line does not have the search pattern and is not replaced, then the /p prints that line only once.

>sed 's/unix/linux/p' file.txt
linux is great os. unix is opensource. unix is free os.
linux is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.
linuxlinux which one you choose.

9. Printing only the replaced lines

Use the -n option along with the /p print flag to display only the replaced lines. Here the -n option suppresses the duplicate rows generated by the /p flag and prints the replaced lines only one time.

>sed -n 's/unix/linux/p' file.txt
linux is great os. unix is opensource. unix is free os.
linuxlinux which one you choose.

If you use -n alone without /p, then the sed does not print anything.

10. Running multiple sed commands.

You can run multiple sed commands by piping the output of one sed command as input to another sed command.

>sed 's/unix/linux/' file.txt| sed 's/os/system/'
linux is great system. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you chosysteme.

Sed provides -e option to run multiple sed commands in a single sed command. The above output can be achieved in a single sed command as shown below.

>sed -e 's/unix/linux/' -e 's/os/system/' file.txt
linux is great system. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you chosysteme.

11. Replacing string on a specific line number.

You can restrict the sed command to replace the string on a specific line number. An example is

>sed '3 s/unix/linux/' file.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.

The above sed command replaces the string only on the third line.

12. Replacing string on a range of lines.

You can specify a range of line numbers to the sed command for replacing a string.

>sed '1,3 s/unix/linux/' file.txt
linux is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.

Here the sed command replaces the lines with range from 1 to 3. Another example is

>sed '2,$ s/unix/linux/' file.txt
linux is great os. unix is opensource. unix is free os.
learn operating system.
linuxlinux which one you choose.

Here $ indicates the last line in the file. So the sed command replaces the text from second line to last line in the file.

13. Replace on a lines which matches a pattern.

You can specify a pattern to the sed command to match in a line. If the pattern match occurs, then only the sed command looks for the string to be replaced and if it finds, then the sed command replaces the string.

>sed '/linux/ s/unix/centos/' file.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.
centoslinux which one you choose.

Here the sed command first looks for the lines which has the pattern "linux" and then replaces the word "unix" with "centos".

14. Deleting lines.

You can delete the lines a file by specifying the line number or a range or numbers.

>sed '2 d' file.txt
>sed '5,$ d' file.txt

15. Duplicating lines

You can make the sed command to print each line of a file two times.

>sed 'p' file.txt

16. Sed as grep command

You can make sed command to work as similar to grep command.

>grep 'unix' file.txt
>sed -n '/unix/ p' file.txt

Here the sed command looks for the pattern "unix" in each line of a file and prints those lines that has the pattern.

You can also make the sed command to work as grep -v, just by using the reversing the sed with NOT (!).

>grep -v 'unix' file.txt
>sed -n '/unix/ !p' file.txt

The ! here inverts the pattern match.

17. Add a line after a match.

The sed command can add a new line after a pattern match is found. The "a" command to sed tells it to add a new line after a match is found.

>sed '/unix/ a "Add a new line"' file.txt
unix is great os. unix is opensource. unix is free os.
"Add a new line"
learn operating system.
unixlinux which one you choose.
"Add a new line"

18. Add a line before a match

The sed command can add a new line before a pattern match is found. The "i" command to sed tells it to add a new line before a match is found.

>sed '/unix/ i "Add a new line"' file.txt
"Add a new line"
unix is great os. unix is opensource. unix is free os.
learn operating system.
"Add a new line"
unixlinux which one you choose.

19. Change a line

The sed command can be used to replace an entire line with a new line. The "c" command to sed tells it to change the line.

>sed '/unix/ c "Change line"' file.txt
"Change line"
learn operating system.
"Change line"

20. Transform like tr command

The sed command can be used to convert the lower case letters to upper case letters by using the transform "y" option.

>sed 'y/ul/UL/' file.txt
Unix is great os. Unix is opensoUrce. Unix is free os.
Learn operating system.
UnixLinUx which one yoU choose.

Here the sed command transforms the alphabets "ul" into their uppercase format "UL"

Thursday, 28 May 2020

Linux cd command examples

LPI Study Materials, LPI Guides, LPI Tutorial and Material, LPI Certification


Linux FAQ: Can you share some cd command examples?


The Linux cd command stands for "change directory". It is the primary command for moving between directories on a Unix/Linux filesystem.

Examples of the cd command


This first command moves you to the /usr directory. The /usr directory becomes your current working directory:

cd /usr

Similarly, this cd command moves you to the /tmp directory:

cd /tmp

You don't have to move just one directory at a time though. You can easily jump from one directory to another directory that's far, far away, like this:

cd /var/www/html/unix/edu

Linux cd command: Using wildcards


You can also use wildcard characters when moving between directories. This next command works just like the previous command, taking me to the /var/www/html/unix/edu directory on my Linux system:

cd /v*/w*/h*/u*/e*

The * wildcard characters can be interpreted as "any number of any character", so the Linux system expands the /v*/w*/h*/u*/e* that I typed into /var/www/html/unix/edu.

Linux cd command and auto-complete


An even better way to cd to that same directory is to use the auto-complete functionality in the Bash shell of all modern Linux systems. Using auto-complete, you can hit the [Tab] key any time you might normally use the asterisk, so I could move to that previous directory using the following keystrokes:

cd /v[Tab]/w[Tab]/h[Tab]/u[Tab]/e[Tab]

That doesn't look great in text, but trust me, you'll come to love the Bash auto-complete functionality. (As they would say on the tv show Monk, "You'll thank me later.")

The cd command: Going home


On all Unix and Linux systems that I'm aware of, you can always get back to your home directory by typing the cd command without any arguments, like this:

cd

As far as I know, that works with Bash, the Korn shell, the C shell, etc.

cd command: Back to the previous directory


Again, with every Unix and Linux shell I've worked with, you can also always move back to your previous directory by adding a hyphen after the cd command, like this:

cd -

This is a great feature for when you're moving back and forth between two different directories while working on a project.

Saturday, 23 May 2020

The Linux more command

LPI Exam Prep, LPI Tutorial and Material, LPI Certification, LPI More Command

The Linux more command lets you view text files or other output in a scrollable manner. It displays the text one screenful at a time, and lets you scroll backwards and forwards through the text, and even lets you search the text.

Looking at a Linux file with the more command


A common way to use the Linux more command is to display the contents of a text file. Where you might normally "cat out" the contents of a text file with the cat command, like this:

cat /etc/passwd

a problem with this approach is that when the file is long, all the output scrolls off the top of your screen. The Linux more command solves this problem by letting you scroll the output one screenful of data at a time. For this use, just use the more command instead of the cat command, like this:

more /etc/passwd

Now you can see the file contents on screen, and you can also scroll through the file output. On modern Linux systems you can use the [UpArrow] and [DownArrow] keys to scroll through the display. You can also use these keys to move through the output:

◉ [Space] - scrolls the display, one screenful of data at a time
◉ [Enter] - scrolls the display one line
◉ [b] - scrolls the display backwards one screenful of data
◉ [/] - lets you search the text, just like you would in the vi/vim editor

Use the Linux more command in a pipeline


It's also very common to use the Linux more command in a command pipeline. For instance, let's say you want to look at a list of system processes, but don't want them to all scroll off the top of your screen. In this case you use the more command with the ps command, like this:

ps auxwww | more

You can use the more command at the end of any Linux command pipeline, for example, something like this:

grep 'foo' myfile.txt | grep bar | more

The 'less' command


Most Unix and Linux systems also now include a less command. It works similarly to the more command, but has a few improved options. Check it out, or read the man (manual) pages for both commands to find out which one you prefer.

Sunday, 10 May 2020

The Unix/Linux lpstat command

Linux Tutorial and Material, Linux Certifications, Linux Study Materials, Linux Exam Prep

The Linux lpstat command lets you look at the progress of your print request(s). The name "lpstat" stands for "line printer statistics".

lpstat command examples


The "lpstat" command, used with no options, may return no output if there are no print jobs queued.

lpstat

It's generally better off to use an option with "lpstat". The "lpstat" command with the "-t" option gives you total information about the printer status. This option is generally the most useful, but the printout can be lengthy if you have a large number for printers configured.

lpstat -t

Linux Tutorial and Material, Linux Certifications, Linux Study Materials, Linux Exam Prep
To look at Linux printer queue information for a specific printer, use the -p option. Here's an example of looking at the long list of output information (-l option) for a printer named "Sales":

lpstat -p Sales -l

The -r option shows whether the print scheduler is currently on or off:

lpstat -r

Finally, the -u option shows print request status information for a given user. Here's what the command looks like when looking at the printer queue information for a user named "fred":

lpstat -u fred

Thursday, 7 May 2020

The Linux lp printing command

Linux Tutorial and Material, Linux Guides, Linux Certifications, LPI Study Materials, LPI Certification, LPI Exam Prep

The lp command is used to print files on Unix and Linux systems. The name "lp" stands for "line printer". As with most Unix commands there are a fairly large number of options available to enable flexible printing capabilities.

Let's look at some lp printing commands examples.

Linux lp printing command examples


lp /etc/passwd

This command prints the "/etc/passwd" file to the default printer. If you do not use the "-d" option, the file is printed to the default printer destination.

lp -dSales .profile

This command prints the ".profile" file to the printer named "Sales". The -d option specifies the destination.

lp -dSales file1 file2 file3

This command prints the three files "file1", "file2", and "file3" to the printer named "Sales".

lp -i Sales-101 -H hold

This command places the print request Sales-101 on hold.

lp -i Sales-101 -H resume

This command resumes the print request Sales-101. The print request starts printing from page one unless you instruct it otherwise.

lp -i Sales-101 -H resume -P 4-

This command resumes the print request Sales-101, starting with page 4 of the print job. Note that the final hyphen (following the "4") is required.

The "lp" command can also be used as part of a pipeline. For instance, the following command will print the output of the "ps -ef" command to the default printer:

ps -ef | lp

Print the output of the "ps -ef" command to the default printer.