How-to articles, tricks, and solutions about Linux

Linux LSOF Command - Explained with Examples

This article covers the usage of the LSOF command in Linux. In fact, With lsof, you can find different processes locking up a file or directory, a process listening on a port, a user's process list, what all files a process is locking.

How to install lsof in Linux ?

lsof isn't available by default on most Linux distributions but can be easily installed. So Use the below command to install lsof:

1. For CentOS / RHEL / Fedora, run the below command:

$ sudo yum install lsof

2. For CentOS/RHEL 8, you can use the DNF command:

$ sudo dnf install lsof

3. For Ubuntu / Debian, run the below command:

$ sudo apt install lsof

How to get lsof supported options ? 

You can get a summarized list of lsof supported options using -? or -h flag:

$ lsof -?

LVEXTEND Command in Linux - Explained with Examples ?

This article covers how to extend LVM partition on the fly using lvextend command. In fact, LVM(Logical Volume Manager) provides the facility to increase and reduce the file system size. 

PASSWD Command in Linux - Explained with Examples

This article covers an overview of how to use the PASSWD command in Linux. In fact, The passwd command modifies passwords for user accounts and manages the password validity period.

What is the general command for passwd ?

passwd general command is:

$ passwd <options> <username>

The terminal prints out what user you are changing the password for. Type your current password, and then define and confirm your new password.

Replace a String in a File Using Ansible

This article covers the usage of the 'replace' module in Ansible for replacing a string in a file. In fact, Ansible provide multiple ways that you can use to replace a string, an entire line or words that match a certain pattern. There are two modules that you can use to achieve this: the replace module and the inline module. 

Rsync Command Options - Explained with Examples

This article covers a few options of the RSYNC command along with a few examples that elaborated on the usage of this command. In fact, with rsync, you will be able to use this tool very efficiently for transferring data from one location to another.

What is the Rsync Command Syntax ?

The syntax for the rsync command changes depending on the usage of the tool. We will cover all the scenarios in the following examples. Rsync syntax in its most basic form looks like this:

$ rsync options SOURCE DESTINATION

Remote data transfers require you to specify a host's address, but more on that later.

What are Rsync Command Options ?

The rsync tool comes with many options. You can enter rsync in your terminal and get all the details. We will list some of the most common rsync options:

  • -r Allows to sync data recursively but does not keep ownership for users and groups, permissions, timestamps, or symbolic links.
  • -a The archive mode behaves like the recursive mode but keeps all file permissions, symbolic links, file ownership, etc.
  • -z Used to compress data during transfers to save space.
  • -b Performs a backup during data synchronization.
  • -h Shows the numbers in the output in a human-readable format.
  • -n Does a dry run. Used for testing before the actual synchronization takes place.
  • -e Instructs the rsync to use the SSH protocol for remote transfers.
  • -progress Displays the transfer progress during synchronization.
  • -v Verbose output. Displays the details of the transfer.
  • -q Used to suppress the output for the rsync command and options.

Execute Remote Command with SSH

This article covers the process of running a remote command with SSH on a Linux system along with actually running a command remotely. In fact, you will be able to run any command on a remote system of your choice provided that you know the correct username of that system as well as its password with which you will be able to access it remotely.