Category Archives: Linux

Discover DevOps roles and learn Linux from basics to advanced at DevOpsRoles.com. Detailed guides and in-depth articles to master Linux for DevOps careers.

passwd command in Linux with Examples

command is a tool on Linux operating systems used to change a user’s password.

The passwd command in Linux is used to change a user’s password. It allows users to set or modify their own passwords or, if executed with root privileges, change the password for any user on the system.

passwd command in Linux with Examples

The syntax

passwd [options] [LOGIN]

In man page, the describe it

  • passwd – change user password
  • man passwd

passwd command in Linux with Examples

passwd huupv

To change another user’s password (as root):

sudo passwd <username>

Replace <username> with the username of the user whose password you want to change. Running the command with sudo and providing the username will prompt you to enter the new password for that user. Again, the characters won’t be displayed while typing.

It’s important to keep in mind that only the root user or users with appropriate privileges (e.g., members of the sudo group) can change other users’ passwords.

Additional options can be used with the passwd command to modify its behavior, such as:

  • -l or --lock: Locks the specified user account.
  • -u or --unlock: Unlocks the specified user account.
  • -S or --status: Shows the password status of the specified user account.

Conclusion

The passwd command is a simple command in Linux. It is the most popular in-use terminal Linux for changing passwords users. You can refer to the passwd command manual (man passwd) for more detailed information on its usage and available options. Thank you for reading the DevopsRoles page!

gzip command in Linux with Examples

gzip is a software application used for file compression and decompression. It is a common way of compressing files in Linux.

The gzip command in Linux is used to compress files. It reduces the size of a file or a group of files and creates a compressed file with the extension .gz.

Here are a few examples of how to use the gzip command:

The syntax gzip command

gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ...  ]

On the man page, the describes it

Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77).

gzip command in Linux with Examples

Creating a compressed file

[huupv@DevopsRoles ~]$ gzip filename.txt

Decompress a File Using the gzip Command

[huupv@DevopsRoles ~]$ gzip -d filename.gz

Decompress multiple compressed files

gzip -d file1.gz file2.gz file3.gz

The following details about gzip command in Linux.

man gzip

Compress multiple files

gzip file1 file2 file3

Keep the original file after compression or decompression

gzip -k filename
gzip -dk filename.gz

The -k option is used to keep the original file after compression or decompression. When compressing a file, the original file will be retained, and a compressed file will be created with the .gz extension. Similarly, when decompressing a file, the original compressed file will be retained, and a decompressed file will be created without the .gz extension.

Conclusion

gzip command is a simple command in Linux. It is the most popular in-use terminal Linux for file compression and

pwd command in Linux with Examples

command is the print working directory. It is one of the most frequently used Linux. like is cd or ls command.

The pwd command in Linux is used to print the current working directory. It displays the absolute path of the current directory where you are located within the file system.

The syntax pwd command

pwd [Option] ...

On the man page, the describes it

Print the full filename of the current working directory.

pwd command in Linux with Examples

The full PathName of the current working directory.

[huupv@DevopsRoles ~]$ cd /etc/nginx
[huupv@DevopsRoles nginx]$ pwd
/etc/nginx

Use the -P option to display the physical path:

pwd -P

Use the -L option to display the logical path:

pwd -L

Print the current directory with a symbolic link indicator:

pwd -P -L

By combining both the -P and -L options, the pwd the command will display the physical path and indicate any symbolic links present in the path.

Conclusion

These are some examples of using the pwd command in Linux. The command is useful for verifying your current directory or capturing it for use in shell scripts or other commands. pwd command is a simple command in Linux. It is the most popular in-use terminal Linux. Thank you for reading the DevopsRoles page!

Linux command tips and tricks

Introduction

In this tutorial, I system admin. Linux the essential for DevOps Roles.

Begin with an engaging introduction that explains the importance of mastering Linux commands for DevOps professionals. Highlight how these commands enhance productivity and streamline operations in a Linux environment.

Linux command tips and tricks

How to return to the previous directory

$ cd -

The display headers and footers in FileName.

$ cat filename | sed -e '$d' | awk 'NR > 1 {print}'

Search files under arbitrary directories

$ find ./ -name '*'|xargs grep 'devopsroles.com'

Empty the file.

$ cat /dev/null > filename.txt

Move to thereafter create the folder

$ mkdir dir_name ; cd $_

To count the number of files in any directory.

$ ls -F |grep -v / |wc -l

or count the number of folders in any directory.

$ ls -F |wc -l

Convert all extensions

$ for filename in *.txt; do mv $filename ${filename%.txt}.txt.old; done

To create serial number files.

$ touch foo_{1..4}.csv
$ touch {A..X}.csv

Delete “.DS_store” in bash

$ find . -name '.DS_Store' -type f -ls -delete

How to delete the last slash of the path.

$ MYDIR=${MYDIR%/}

Extract processes that use a lot of physical memory

$ ps aux | sort -n -k 6 | tail -n 10

Find processes with high CPU utilization

$ vmstat 1 | awk '{print strftime("%y/%m/%d %H:%M:%S"), $0}

lsof command list of ports in Listen

$ lsof -Pan -i tcp -i udp

Generate random passwords using the head command and tr command.

$ head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo ''

Extract a character string

$ echo 'devopsroles.com' | awk '{print substr($0, 2)}'

the mount command the display formatting with column

$ mount | column -t

To See CPU utilization per user

$ ps aux | awk  '{if (NR> 1) {p [$1] +=$3; n [$ 1] ++}} END {for (i in p) print p [i], n [i], i }'

How much RAM is installed on this system?

[huupv@huupv devopsroles]$ sudo dmidecode -t 17 | grep "Size.*MB" | awk '{s+=$2} END {print s / 1024 "GB"}'

Awk command line

Character count (wc – c)

$ awk '{n+=length($0)} END{print n}' filename

Word count (wc – w)

$ awk '{n+=NF} END{print n}' filename

Row count (wc – l)

$ awk 'END{print NR}' filename

Display from specified line to specified line

$ awk 'NR==3,NR==10'

Kill bulk by process name

$ kill $(ps aux | grep  "jenkins" | awk '{print $2;}')

Conclusion

Throughout this article, we’ve explored various Linux command tips and tricks. I hope you find these insights useful for your tasks. Thanks for visiting the DevopsRoles page.

How to install MySQL Server on Centos

In this tutorial, How to install MySQL Server on Centos/RedHat. The default local repository only supports MySQL packages including MySQL (replaced by Mariadb), Mongodb, so forth. In some cases, you need to install the correct MySQL Community server. I will point to a local repository dedicated to MySQL. Linux the essential for DevOps Roles.

My environment

  • Centos 7/6.
  • MySQL Version 8.

Install MySQL Server on CentOS 7

Step 1. Disable the current repository on Centos.

Failure to do this will result in conflicting package MongoDB on Epel repository. Install a package management software package:

$ sudo yum install yum-utils

Disable repository ‘remi- *’ and internet MongoDB package if pre-ordered:

$ sudo yum-config-manager --disable \*epel\*
$ sudo yum-config-manager --disable \*mongo\*

Step 2. Enable repository MySQL Server.

Create a “/etc/yum.repos.d/MySQL.repo” file with the content as below:

# Enable to use MySQL 5.5
[Local-mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/\$releasever/\$basearch/
enabled=0
gpgcheck=0

# Enable to use MySQL 5.6
[Local-mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/\$releasever/\$basearch/
enabled=0
gpgcheck=0

# Enable to use MySQL 5.7
[Local-mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/\$releasever/\$basearch/
enabled=0
gpgcheck=0

[Local-mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/\$releasever/\$basearch/
enabled=1
gpgcheck=0

[Local-mysql80-mysql-cluster-7.6-community]
name=MySQL cluster 7.6 community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/\$releasever/\$basearch/
enabled=1
gpgcheck=0

[Local-mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/\$basearch/
enabled=0
gpgcheck=0

[Local-mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/\$releasever/\$basearch/
enabled=1
gpgcheck=0

[Local-mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/\$releasever/\$basearch/
enabled=1
gpgcheck=0

[Local-mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/\$basearch/
enabled=1
gpgcheck=0

Install the MySQL Community Server package:

$ sudo yum install mysql-community-server

Install another library for MySQL Server  (if necessary)

Workbench

$ sudo yum install mysql-workbench-community

Shared client libraries

$ sudo yum install mysql-community-libs

MySQL Cluster server

$ sudo yum install mysql-cluster-community
$ sudo yum install mysql-cluster-community-management-server

Shell Tools

$ sudo yum install mysql-shell

Tools

$ sudo yum install mysql-utilities
$ sudo yum install mysql-router

Connector

$ sudo yum install mysql-connector-python
$ sudo yum install mysql-connector-odbc

Step 3. Disable MongoDB and Enable back the repository epel.

$ sudo yum-config-manager --enable \*epel\*
$ sudo yum-config-manager --disable \*mongo\*

To install MySQL Server another  version (Option)

MySQL versions other you can enable/disable in the directory: /etc/yum.repos.d/MySQL.repo

Disable the current MySQL version:

$ sudo yum-config-manager --disable Local-mysql\*-community

Enable MySQL version 5.6, type the command:

$ sudo yum-config-manager --enable Local-mysql56-community

Enable MySQL version 5.7, type the command:

$ sudo yum-config-manager --enable Local-mysql57-community

Checking the current MySQL version with the command:

$ sudo yum info mysql-community-server

Reference to  MySQL

Conclusion

Thought the article, You can “Install MySQL Server” as above. I hope will this your helpful.

How to install Mongodb on Centos/Redhat

In this tutorial,  How to install MongoDB on Centos. The Local Remi Repository only supports the old MongoDB packages by default. Need to upgrade to higher version need to point to the server of MongoDB. Linux the essential for DevOps Roles.

My environment

  • Centos 7/6, Redhat.
  • MongoDB Version 4.0

Install Mongodb on Centos/Redhat

Step 1. Disable the current Repository on Centos.

Failure to do this will result in conflicting package MongoDB on Epel Repository. Installing a package management software package:

$ sudo yum install yum-utils

Disable Repository ‘remi- *’ and internet MongoDB package if Pre-ordered:

$ sudo yum-config-manager --disable \*epel\*
$ sudo yum-config-manager --disable \*mongo\*

Step 2. Enable Repository MongoDB.

Creating a “/etc/yum.repos.d/mongodb.repo” file with the content as below

[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

Now, You can install MongoDB directly using yum

$ sudo yum install mongodb-org

The screen output terminal:

Step 3. To disable MongoDB and Enable back the repository epel.

$ sudo yum-config-manager --enable \*epel\*
$ sudo yum-config-manager --disable \*mongo\*

To check the MongoDB version

$ mongod --version

The screen output terminal:

Reference to Mongodb

Conclusion

Thought the article, You can “Install MongoDB” as above. I hope will this your helpful.

Complete Guide to Install Development Tools on CentOS

Introduction

This guide provides a comprehensive overview of installing essential development tools on CentOS. By using the yum groupinstall command, users can efficiently manage and install packages required for development, such as GNU GCC C/C++ compilers. This process is crucial for developers working in CentOS environments, aiming to streamline their setup and increase productivity.

In this tutorial, I used Centos “install development tools”.  The Ubuntu distribution install method is equivalent to “apt-get build-essential, while the Centos called groupinstall with yum command. How do I install all developer tools such as GNU GCC C/C++ compilers and others? You need to “install Development Tools“.

  • Development Tools for CentOS: Overview of tools and installation via Yum.
  • Development Tools for RHEL 7: Recommended tools and installation tips for Red Hat Enterprise Linux.
  • Development Tools for Ubuntu: Effective tools for Ubuntu and installation using apt-get.
  • Comparing Toolsets Across OS: Differences and similarities in toolkits across CentOS, RHEL 7, and Ubuntu.

How to Install Development Tools on Centos

For Centos, RHEL, and Fedora

Installing groupinstall use the yum command on Centos, RHEL, and Fedora.

[huupv@huupv devopsroles]$ sudo yum groupinstall "Development Tools"

The related with the subcommand  Group list

A list of groups uses “grouplist” command on Centos, RHEL, and Fedora.

[huupv@huupv devopsroles]$ sudo yum grouplist

To install a unit of a group name.

[huupv@huupv devopsroles]$ sudo yum groupinstall "Group name"

To remove a unit of a group using “groupremove” command on Centos, RHEL, and Fedora.

[huupv@huupv devopsroles]$ sudo yum groupremove "Group name"

Updating a unit of a group by “groupupdate” command on Centos, RHEL, and Fedora.

[huupv@huupv devopsroles]$ sudo yum groupupdate "Group name"

Conclusion

By following the steps outlined in this tutorial, users can successfully install all necessary development tools on CentOS, ensuring a robust environment for programming and development tasks.

This guide simplifies the process, making it accessible even for those new to Linux systems, ultimately enhancing their capabilities in handling various software development requirements. I hope will this your helpful. Thank you for reading the DevopsRoles page!

RPM query installed packages in Centos RHEL and Fedora

In this tutorial, I using the rpm command to query lists the packages installed on the system. How do I use “rpm query installed packages in Centos, RHEL, and Fedora“. Linux the essential for DevOps Roles.

RPM query installed packages

List of the only package installed your system.

$ rpm -qa --qf "%{NAME}\n"

Example, List of the package installed on “Server A”. After then, How to install the package from “Server A” for “Server B”

Server A $ rpm -qa --qf "%{NAME}\n" > packaged.list
Server B # xargs yum -y < packaged.list

Display the package names, versions and releases with this command

[huupv@huupv devopsroles]$ rpm -qa --qf '%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n'

The screen output terminal as below

Conclusion

Thought the article, How to use “RPM query installed packages in Centos RHEL and Fedora” as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

bad interpreter: /bin/sh^M: no such file or directory solve problem

In this tutorial, How to solve bad interpreter when running the shell exit with “bad interpreter: /bin/sh^M: no such file or directory“. I will be using three methods. Linux the essential for DevOps Roles.

bad interpreter: /bin/sh^M: no such file or directory fixed

Method 1: Using vim editor

Open vim and insert the following command

:set fileformat=unix
:x

Or

:set ff=unix
:x

Method 2: Using sed command

[huupv@huupv devopsroles]$ sed -i 's/\r//' FILE_NAME

Method 3: I Using dos2unix command

[huupv@huupv devopsroles]$ dos2unix FILE_NAME

Conclusion

Thought the article, You have solved the problem “bad interpreter: /bin/sh^M: no such file or directory” as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to kill specific processes in Linux

Introduction

This guide will walk you through how to kill specific processes in Linux, from basic commands to advanced techniques, with practical examples. Whether you’re new to Linux or looking to refine your skills, mastering these commands can save you time and enhance system stability.

Linux is a powerful and flexible operating system, used in a variety of environments, from personal desktops to complex server systems. One essential aspect of managing a Linux system effectively is understanding how to handle running processes, especially when they behave unexpectedly or consume too many resources.

Why Kill Processes in Linux?

Processes in Linux are essentially tasks or programs that are currently running on the system. Sometimes, these processes can become unresponsive, hog system resources, or even cause the system to crash. In such cases, killing the process becomes essential to free up resources and maintain the smooth operation of the system. This article provides a comprehensive look at various ways to kill processes based on different criteria, allowing you to manage your Linux system with greater efficiency.

How to View Running Processes

Before killing any process, it’s crucial to know how to view the processes running on your system. You can use several commands to list active processes.

Using ps

The ps command provides a static snapshot of all currently running processes:

ps aux
  • a: Shows processes for all users.
  • u: Displays processes in a user-oriented format.
  • x: Lists processes not connected to a terminal.

Using top and htop

The top and htop commands give a real-time view of running processes.

top

For a more user-friendly interface, install and use htop:

htop

kill specific processes in Linux

For example, kill all PID of the browser Firefox. But not kill line “grep –color=auto firefox” as the picture below

Use ps command with “-ef” option the display PID of browser Firefox.

[huupv@huupv devopsroles]$ ps -ef | grep firefox

The only display PID of Firefox as command below

[huupv@huupv devopsroles]$ ps -ef | grep firefox | grep -v "grep" | awk '{print $2}'

The screen output terminal as below

Using kill command to kill all Processes for Firefox as command line below

[huupv@huupv devopsroles]$ sudo kill -9 $(ps -ef | grep firefox | grep -v "grep" | awk '{print $2}')

Frequently Asked Questions (FAQ)

How do I kill a process without knowing its PID?

You can use pkill or killall to kill a process by name.

What’s the difference between kill and kill -9?

The default kill (SIGTERM) requests a graceful shutdown, while kill -9 (SIGKILL) forcefully stops the process.

Is there any risk in using kill -9?

kill -9 terminates a process immediately without cleanup, so unsaved data may be lost. Use it only when necessary.

How can I kill processes that belong to another user?

To kill processes owned by another user, you need root privileges. Use sudo pkill -u [username].

Why is xkill not working on my Linux distribution?

Some distributions don’t have xkill installed by default. You can install it using your package manager.

External Resources

Conclusion

Managing processes in Linux is a fundamental skill that improves your efficiency and control over the system. This guide has covered essential commands for killing specific processes, from using kill and pkill to more advanced techniques. Practice these commands to confidently handle any unresponsive or resource-consuming processes on your system. Remember to exercise caution, especially with kill -9, and ensure you understand the implications of terminating critical processes. By mastering these techniques, you’ll be better equipped to maintain a smooth-running Linux environment. Thank you for reading the DevopsRoles page!