Skip to main content

Linux Useful Commands with examples

To know the IP address
-----------
hostname -i (ip addres)
hostname -s (short name)
hostname -d (domain name)
hostname -v (host name with domain name)


To know the port number and running processes
netstat -ano | findstr 80

If the file is huge in size and to see the file content we can use
less <file name>
e.g. less service.log

Searching  matching pattern in file
grep '<matching text>' <file name>
e.g. grep 'Exception' service.log

To grep the text from .gz files
gzgrep '<matching text>' <gz file name>
e.g. gzgrep 'Exception' service.log.gz

ps -eaf | grep java
ps aus | grep java

tail -f <file Name> (auto updated last few lines)
tail -100 logfile.log  (last 100 lines)

ls -a  (hidden files)
ls -lrt (Sort the files by time stamp)

kill -9 <Process ID>   (get Process ID using ps -eaf | grep <process name>)
e.g. kill -9 30102

Comments

Popular posts from this blog

NO SQL Types and vendors in market

NO SQL

KEY - VALUE Store  - Similar to a  MAP.
   e.g. Dynamo DB or REDIS

DOCUMENT Sore  - Similar to KEY-VALUE, value can be JSON/XML and key will be unqiuely idnetified this document.
   e.g. Coutch DB or mongoDB.

Column Store - Multi timentional table, identifying data with row and column numbers.
  e.g.  Cassandra or Apache HBase

Graph Store - Store relation between nodes (record entities). It has better transaction management
e.g. Neo4J and Orient DB.




Compress a String

package com.sbs.java8.praticse;

public class StringCompression {

public StringCompression() {
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {
System.out.println(compressString("aaaabbbbbccccAAAAccccccccdefg"));
}

public static String compressString(String str) {
//String str = "aaaabbbbbcccc";
char[] charArray = str.toCharArray();
String compressedString = "";
int i = 0;
while (i < charArray.length) { int counter = 1; int j = i + 1; while (j < charArray.length && charArray[i] == charArray[j]) { counter++; j++; i++; } compressedString = compressedString + charArray[i] + counter; i++; } //System.out.println(compressedString); String output =(compressedString.length() > charArray.length)? str: compressedString;
return output;
}
}