Deleting files using find

We will learn how to delete files using command find from given folder.

Suppose you want to delete .png files from /home/directory.

Use following command

find /home/directory/ \( -name "*.png" \) -type f -exec rm {} +

This will delete file with extension .png from /home/directory and sub directories of /home/directory like *.png files from /home/directory/directory2/ as well .

But suppose if you need to delete .png files only from directory /home/directory and not from sub directories then use following command.

find /home/directory/ -maxdepth 1  \( -name "*.png" \) -type f -exec rm {} +

Install MongoDB on Ubuntu 18.04

How Install MongoDB on Ubuntu 18.04..

What is MongoDB ?

MongoDB is a free and open-source NoSQL document database which uses JSON-like documents with schemata. It means fields can vary from document to document and data structure can be changed over time.

In this tutorial we will learn how to install MongoDB, manage MongoDB service, and enable remote access.

First we will update package list so we will have more recent repository version listing.

Command to update package list on Ubuntu 18.04 is

apt update

Now install MongoDB using command

apt install mongodb -y

This command will install latest version of mongodb on your server along with management tools required for mongodb server.

Let’s check status of mongodb service installed using command

systemctl status mongodb

If you see active running then it is up and running.

We will execute further command to connect mongodb server

mongo --eval 'db.runCommand({ connectionStatus: 1 })'

Above command will provide version of mongodb server as output.

Output should be like:

MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
{
        "authInfo" : {
                "authenticatedUsers" : [ ],
                "authenticatedUserRoles" : [ ]
        },
        "ok" : 1
}

Here ok: 1 means service mongodb is ready to use.

Below are command to start, stop, restart.

systemctl start mongodb

systemctl stop mongodb

systemctl restart mongodb

By default it is enabled for onboot start. Command to disable/enable ie. to disable automatic start on server boot is

systemctl disable mongodb

To enable automatic start of mongodb server on server boot is

systemctl enable mongodb

Port used by mongodb server is 27017. You need to open this port in firewall if you want to allow access to this server from remote server.

Once you open port you will need to define IP of remote server in mongodb configuration.

vi /etc/mongodb.conf

find line starting with word bind_ip and then add all remote server IPs and separate them by comma for example to allow IPs 10.0.0.1 and 10.0.0.2.

Change line
bind_ip = 127.0.0.1
To
bind_ip = 127.0.0.1, 10.0.0.1, 10.0.0.2

Save file and restart mongodb service.

systemctl restart mongodb.

 

Install-gcc-gnu-c-c-compiler-linux

If you are getting errors like missing of GNU C / C++ compiler on server. To fix you just need to install with help of Linux package installer like YUM, Apt-get etc.

Installation of GNU C / C++ compiler on CentOS

Use following command

yum install gcc gcc-c++ autoconf automake

Installation of GNU C / C++ compiler on Ubuntu/Debian

Here, you can use apt-get command instead of YUM.

 sudo apt-get install build-essential 

On ubuntu for installing gcc and g++ compilers, you just need to install build-essential package. This will also install GNU make.

build-essential contains a list of packages which are essential for building Ubuntu packages including gcc compiler, make and other required tools.