GoogleSearchBox

Custom Search

Friday, May 24, 2013

Frequently Used Linux Unix Commands while working with Java Web Projects

To Display the current directory path:
# pwd

To List out the directories and Files under the current directory:
# ls 

To list out vertically only:
# ls -l

To list out vertically with sort by timestamp:
# ls -lt

To list out vertically and files having all kind of attributes:
# ls -la

Set JAVA_HOME and PATH Environment variables for a single user:
Login to your account and edit .bash_profile file using vi editor as below:
# vi ~/.bash_profile

Set JAVA_HOME and PATH Environment variables for all users:
Edit the global config file located at /etc/profile OR /etc/bash.bashrc file for all users:
# vi /etc/profile

type below in the .bash_profile  or   /etc/profile file towards the end of the file using the vi editor as above:

export JAVA_HOME=/usr/java/jdk1.7.0_07/
PATH=$PATH:$JAVA_HOME/bin
export PATH

where "/usr/java/jdk1.7.0_07/" is the JDK installation path.
Save and close the file. Just logout and login back to see new changes.

To test JAVA_HOME set correctly or not:
# echo $JAVA_HOME

To verify if Java is setup correctly on your PATH or not:
# java -version
-Should return the JRE version.

To verify if Java Compiler (JDK) is setup correctly on your PATH or not:
# javac -version
-Should return the version of the JDK compiler.

To list all installed jdk versions for Ubuntu or Debian Linux:
$ dpkg --list | grep -i jdk

To list all installed jdk versions for CentOS (RedHat) Linux:
# rpm -qa | egrep -i "(jdk|jre)"


To display the value (String) Set in a System/User Variable :
$ echo $PATH
# echo $CATALINA_HOME
Result:
/usr/share/tomcat6

To View Log Files / Any files :
User head or tail command as below :
$ head -30  mylogfile.log    
Is used to see first 30 lines of the file from beginning.

$ tail +30  mylogfile.log    
To view records in the log file starting from line 30 till the end of the file.

$ tail -20f mylogfile.log
To view the log records on realtime on console starting from -20 records from end of file at that point and fetch the records of log file as it generates in realtime and displays on console.

$ tail -f mylogfile.log
Display log records on console as it generates for the log file mylogfile.log

To know the version of Linux is running:
$ cat /etc/issue            

Result in my System:



              

or   $ cat /etc/*-release

You can use more ways to get the answer, follow this link: http://arun.wordpress.com/2006/06/10/which-linux-distro-are-you-using/#comment-15123

How to Use the vi Editor:
Very nice and day to day used vi commands : Follow the Link: http://www.washington.edu/computing/unix/vi.html

To Check Which Directory our Opnessl conf is located:
$ openssl version -d

Result is something like this:  


Finding a File containing a particular String.
We have to navigate to the suspected directory first or its parent directory.
It starts searching for the file containing the text from the current directory and then in its sub-directories.

$ find . -type f -exec grep -l "Hello" {} +













No comments:

Post a Comment