{"id":12709,"date":"2019-03-28T14:13:19","date_gmt":"2019-03-28T14:13:19","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12709"},"modified":"2019-03-28T14:13:19","modified_gmt":"2019-03-28T14:13:19","slug":"useful-commands-to-create-commandline-chat-server-and-remove-unwanted-packages-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/useful-commands-to-create-commandline-chat-server-and-remove-unwanted-packages-in-linux\/","title":{"rendered":"Useful Commands to Create Commandline Chat Server and Remove Unwanted Packages in Linux"},"content":{"rendered":"<p>Here we are with the next part of Linux Command Line Tips and Tricks. If you missed our previous post on Linux Tricks you may find it here.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/5-linux-command-line-tricks\/\" target=\"_blank\" rel=\"noopener\">5 Linux Command Line Tricks<\/a><\/li>\n<\/ol>\n<p>In this post we will be introducing\u00a0<strong>6 command Line tips<\/strong>\u00a0namely create Linux Command line chat using\u00a0<strong>Netcat<\/strong>command, perform addition of a column on the fly from the output of a command, remove orphan packages from Debian and CentOS, get local and remote IP from command Line, get colored output in terminal and decode various color code and last but not the least hash tags implementation in Linux command Line. Lets check them one by one.<\/p>\n<div id=\"attachment_13180\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/linux-commandline-chat-server.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-13180\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/linux-commandline-chat-server-620x297.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/linux-commandline-chat-server-620x297.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/linux-commandline-chat-server.jpg 720w\" alt=\"Linux Commandline Chat Server\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-13180\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-13180\" class=\"wp-caption-text\">6 Useful Commandline Tricks and Tips<\/p>\n<\/div>\n<h3>1. Create Linux Commandline Chat Server<\/h3>\n<p>We all have been using chat service since a long time. We are familiar with Google chat, Hangout, Facebook chat, Whatsapp, Hike and several other application and integrated chat services. Do you know Linux\u00a0<strong>nc<\/strong>command can make your Linux box a chat server with just one line of command.<\/p>\n<h6>What is nc command in Linux and what it does?<\/h6>\n<p><strong>nc<\/strong>\u00a0is the depreciation of Linux\u00a0<strong>netcat<\/strong>\u00a0command. The\u00a0<strong>nc<\/strong>\u00a0utility is often referred as Swiss army knife based upon the number of its built-in capabilities. It is used as debugging tool, investigation tool, reading and writing to network connection using TCP\/UDP, DNS forward\/reverse checking.<\/p>\n<p>It is prominently used for port scanning, file transferring, backdoor and port listening. nc has the ability to use any local unused port and any local network source address.<\/p>\n<p>Use\u00a0<strong>nc<\/strong>\u00a0command (On Server with IP address:\u00a0<strong>192.168.0.7<\/strong>) to create a command line messaging server instantly.<\/p>\n<pre>$ nc -l -vv -p 11119\r\n<\/pre>\n<p>Explanation of the above command switches.<\/p>\n<ol>\n<li><strong>-v<\/strong>\u00a0: means Verbose<\/li>\n<li><strong>-vv<\/strong>\u00a0: more verbose<\/li>\n<li><strong>-p<\/strong>\u00a0: The local port Number<\/li>\n<\/ol>\n<p>You may replace\u00a0<strong>11119<\/strong>\u00a0with any other local port number.<\/p>\n<p>Next on the client machine (IP address: 192.168.0.15) run the following command to initialize chat session to machine (where messaging server is running).<\/p>\n<pre>$ nc 192.168.0.7 11119\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Chat-on-Linux-Commandline.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13146\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Chat-on-Linux-Commandline.gif\" alt=\"Linux Commandline Chat with nc Command\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p><strong>Note:<\/strong>\u00a0You can terminate chat session by hitting\u00a0<strong>ctrl+c<\/strong>\u00a0key and also nc chat is one-to-one service.<\/p>\n<h3>2. How to Sum Values in a Column in Linux<\/h3>\n<p>How to sum the numerical values of a column, generated as an output of a command, on the fly in the terminal.<\/p>\n<p>The output of the \u2018<strong>ls -l<\/strong>\u2018 command.<\/p>\n<pre>$ ls -l\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Sum-Values.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13150\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Sum-Values.gif\" alt=\"Sum Numerical Values\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Notice that the second column is numerical which represents number of symbolic links and the\u00a0<strong>5th<\/strong>\u00a0column is numerical which represents the size of he file. Say we need to sum the values of fifth column on the fly.<\/p>\n<p>List the content of\u00a0<strong>5th<\/strong>\u00a0column without printing anything else. We will be using \u2018<strong>awk<\/strong>\u2018 command to do this. \u2018<strong>$5<\/strong>\u2018 represents\u00a0<strong>5th<\/strong>\u00a0column.<\/p>\n<pre>$ ls -l | awk '{print $5}'\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/List-Content-Column.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13151\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/List-Content-Column.gif\" alt=\"List Content Column\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Now use\u00a0<strong>awk<\/strong>\u00a0to print the sum of the output of\u00a0<strong>5th<\/strong>\u00a0column by pipelining it.<\/p>\n<pre>$ ls -l | awk '{print $5}' | awk '{total = total + $1}END{print total}'\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Sum-Columns.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13152\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Sum-Columns.gif\" alt=\"Sum and Print Columns\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<h3>How to Remove Orphan Packages in Linux?<\/h3>\n<p><strong>Orphan<\/strong>\u00a0packages are those packages that are installed as a dependency of another package and no longer required when the original package is removed.<\/p>\n<p>Say we installed a package\u00a0<strong>gtprogram<\/strong>\u00a0which was dependent of\u00a0<strong>gtdependency<\/strong>. We can\u2019t install\u00a0<strong>gtprogram<\/strong>unless\u00a0<strong>gtdependency<\/strong>\u00a0is installed.<\/p>\n<p>When we remove\u00a0<strong>gtprogram<\/strong>\u00a0it won\u2019t remove\u00a0<strong>gtdependency<\/strong>\u00a0by default. And if we don\u2019t remove\u00a0<strong>gtdependency<\/strong>, it will remain as Orpahn Package with no connection to any other package.<\/p>\n<pre># yum autoremove                [On RedHat Systems]\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Remove-Orphan-Packages-in-CentOS1.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13159\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Remove-Orphan-Packages-in-CentOS1.gif\" alt=\"Remove Orphan Packages in CentOS\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<pre># apt-get autoremove                [On Debian Systems]\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Remove-Orphan-Packages-in-Debian.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13155\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Remove-Orphan-Packages-in-Debian.gif\" alt=\"Remove Orphan Packages in Debian\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>You should always remove Orphan Packages to keep the Linux box loaded with just necessary stuff and nothing else.<\/p>\n<h3>4. How to Get Local and Public IP Address of Linux Server<\/h3>\n<p>To get you local IP address run the below one liner script.<\/p>\n<pre>$ ifconfig | grep \"inet addr:\" | awk '{print $2}' | grep -v '127.0.0.1' | cut -f2 -d:\r\n<\/pre>\n<p>You must have installed\u00a0<strong>ifconfig<\/strong>, if not,\u00a0<strong>apt<\/strong>\u00a0or\u00a0<strong>yum<\/strong>\u00a0the required packages. Here we will be pipelining the output of\u00a0<strong>ifconfig<\/strong>\u00a0with\u00a0<strong>grep<\/strong>\u00a0command to find the string \u201c<strong>intel addr:<\/strong>\u201d.<\/p>\n<p>We know\u00a0<strong>ifconfig<\/strong>\u00a0command is sufficient to output local IP Address. But\u00a0<strong>ifconfig<\/strong>\u00a0generate lots of other outputs and our concern here is to generate only local IP address and nothing else.<\/p>\n<pre># ifconfig | grep \"inet addr:\"\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Check-Local-IP-Address.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13160\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Check-Local-IP-Address.gif\" alt=\"Check Local IP Address\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Although the output is more custom now, but we need to filter our local IP address only and nothing else. For this we will use awk to print the second column only by pipelining it with the above script.<\/p>\n<pre># ifconfig | grep \u201cinet addr:\u201d | awk '{print $2}'\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Filter-IP-Address.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13161\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Filter-IP-Address.gif\" alt=\"Filter Only IP Address\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Clear from the above image that we have customised the output very much but still not what we want. The loopback address\u00a0<strong>127.0.0.1<\/strong>\u00a0is still there in the result.<\/p>\n<p>We use use\u00a0<strong>-v<\/strong>\u00a0flag with\u00a0<strong>grep<\/strong>\u00a0that will print only those lines that don\u2019t match the one provided in argument. Every machine have the same\u00a0<strong>loopback address 127.0.0.1<\/strong>, so use\u00a0<strong>grep -v<\/strong>\u00a0to print those lines that don\u2019t have this string, by pipelining it with above output.<\/p>\n<pre># ifconfig | grep \"inet addr\" | awk '{print $2}' | grep -v '127.0.0.1'\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Print-IP-Address.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13162\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Print-IP-Address.gif\" alt=\"Print IP Address\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>We have almost generated desired output, just replace the string\u00a0<code>(addr:)<\/code>\u00a0from the beginning. We will use\u00a0<strong>cut<\/strong>command to print only column two. The\u00a0<strong>column 1<\/strong>\u00a0and\u00a0<strong>column 2<\/strong>\u00a0are not separated by tab but by\u00a0<code>(:)<\/code>, so we need to use delimiter\u00a0<code>(-d)<\/code>\u00a0by pipelining the above output.<\/p>\n<pre># ifconfig | grep \"inet addr:\" | awk '{print $2}' | grep -v '127.0.0.1' | cut -f2 -d:\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Custome-IP-Address.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13163\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Custome-IP-Address.gif\" alt=\"Customized IP Address\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Finally! The desired result has been generated.<\/p>\n<h3>5. How to Color Linux Terminal<\/h3>\n<p>You might have seen colored output in terminal. Also you would be knowing to enable\/disable colored output in terminal. If not you may follow the below steps.<\/p>\n<p>In Linux every user has\u00a0<code>'.bashrc'<\/code>\u00a0file, this file is used to handle your terminal output. Open and edit this file with your choice of editor. Note that, this file is hidden (dot beginning of file means hidden).<\/p>\n<pre>$ vi \/home\/$USER\/.bashrc\r\n<\/pre>\n<p>Make sure that the following lines below are uncommented. ie., it don\u2019t start with a\u00a0<strong>#<\/strong>.<\/p>\n<pre>if [ -x \/usr\/bin\/dircolors ]; then\r\n    test -r ~\/.dircolors &amp;&amp; eval \"$(dircolors -b ~\/.dircolors)\" || eval \"$(dirc$\r\n    alias ls='ls --color=auto'\r\n    #alias dir='dir --color=auto'\r\n    #alias vdir='vdir --color=auto'\r\n\r\n    alias grep='grep --color=auto'\r\n    alias fgrep='fgrep --color=auto'\r\n    alias egrep='egrep --color=auto'\r\nfi<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/bashrc-file.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13164\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/bashrc-file.gif\" alt=\"User .bashrc File\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Once done! Save and exit. To make the changes taken into effect logout and again login.<\/p>\n<p>Now you will see files and folders are listed in various colors based upon type of file. To decode the color code run the below command.<\/p>\n<pre>$ dircolors -p\r\n<\/pre>\n<p>Since the output is too long, lets pipeline the output with less command so that we get output one screen at a time.<\/p>\n<pre>$ dircolors -p | less\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Linux-Color-Output.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13165\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Linux-Color-Output.gif\" alt=\"Linux Color Output\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<h3>6. How to Hash Tag Linux Commands and Scripts<\/h3>\n<p>We are using hash tags on\u00a0<strong>Twitter<\/strong>,\u00a0<strong>Facebook<\/strong>\u00a0and\u00a0<strong>Google Plus<\/strong>\u00a0(may be some other places, I have not noticed). These hash tags make it easier for others to search for a hash tag. Very few know that we can use hash tag in Linux command Line.<\/p>\n<p>We already know that\u00a0<code>#<\/code>\u00a0in configuration files and most of the programming languages is treated as comment line and is excluded from execution.<\/p>\n<p>Run a command and then create a hash tag of the command so that we can find it later. Say we have a long script that was executed in\u00a0<strong>point 4<\/strong>\u00a0above. Now create a hash tag for this. We know\u00a0<strong>ifconfig<\/strong>\u00a0can be run by\u00a0<strong>sudo<\/strong>or\u00a0<strong>root<\/strong>\u00a0user hence acting as root.<\/p>\n<pre># ifconfig | grep \"inet addr:\" | awk '{print $2}' | grep -v '127.0.0.1' | cut -f2 -d: #myip\r\n<\/pre>\n<p>The script above has been hash tagged with \u2018<strong>myip<\/strong>\u2018. Now search for the hash tag in\u00a0<strong>reverse-i-serach<\/strong>\u00a0(<strong>press ctrl+r<\/strong>), in the terminal and type \u2018<strong>myip<\/strong>\u2018. You may execute it from there, as well.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Create-Command-Hash-Tags.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13166\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/04\/Create-Command-Hash-Tags.gif\" alt=\"Create Command Hash Tags\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>You may create as many hash tags for every command and find it later using\u00a0<strong>reverse-i-search<\/strong>.<\/p>\n<p>That\u2019s all for now. We have been working hard to produce interesting and knowledgeable contents for you. What do you think how we are doing? Any suggestion is welcome. You may comment in the box below. Keep connected! Kudos.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-commandline-chat-server-and-remove-unwanted-packages\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here we are with the next part of Linux Command Line Tips and Tricks. If you missed our previous post on Linux Tricks you may find it here. 5 Linux Command Line Tricks In this post we will be introducing\u00a06 command Line tips\u00a0namely create Linux Command line chat using\u00a0Netcatcommand, perform addition of a column on &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/useful-commands-to-create-commandline-chat-server-and-remove-unwanted-packages-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Useful Commands to Create Commandline Chat Server and Remove Unwanted Packages in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12709","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12709","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12709"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12709\/revisions"}],"predecessor-version":[{"id":12710,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12709\/revisions\/12710"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}