Commands used to create a chat server and remove redundant software packages in Linux

Source: Internet
Author: User

Commands used to create a chat server and remove redundant software packages in Linux

Here, let's look at the next part of the Linux Command Line practical skills. If you miss the article before Linux Tracks, you can find it here.

  • Five interesting Linux Command Line skills

In this article, we will introduce six command line tips, including using the Netcat command to create a Linux Command Line chat and adding a column from the output of a command, remove unnecessary packages on Debian and CentOS, obtain local and remote IP addresses from the command line, and obtain color output and decoding from the terminal, finally, the use of the well number label in the Linux Command Line. Let's take a look at it one by one.

6 practical command line skills

 

1. Create a Linux Command Line chat service

We have been using the chat service for a long time. We are familiar with Google Chat, Hangout, Facebook Chat, Whatsapp, Hike, and other integrated Chat services. Then you know that the Linux nc command can turn your Linux machine into a chat server, but only one line of command is required. What is an nc command? How does it work?

Nc is the Linux netcat command. Like the Swiss Army knife, nc has many built-in functions. Nc can be used as a tuning tool, investigation tool, TCP/UDP read/write network connection, DNS forward/reverse query, and so on.

Nc is mainly used for port scanning, file transmission, backend and port listening. Nc can use any idle port and any local network source address.

Use the nc command (on the 192.168.0.7 server) to create a command line instant information transmission server.

  1. $ nc -l -vv -p 11119

The description of the preceding command.

  • -V: Display Redundancy Information
  • -Vv: displays more redundant information.
  • -P: local port number

You can replace 11119 with any other local port number.

Next, run the following command on the client machine (IP Address: 192.168.0.15) to initialize the chat session (the Information Server mentioned above is running ).

  1. $ nc 192.168.0.7:11119

Note: you can press ctrl + c to terminate the session, and nc chat is a one-to-one service.

 

2. How to count the total value of a column in Linux

How to count the sum of values in one of the output columns of a command on the terminal,

The output of the 'LS-l' command.

  1. $ ls -l

Note that the second column indicates the number of soft connections, and the fifth column indicates the file size. Suppose we need to summarize the values in the Fifth Column.

Only list the content in the Fifth Column. We will use the 'awk' command to do this. '$ 5' indicates the Fifth Column.

  1. $ ls -l | awk '{print $5}'

Now, use the MPs queue to print the sum of the values in the Fifth Column.

  1. $ ls -l | awk '{print $5}'| awk '{total = total + $1}END{print total}'

 

How to remove discarded packages in Linux

Deprecated packages are those installed as dependencies of other packages, but are no longer needed after the source package is removed.

Suppose we have installed a software package named gtprogram, which depends on gtdependency. Gtprogram cannot be installed unless gtdependency is installed.

When we remove the gtprogram, The gtdependency is not removed by default. If we do not remove the gtdependency, it will be left as an abandoned package and will not be associated with any other package.

  1. # yum autoremove [On RedHat Systems]

  1. # apt-get autoremove [On Debian Systems]

You should often remove discarded packages to ensure that Linux machines only load the required items.

 

4. How to obtain the local and public IP addresses of Linux servers

To obtain the local IP address, run the following script.

  1. $ ifconfig | grep "inet addr:"| awk '{print $2}'| grep -v '127.0.0.1'| cut -f2 -d:

You must install ifconfig. If not, use apt or yum to install the required package. Here, we will connect the ifconfig output in the pipeline and use the grep command to find the string containing "intel addr.

We know that the ifconfig command is enough for the output local IP address. However, ifconfig generates a lot of output, and we only focus on local IP addresses, not others.

  1. # ifconfig | grep "inet addr:"

Although the current output is much better, we need to filter out the local IP address, excluding other items. For this purpose, we will use awk to print the second output column and connect the above script through the pipeline.

  1. # ifconfig | grep “inet addr:” | awk '{print $2}'

The image above clearly indicates that we have already customized the output to a large extent, but it is still not what we want. The local loop address 127.0.0.1 is still in the result.

We can use the-v option of grep to print other rows that do not match the given parameter. Each machine has the same loop address 127.0.0.1. Therefore, use grep-v to print the line that does not contain 127.0.0.1 and connect the preceding script through the pipeline.

  1. # ifconfig | grep "inet addr" | awk '{print $2}' | grep -v '127.0.0.1'

We almost got the desired output. We just need to replace the string from the beginning.(addr:). We will use the cut command to print the second column separately. One or two columns are not separated by tab,(:)So we need to use the domain delimiter Option(-d), Connect the above output through the pipeline.

  1. # ifconfig | grep "inet addr:" | awk '{print $2}' | grep -v '127.0.0.1' | cut -f2 -d:

Last! The expected result is displayed.

 

5. How to output color data on Linux Terminals

You may have seen the color output on the terminal. At the same time, you may also know how to allow/disable color output in the terminal. If you do not know, you can refer to the following steps.

In Linux, every user has'.bashrc'File, used to manage your terminal output. Open and edit the file in your favorite editor. Note that this file is hidden (the file starts with a dot and represents a hidden file ).

  1. $ vi /home/$USER/.bashrc

Make sure that the following rows are not commented out. That is, there is no # At the beginning of the line #.

  1. if[-x /usr/bin/dircolors ];then
  2. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dirc$
  3. alias ls='ls --color=auto'
  4. #alias dir='dir --color=auto'
  5. #alias vdir='vdir --color=auto'
  6. alias grep='grep --color=auto'
  7. alias fgrep='fgrep --color=auto'
  8. alias egrep='egrep --color=auto'
  9. fi

After that! Save and exit. To make the change take effect, you need to cancel the account and log on again.

Now, you will see that the listed files and folder names have different colors, depending on the file type. To understand the color code, run the following command.

  1. $ dircolors -p | less

 

6. How to mark Linux commands and scripts #

We have been using the # tag on Twitter, Facebook, and Google Plus (maybe something we didn't mention. Those # tags make it easier for others to search for a tag. But few people know that we can use the # label in the Linux Command Line.

We already know#In most programming languages, this symbol is used as a comment line, that is, it is not executed.

Run a command and create a # label for the command. Then we can find it. Suppose we have a very long script, that is, the Command executed at the fourth point above. Create a # label for it. We know that ifconfig can be executed by sudo or root, so it is executed by root.

  1. # ifconfig | grep "inet addr:" | awk '{print $2}' | grep -v '127.0.0.1' | cut -f2 -d: #myip

The above script is marked by 'myip. Search for this tag in reverse-I-search (press ctrl + r), enter 'myip' in the terminal '. You can start execution from here.

You can create a # label for each command and use reverse-I-search to find it.

So much now. We have been working hard to create interesting and knowledgeable content for you. How do you think we work? Please contact us for any questions. You can comment below. Keep in touch! Kudox.

Via: http://www.tecmint.com/linux-commandline-chat-server-and-remove-unwanted-packages/

Author: Avishek Kumar Translator: wi-cuckoo Proofreader: wxy

This article was originally translated by LCTT and launched with the Linux honor in China

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.