Posts

Showing posts with the label Linux

Featured Post

15 Python Tips : How to Write Code Effectively

Image
 Here are some Python tips to keep in mind that will help you write clean, efficient, and bug-free code.     Python Tips for Effective Coding 1. Code Readability and PEP 8  Always aim for clean and readable code by following PEP 8 guidelines.  Use meaningful variable names, avoid excessively long lines (stick to 79 characters), and organize imports properly. 2. Use List Comprehensions List comprehensions are concise and often faster than regular for-loops. Example: squares = [x**2 for x in range(10)] instead of creating an empty list and appending each square value. 3. Take Advantage of Python’s Built-in Libraries  Libraries like itertools, collections, math, and datetime provide powerful functions and data structures that can simplify your code.   For example, collections.Counter can quickly count elements in a list, and itertools.chain can flatten nested lists. 4. Use enumerate Instead of Range     When you need both the index and the value in a loop, enumerate is a more Pyth

Tail Command in Linux: A Comprehensive Overview

Image
The tail in Linux is handy command. You can check the last lines of a file in Linux/Unix operating systems. You can use it to display last lines from single file, display last lines from multiple files, display the last entries of log files. Tail Command in Linux During production support the usage of Tail command is helpful since you can check latest logs quickly. Here are the top Tail command examples. #1 Display last lines in a file (Tail file Linux) Here's the tail command that shows last three lines of a file. cat sample.txt | tail -3 It displays last 3 lines of a file. The same command you can use as tail -3 sample.txt #2 Display last lines of multiple files There are three files. sample2.txt, sample3.txt, sample4.txt. The command displays the last 3 lines from all the three files. tail -3 sample[2-4].txt #3 Tail -f option (Tail f Linux) The –f option is to check status of long-running process that is redirecting output to a file. For example, if you invoke the below command

How to Configure Firewall For an Application

Image
A firewall is a set of rules. When a data packet moves into or out of protected network space, its contents (in particular, information about its origin, its target, and the protocol it plans to use) are tested against the firewall rules to see if it should be allowed through. How a Firewall concept works Let's say that the web server has to be open to incoming web traffic from anywhere on earth using either the insecure HTTP or secure HTTPS protocol. Because your developers and admins will need to get into the backend from time to time to do their work, you’ll also want to allow SSH traffic, but only for those people who’ll need it. Requests for any other services should be automatically refused. A Linux machine can be configured to apply firewall rules at the kernel level through a program called iptables. Creating table rules isn't all that difficult; the syntax can be learned without too much fuss. But, in the interest of simplifying your life, many Linux distributions ha

How to Send Shell script Result to Email

Image
The shell-script result you can send to email. Below, you will find the steps you need to do it. There are two steps and both will help you know the entire process. Sending shell-script results to email Creating shell-script Sending the result to email 1. Creating shell-script Create an empty script Create test1.sh script using the vi command with the Sudo command. $sudo vi test1.sh Write the first line in the script #!/bin/bash exec > out1.txt 2>&1 Add logic in the shell script #!/bin/bash exec > out1.txt 2>&1 echo" Here is my logic" Provide executable permissions to your script $ sudo chmod +x test1.sh Run your script using the command below $ ./test1.sh Verify the output $ cat out1.txt 2. Sending result to email Use the below command to send the output (result) to email. $ mail <<output file path name>> abc@gmail.com Bottom-line These steps are helpful to send the output to an email.  References How to Install Mailx Utility in Linux

The Real Command to Wrap Text in Linux

Image
Here is a command to wrap text in Linux. The wrapping means it prints it in fixed-width column. More importantly, it will not consider spaces between words. The command you need is FOLD.   Fold command in Linux Below, you will find two examples on usage of the FOLD command. These are helpful for your project where you need to write a shell script. Example-1 The following command displays a set of lines with ten characters in each line: x="aa bb cc d e f g h i j kk ll mm nn"  echo $x | fold -10 The output of the preceding code snippet is here: aa bb cc d e f g h i j kk ll m m nn ✏Related: How to Write Recursive Shell Script in Bash Terminal Example-2 As another example, consider the following code snippet: x="The quick brown fox jumps over the fat lazy dog. "  echo $x | fold -10 The output of the preceding code snippet is here: The quick brown fox jumps over the fat l azy dog. ✏References: List of complete ls commands in Linux Keep reading How to Work with Linux

How to Understand the 'ps' Command output in Linux

Image
You can get process details by using the ps command. Those are number of processes running in a current Session, and other parameters about the process.   Here is all about how to use ps command in Linux. How to use ps command Here's an example that is how it appears when you issue the 'ps' command. PID (Process Id) - It is the process identification number. TTY(Terminal name) - associated with this process TIME(Time) - the format is hh: mm: ss (Hours, Minutes, and Seconds). Cumulated time of that particular process. CMD (Executable Command name). You May Also Like: PS Command Options in Linux How to understand slave/master terminal Here is all about Slave and Master terminal. The pts/0 is the slave terminal. The pts means pseudo terminal slave. Raise your knowledge by bringing in these quick definitions. LINUX - DIFFERENCE BETWEEN TTY AND PTS. In reality, the terminals are two types. One is ptmx (Master) and pts (Slave). The master terminal holds the details of slaves. Tho

Relative Vs. Absolute Path in Linux: Top Differences

Image
 Here's the difference between the relative and absolute paths in Linux. Many a time, the programmer needs to trade in these paths. Here're simple ideas on how you can differentiate. Absolute Vs. Relative path These are the differences between Absolute and Relative path in Linux. Absolute Path $ cd /usr/lib $ cd /usr/lib pwd See this path (linux#1/usr/lib), when you give PWD, it gives a full path from the root level. This is called absolute or full path. Think of the absolute pathname as being the complete mailing address for a package that the postal service will deliver to your next-door neighbor. Relative Path $ cd usr $ /user cd lib $ /usr/lib pwd $ linux#1/usr/lib ==> Going step by step and achieving. $ linux#1/usr/lib cd ../../ ==> This is the method of going back step by step. $ linux#1 ==> This is root level directory You are currently in the lib directory. So relative path nothing but complete information of all the mother directories. Here, for lib, th

10 Top Differences Between Unix and Linux

UNIX It is an operating system which was first developed in the 1960s and has been under constant development ever since. By operating system, we mean the suite of programs which make the computer work. It is a stable, multi-user, multi-tasking system for servers, desktops, and laptops. UNIX systems also have a graphical user interface (GUI) similar to Microsoft Windows which provides an easy to use environment. However, knowledge of UNIX is required for operations which aren't covered by a graphical program, or for when there is no windows interface available, for example, in a telnet session. The kernel - The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls. As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the file myfile). The shell searches the filestore for the file c

Linux Must Read Course Contents

Image
The complete syllabus for the Linux certification course you need to know before start preparation for the test. List of Course Contents The Linux community and a career in open source Finding your way on a Linux system The power of the command line The Linux operating system Security and file permissions Topic 1: The Linux Community and a Career in Open Source (weight: 7) 1.1 Linux Evolution and Popular Operating Systems Weight: 2 Description: Knowledge of Linux development and major distributions. Key Knowledge Areas: Open Source Philosophy Distributions Embedded Systems The following is a partial list of the used files, terms and utilities: Android Debian, Ubuntu (LTS) CentOS, openSUSE, Red Hat Linux Mint, Scientific Linux 1.2 Major Open Source Applications Weight: 2 Description: Awareness of major applications as well as their uses and development. Key Knowledge Areas: Desktop Applications Server Applications Development Languages Package Management

How Linux is Most Popular Operating System

Image
#Why-linux is most popular-operating system Today more than 97 percent of the world's supercomputers (including the complete top 10), more than 80 percent of all smartphones, many millions of desktop computers, around 70 percent of all web servers, a large chunk of tablet computers, and several appliances (dvdplayers, washing machines, dsl modems, routers, self-driving cars, space station laptops...) run Linux.  Linux is by far the most commonly used operating system in the world.  Linux kernel version 4.0 was released in April 2015. Its source code grew by several hundred thousand lines (compared to version 3.19 from February 2015) thanks to contributions of thousands of developers paid by hundreds of commercial companies including Red Hat, Intel, Samsung, Broadcom, Texas Instruments, IBM, Novell, Qualcomm, Nokia, Oracle, Google, AMD and even Microsoft. What is Linux Distribution A Linux distribution is a collection of (usually open source) software on top of a Linux ke

The Linux Commands List That Give Deep Insights on Usage

Here is the list of Linux commands, which explains all the daily-use commands. And each command has showed with an example so you can get deep insights quickly. List of Linux commands 1. What is a command shell? A program that interprets commands Allows a user to execute commands by typing them manually at a terminal, or automatically in programs called shell scripts. A shell is not an operating system. It is a way to interface with the operating system and run commands. 2. What is BASH? BASH = Bourne Again Shell Bash is a shell written as a free replacement to the standard Bourne Shell (/bin/sh) originally written by Steve Bourne for UNIX systems. It has all of the features of the original Bourne Shell, plus additions that make it easier to program with and use from the command line. Since it is Free Software, it has been adopted as the default shell on most Linux systems. 3. How is BASH different from the DOS command prompt? Case Sensitivity: In Linux/UNIX, commands and filenames are