How-to articles, tricks, and solutions about Linux

TAR Command Options in Linux - Explained with Examples

This article covers the usage of the TAR command in Linux. In fact, the GNU tar (short for Tape ARchiver) command is the most widely used archiving utility in Linux systems. Available directly in the terminal, the tar command helps create, extract, and list archive contents.

How to tar a file in Linux using command line ?

  • Open the terminal app in Linux.
  • Compress an entire directory by running tar -zcvf file.tar.gz /path/to/dir/ command in Linux.
  • To compress a single file by running tar -zcvf file.tar.gz /path/to/filename command on Linux.
  • Tar and compress multiple directories file by running tar -zcvf file.tar.gz dir1 dir2 dir3 command in Linux.

Ansible "Debug" Module - Explained with Examples with Ubuntu

This article covers how to use the "debug" module with some examples. In fact, the Ansible "debug" module is very useful for actively debugging operations as we seen in the given examples. It is equally helpful for getting a verbose output from a playbook.

How do Ansible Debug works ?

  • msg: – This parameter accepts strings as inputs. This is used to print a customized message. If no message is given, then a generic message like “Hello World!” is
  • var: – This accepts strings as input and this is the variable that has been set either by Ansible facts or by the playbook. Also, the values written here will be having implicit double interpolation, as this option runs in the jinja2 context. So, you don’t need to use jinja2 delimiter unless you want to print double interpolation as well. You can use double interpolation when you print a variable in a
  • verbosity: – This has default as 0. This parameter is used to control when debug is in a run. For example if value 3 is given then debug will only run if -v or above is given while running the playbook.

Working with Variables in Ansible running Ubuntu 22.04 (Jammy Jellyfish)

This article covers the various types of variables used in Ansible. In fact, they are very useful for increasing the flexibility and comprehensibility of a code when used in an appropriate manner.

Basically, The use of variables simplifies the management of dynamic values throughout an Ansible project and can potentially reduce the number of human errors. 

Different types of variables in Ansible:
  • Global: this is set by config, environment variables and the command line. 
  • Play: each play and contained structures, vars entries, include_vars, role defaults and vars. 
  • Host: variables directly associated to a host, like inventory, facts or registered task outputs.

Fix Inactive UFW Status on Ubuntu 22.04 (Jammy Jellyfish)

This article covers how you can easily activate the Firewall status on Ubuntu system and protect it from almost all the potential threats and attacks. In fact, The Uncomplicated Firewall (ufw) is a frontend for iptables and is particularly well-suited for host-based firewalls. ufw provides a framework for managing netfilter, as well as a command-line interface for manipulating the firewall.

How to enable UFW status on Ubuntu ?

To enable UFW, run the below command: 

$ sudo ufw enable

How to Open SSH TCP port 22 connections ?

1. We can easily open SSH TCP port 22 using UFW as follows:

$ sudo ufw allow ssh

2. If you are running ssh on TCP port 2222 or TCP port 2323, run:

$ sudo ufw allow 2222/tcp
$ sudo ufw allow 2323/tcp

Run Background Process in Ubuntu 22.04 (Jammy Jellyfish) Linux system

This article covers the ways of sending a process to the background in Ubuntu Linux system. In fact, a background process is a process/command that is started from a terminal and runs in the background, without interaction from the user.

Commands to find out what processes are running in the background ?

  • ps command - You can use the ps command to list all background process in Linux. Other Linux commands to obtain what processes are running in the background on Linux.
  • top command – Display your Linux server's resource usage and see the processes that are eating up most system resources such as memory, CPU, disk and more.
  • htop command – Just like a top command but with an improved user interface.