Useful Commands in Linux

Modified on Tue, 12 Mar 2024 at 01:21 PM

1.       How to forcefully stop wildlfy server using Kill command

·         Check if the JAVA process is running using following command

    ps aux | grep java

It will show following output

"root      2929 39.1  5.0 3323548 204140 pts/0  Sl+  12:51   0:09 java -D[Standalone] -server -Xms64m -Xmx2048M -XX:MaxPermSize=256m -XX:NewRatio=2 -XX:PermSize=64m -XX:+UseG1GC -noverify -Djava.net.preferIPv4Stack=true -Djava.util.Arrays.useLegacyMergeSort=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=false -Dorg.jboss.boot.log.file=/root/wildfly/standalone/log/server.log -Dlogging.configuration=file:/root/wildfly/standalone/configuration/logging.properties -jar /root/wildfly/jboss-modules.jar -mp /root/wildfly/modules org.jboss.as.standalone -Djboss.home.dir=/root/wildfly -Djboss.server.base.dir=/root/wildfly/standalone"

·         In the above output the one that is marked with yellow is the process ID of the JAVA. 

·         To kill the Wildfly process run this command

    kill -9 2929

·         After executing above command run the "ps aux | grep java" again to verify that there is no JAVA process running

·         The output should look like below which show that no JAVA process is running

"root      3037  0.0  0.0  13592   912 pts/1    S+   13:00   0:00 grep --color=auto java"

 

2.       Finding JDK location in Linux

·         Execute the following command to find the JAVA Installed in the Linux

    find / -name java

          The above command will show following output depending upon the flavor of the Linux

/etc/bash_completion.d/java

/etc/alternatives/java

/etc/apparmor.d/abstractions/ubuntu-browsers.d/java

/etc/ssl/certs/java

/usr/bin/java

/usr/share/java

/usr/lib/jvm/java-7-oracle/bin/java

/usr/lib/jvm/java-7-oracle/jre/bin/java

/usr/lib/ure/share/java

/var/lib/dpkg/alternatives/java

·         From the above output you have to look for line containing the oracle, that will be your JDK installed path.

·         After you have found out JDK installed path you can now set JAVA environment variable, that will configure all JAVA application to use default JDK.


3.      Command to remove tmp folder and empty log folder in Linux 

·         When you upgrade your Smarten version or you have made some change in the EJBI data folder , sometime the changes are not reflected. In that case you need to delete temporary folder and restart Wildfly server.

·         Log files takes up lot of disk space so it is good practice to delete the log files on regular basis.

·         To delete Wildlfy tmp folder execute following command

           cd WILDFLY_HOME/standalone  ( To change the directory path)

           rm -rf tmp

·         To delete Data tmp folder execute following command

          cd WILDFLY_HOME/standalone/deployments/smarten.war/data ( To change the directory path )

          rm -rf temp

·         To delete the contents of the Wildfly Log folder execute following command.

          cd WILDFLY_HOME/standalone/log ( To change the directory path )

          rm -rf *

·        To delete the contents of the Data log folder execute the following  command

          cd WILDFLY_HOME/standalone/deployments/smarten.war/data/logs ( Change the Directory path )

          rm -rf *

·        To empty the contents of the log files execute the following command

          cat /dev/null > logfile 

4.   

4.      Command to view log files in real time. 

·         You need  to monitor the log files for errors. To view the log file in real time i:e the file is constantly changed as log is generated. To do this you have to use tail command available in Linux

·         You can view last logs of file using tail command

    tail -f logfile

·         The above command will display only last 10 lines of log file , but suppose you need to view last 500 lines you can execute below mention command

          tail -500f logfile

 

5.      To view current port binding and TCP/IP Protocol used in Linux 

·         Your Wildlfly server is bind to particular port for example 80 , 8080 and so on. Bind port will be used to access Smarten URL.

·         In some cases you server is running multiple applications  and if they are running on the same port as wildfly server, In that case wildfly server will throw HTTP listener error and will not start.

·         To resolve the above issue you need to first check that the ports configured in Wildfly server is not used by other application.

·         To do that run below mention commands.

     netstat -tulnp | grep 80 ( Here we are checking if some application is utilizing port 80)

        You will get following output if any application is configured to use port 80

       

        

 

        As you can see from above output 80 port is being used by nginx web server and port 8080 is being used

        JAVA (WIldfly) server.

        To check you have to view the "Listening" parameter which show that port 80 and port 8080 is being used by some application

·         In general to will all the ports used you can simply run  " netstat -anb " or " netstat -tulnp " command without pipe parameter.


6.      Create or Extract tar/zip folder in Linux

·         In case there is no GUI available in Linux and you need to create backup of your current Smarten version or Data folder. You can use tar or zip command to create compressed folder.

·         To create tar use following command

    tar -cvf output.tar /directory

    For eg:-   tar -cvf wildfly.tar /wildfly

·         To extract the tar file use following command

   tar -xzf wildfly.tar

·         To extract the zip folder use following command

         unzip wildlfy.zip


7.      To view system resources utilization

·         We need to view the CPU, RAM and other processes utilization

·         "Top" command will display all the system resources

·         You can view following parameter such as %CPU , % MEM utilization and how much memory is used by the processes.

·         To view details in more human readable format you can use "htop" command.

·         You have to installed "htop" utility in Linux

        Installed htop in Debian based Linux (Ubuntu)

            apt-get install htop

        Installed htop in RPM base Linux ( Cent OS , Red Hat and Fedora )

        Please refer the following URL to install "htop" in RPM based Linux

        http://www.tecmint.com/install-htop-linux-process-monitoring-for-rhel-centos-fedora/

·         You will get following output using "htop" command

·         You can see the difference as "htop" command provides more detail information in human readable format.

 

8.      Basic Commands in Linux

·         To Rename folder in Linux

   For e.g. we need to rename wildlfy folder to wildfly_old

   mv wildfly wildfly_old

·         To copy recursively in Linux

         For e.g we need to copy wildfly folder contents to another location (/home)

         cp -R wildfly/ /home/

·         To Move folder to different location

         For e.g you need to move wildfly folder to another location (/home)

         mv wildfly_old /home 

·         To list folders Contents in Linux

         For e.g To list the contents of wildfly folder

         ls -al wildfly

·         To view size of folder or file in Linux

         For e.g To view size of Wildfly folder

         du -sh wildfly

         To view size of stanalone.xml file

         du -sh standalone.xml

·         To change ownership of folder/file in Linux

         For e.g. To change the ownership of folder/file in Linux

         chown -R root:root wildfly

·         Restart Linux server using Terminal

         init 6

·         Changing permission of folder/files in Linux

         For e.g. You want to give Read/Write/execute permission to particular folder or file in Linux

         chmod -R 755 wildfly (This will give R/W/E permission to owner and R/W permission to other and group)

         chmod -R 777 wildlfy (This will give R/W/E permission to owner, other and group)

         chmod -R 644 wildfly (This will give R/W permission to owner and R permission to other and group)

·         View Hard Disk space in Linux

         df -h (This will display size according to the partition)

         fdisk -l | grep Disk (This will display total HDD size)     

·         To check Memory size in Linux

         free -m

 

Note: This article is based on Smarten Version 5.x. This may or may not be relevant to the Smarten version you may be using.

linux commands stop wildfly kill jdk location remove tmp folder empty logs real time logs current port binding tcp/ip protocol extract tar extract zip system resource utilization basic commands

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article