Wednesday, October 26, 2016
13 Basic Cat Command Examples in Linux
The cat (short for “concatenate“) command is one of the most frequently used command in Linux/Unix like operating systems. cat command allows us to create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files. In this article, we are going to find out handy use of cat commands with their examples in Linux.
General Syntax
cat [OPTION] [FILE]...
1. Display Contains of File
In the below example, it will show contains of /etc/passwd file.
# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
narad:x:500:500::/home/narad:/bin/bash
2. View Contains of Multiple Files in terminal
In below example, it will display contains of test and test1 file in terminal.
# cat test test1
Hello everybody
Hi world,
3. Create a File with Cat Command
We will create a file called test2 file with below command.
# cat >test2
Awaits input from user, type desired text and press CTRL+D (hold down Ctrl Key and type ‘d‘) to exit. The text will be written in test2 file. You can see contains of file with following cat command.
# cat test2
hello everyone, how do you do?
4. Use Cat Command with More & Less Options
If file having large number of contains that won’t fit in output terminal and screen scrolls up very fast, we can use parameters more and less with cat command as show above.
# cat song.txt | more # cat song.txt | less
5. Display Line Numbers in File
With -n option you could see the line numbers of a file song.txt in the output terminal.
# cat -n song.txt
1 "Heal The World"
2 There's A Place In
3 Your Heart
4 And I Know That It Is Love
5 And This Place Could
6 Be Much
7 Brighter Than Tomorrow
8 And If You Really Try
9 You'll Find There's No Need
10 To Cry
11 In This Place You'll Feel
12 There's No Hurt Or Sorrow
6. Display $ at the End of File
In the below, you can see with -e option that ‘$‘ is shows at the end of line and also in space showing ‘$‘ if there is any gap between paragraphs. This options is useful to squeeze multiple lines in a single line.
# cat -e test
hello everyone, how do you do?$
$
Hey, am fine.$
How's your training going on?$
$
7. Display Tab separated Lines in File
In the below output, we could see TAB space is filled up with ‘^I‘ character.
# cat -T test hello ^Ieveryone, how do you do? Hey, ^Iam fine. ^I^IHow's your training ^Igoing on? Let's do ^Isome practice in Linux.
8. Display Multiple Files at Once
In the below example we have three files test, test1 and test2 and able to view the contains of those file as shown above. We need to separate each file with ; (semi colon).
# cat test; cat test1; cat test2
This is test file
This is test1 file.
This is test2 file.
9. Use Standard Output with Redirection Operator
We can redirect standard output of a file into a new file else existing file with ‘>‘ (greater than) symbol. Careful, existing contains of test1 will be overwritten by contains of test file.
# cat test > test1
10. Appending Standard Output with Redirection Operator
Appends in existing file with ‘>>‘ (double greater than) symbol. Here, contains of test file will be appended at the end of test1 file.
# cat test >> test1
11. Redirecting Standard Input with Redirection Operator
When you use the redirect with standard input ‘<‘ (less than symbol), it use file name test2 as a input for a command and output will be shown in a terminal.
# cat < test2
This is test2 file.
12. Redirecting Multiple Files Contain in a Single File
This will create a file called test3 and all output will be redirected in a newly created file.
# cat test test1 test2 > test3
13. Sorting Contains of Multiple Files in a Single File
This will create a file test4 and output of cat command is piped to sort and result will be redirected in a newly created file.
# cat test test1 test2 test3 | sort > test4
This article shows the basic commands that may help you to explore cat command. You may refer man page ofcat command if you want to know more options. In out next article we will cover more advanced cat commands. Please share it if you find this article useful through our comment box below.
Linux chown - Be careful
The
If you're not the root user on your Unix or Linux system -- or even if you are -- be very careful with the
chown
command is most commonly used by Unix/Linux system administrators who need to fix a permissions problem with a file or directory, or many files and many directories.If you're not the root user on your Unix or Linux system -- or even if you are -- be very careful with the
chown
and chgrp
commands. Once you grant ownership of files to another user on your Unix/Linux system, guess what? You don't own them any more. This can lead to all sorts of nasty problems, such as not being able to delete the files.
Fortunately the
chown
and chgrp
commands are commonly used by Unix system administrators (Unix 'root' users) and this isn't usually much of a problem, but I thought I better warn you about it anyway, as it can create a mess.Tuesday, October 25, 2016
Sunday, October 23, 2016
How to Create a Bootable USB Drive Without Using Any Software?
For windows PC user: How to Create a Bootable USB Drive Without Using Any Software?
To create a bootable USB drive manually, we will use the Command Prompt as a Windows default program. Here are step by step to create a bootable USB drive as the Windows installation media. To create a bootable USB drive as a Windows installation media, we require at least 4 GB for minimum capacity. Larger capacity is better. At this moment, I use the USB flash drive with 2 GB of capacity as just an example. It's due to some reasons that my 4 GB flash drive encountered an unusual problem that i have to fix later. :D
To create a bootable USB drive manually, we will use the Command Prompt as a Windows default program. Here are step by step to create a bootable USB drive as the Windows installation media. To create a bootable USB drive as a Windows installation media, we require at least 4 GB for minimum capacity. Larger capacity is better. At this moment, I use the USB flash drive with 2 GB of capacity as just an example. It's due to some reasons that my 4 GB flash drive encountered an unusual problem that i have to fix later. :D
N.B: Very Carefully look at the picture. Size of Disk 1 is 1910 MB. Which is the size of your pendrive/ USB flash drive. It needs to be selected.
Caution: In step 4, If you select Disk 0[which is 298 GB, specifically your Hard Drive], you will loose all your hard drive data.
- Insert your USB flash drive to your running computer. As the first step, we need to run Command Prompt as administrator. To do this, we need to find cmd by typing 'cmd' in the search box on Windows Start Menu. After search result for 'cmd' appears, right click on it and select "Run as administrator".
- Type 'diskpart' on Command Prompt (without quotes) and hit Enter. Wait for a while until the DISKPART program run.
- Type 'list disk' to view active disks on your computer and hit Enter. There would be seen that the active disks shown as Disk 0 for hard drive and Disk 1 for your USB flashdrive with its total capacity.
- Type 'select disk 1' to determine that disk 1 would be processed in the next step then hit Enter.
- Type 'clean' and hit Enter to remove all of data in the drive.
- Type 'create partition primary' and hit Enter. Creating a primary partition and further recognized by Windows as 'partition 1'.
- Type 'select partition 1' an hit Enter. Choosing the 'partition 1' for setting up it as an active partition.
- Type 'active' and hit Enter. Activating current partition.
- Type 'format fs=ntfs quick' and hit Enter. Formatting current partition as NTFS file system quickly.
- Type 'exit' and hit Enter. Leaving DISKPART program but don't close the Command Prompt instead. We would still need it for next process.
Thursday, October 20, 2016
JMeter Installation Procedure Step by Step
Steps to Install JMeter
Step 1) Install Java
Because JMeter is pure Java desktop application, it requires a fully compliant JVM 6 or higher.
In Window/Linux, go to Terminal
Enter command java -version
Step 2) Download Jmeter
You can download Latest version of JMeter from here
http://jmeter.apache.org/download_jmeter.cgi
Choose the Binaries file (either zip or tgz) to download as shown in figure below
Step 3) Installation
You simply unzip the zip/tar file into the directory where you want JMeter to be installed.
installation directory structure should look like as figure below
Step 4) Launch JMeter
You can start JMeter in 3 modes
1. GUI Mode
2. Server Mode
3. Command Line Mode
1. Start JMeter in GUI Mode
If you are using Window, just run the file /bin/jmeter.bat to start JMeter in GUI mode as shown below
Following figure annotates the various components in the JMeter GUI
2. Start JMeter in Server Mode
Server mode is used for distributed testing. This testing works as client-server model. In this model, JMeter runs on server computer in server mode. On client computer, JMeter runs in GUI mode.
To start the server mode, you run the bat file bin\jmeter-server.bat as below figure
3. Start JMeter in command line mode
JMeter in GUI mode consumes much computer memory. For saving resource, you may choose to run JMeter without the GUI. To do so, use the following command options
This is a command line example
$jmeter -n -t testPlan.jmx - l log.jtl -H 127.0.0.1 -P 8000
Resource Link: All documents are copied from following link for study purpose.
http://www.guru99.com/guide-to-install-jmeter.html
Step 1) Install Java
Because JMeter is pure Java desktop application, it requires a fully compliant JVM 6 or higher.
In Window/Linux, go to Terminal
Enter command java -version
Step 2) Download Jmeter
You can download Latest version of JMeter from here
http://jmeter.apache.org/download_jmeter.cgi
Choose the Binaries file (either zip or tgz) to download as shown in figure below
Step 3) Installation
You simply unzip the zip/tar file into the directory where you want JMeter to be installed.
installation directory structure should look like as figure below
Step 4) Launch JMeter
You can start JMeter in 3 modes
1. GUI Mode
2. Server Mode
3. Command Line Mode
1. Start JMeter in GUI Mode
If you are using Window, just run the file /bin/jmeter.bat to start JMeter in GUI mode as shown below
Following figure annotates the various components in the JMeter GUI
2. Start JMeter in Server Mode
Server mode is used for distributed testing. This testing works as client-server model. In this model, JMeter runs on server computer in server mode. On client computer, JMeter runs in GUI mode.
To start the server mode, you run the bat file bin\jmeter-server.bat as below figure
3. Start JMeter in command line mode
JMeter in GUI mode consumes much computer memory. For saving resource, you may choose to run JMeter without the GUI. To do so, use the following command options
This is a command line example
$jmeter -n -t testPlan.jmx - l log.jtl -H 127.0.0.1 -P 8000
Resource Link: All documents are copied from following link for study purpose.
http://www.guru99.com/guide-to-install-jmeter.html
Wednesday, October 19, 2016
How does EJB and JPA relate?
JPA has been designed to
replace EJB2 entity beans, and has started as a part of the EJB3 specification.
Since it makes sense to
also use JPA outside of an EJB container, it has now its own specification, but
it's still related to EJB3, since a compliant EJB3 container has to provide a
JPA implementation, which integrates into the transaction handling of the
container.
EJB2 had
"entity beans" which were a third type of component. EJB3 has JPA,
which has "entities". But I don't think they're considered as
"EJB components" anymore. They're just called JPA entities.
2.
Up until version 2.1 of the EJB specifications, an entity bean
class had to implement the
javax.ejb.EntityBean
interface
and provide an implementation for boilerplate methods such as ejbLoad,
ejbStore, ejbActivate, and ejbPassivate.
EJB 3.0
adopted the JPA specification. The very notion of an entity bean was superceded
by the simpler notion of a JPA entity. To create such entity, no interface
implementation or boiler plate methods are required. The entity is a POJO that
has the
@Entity
annotation.
Thus, in practice the use of "entity bean" EJBs in
Java EE applications is dead (buried under JPA) as of EJB 3.
You are right. JPA has
more to do than only supporting EJB. Thats the reason why JPA became a separate
JSR or specification. EJB uses or enables the usage of JPA in its
specification, simply because JPA is a good standard. You can now switch
between JPA vendors without changing your code if designed properly.
EJB specification can be
used independent of JPA (although JPA has been included as a part of EJB spec)
and likewise JPA can be used for many more stuff outside the EJB spec.
Nevertheless, EJB specification enables the injection of JPA Entitiy Manager
(and its usage) into its beans very easily which makes programming easier.
Ofcourse this can now be achieved easily using a new JSR on CDI :-).
All
the application server that supports EJB spec, should support JPA also. You can
see this threadfor
more information.
Hibernate is an implementation of the JPA spec.
Pros of Agile methods
- Working software is delivered much more quickly and successive iterations can be delivered frequently, at a consistent pace.
- There is closer collaboration between developers and the business.
- Changes to requirements can be incorporated at any point of the process – even late in development.
- It gives the opportunity for continuous improvement for live systems
- It is highly transparent
Pros of the
waterfall method
·
Potential issues that would have
been found during development can be researched and bottomed out during the
design phase. If appropriate meaning an alternate solution is selected before
any code is written.
·
The development process tends to
be better documented since this methodology places greater emphasis on
documentation like requirements and design docs. Many organisations find this
reassuring.
·
Because the waterfall process is a
linear one it is perhaps easier to understand, especially for non-developers or
those new to software development. Often teams feel more comfortable with this
approach.
Cons of the waterfall
method
·
Often the people we’re building
software for (the client) don’t know exactly what they need up front and don’t
know what’s possible with the technology available. This way of working doesn’t
handle this well.
·
Solution designers often aren’t
able to foresee problems that will arise out of the implementation of their
designs.
·
Changes to requirements (e.g. like
those resulting from new technologies, changes in a market or changes to
business goals) can’t easily be incorporated with the waterfall method and
there are often laborious change control procedures to go through when this
happens
·
The process doesn’t have its own
momentum
Web Services good link
There are 4 links available in the list. It helps more to understand Web Services.
- Web Services - Hidden Mysteries
- Invoking Web Services through Matlab
- SOAP Monitoring using Apache Axis2
- Creation of a Web Service in C#.NET
Monday, October 17, 2016
How to enable HTTPS with AXIS 2
I've been using AXIS2 for a couple of months now and decided to take the HTTPS / SSL plunge. The following notes are guidelines on how I configured HTTPS with AXIS2.
I am using Tomcat 6, so firstly you need to enable HTTPS in Tomcat:
1) Create a keystore with the following command and enter the required values:
keytool -genkey -alias tomcat -keyalg RSA -validity 365
2) Then copy this file to a directory e.g. /usr/share/tomcat6/.keystore
3) Edit the Tomcat server.xml e.g. /etc/tomcat6/server.xml and add the following section inside the <Service name="Catalina"> tag
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystorePass="yourkeystorepassword" keystoreFile="/usr/share/tomcat6/.keystore"
clientAuth="false" sslProtocol="TLS" />
(replace yourkeystorepassword with the password you used in step 1)
4) Restart Tomcat and test that you can access Tomcat via HTTPS on port 8443 (you will get a certificate error in your browser as it's not a trusted certificate).
Now onto AXIS2:
5) I downloaded the axis2.war file.
6) Extract the war file with unzip to a empty directory.
7) Edit the WEB-INF/conf/axis2.xml file
8) Change this:
<transportReceiver name="http"
class="org.apache.axis2.transport.http.AxisServletListener"/>
to this:
<transportReceiver name="http"
class="org.apache.axis2.transport.http.AxisServletListener">
<parameter name="port">8080</parameter>
</transportReceiver>
<transportReceiver name="https"
class="org.apache.axis2.transport.http.AxisServletListener">
<parameter name="port">8443</parameter>
</transportReceiver>
9) Now restart Tomcat and go to the HappyAxis(https://localhost:8443/axis2/axis2-web/HappyAxis.jsp) page. You'll see you get some internal server error. This is because Tomcat does not have the keystore configured for AXIS2 to use.
I fixed this by adding the following JAVA_OPT options:
JAVA_OPTS="$JAVA_OPTS -Djavax.net.ssl.trustStore=\"/usr/share/tomcat6/.keystore\" - Djavax.net.ssl.trustStorePassword=\"yourkeystorepassword\""
(replace yourkeystorepassword with the password you used in step 1)
10) Check HappyAxis page and WSDL -> https://localhost:8443/axis2/services/Version?wsdl
All done no mess no fuss :)
I am using Tomcat 6, so firstly you need to enable HTTPS in Tomcat:
1) Create a keystore with the following command and enter the required values:
keytool -genkey -alias tomcat -keyalg RSA -validity 365
2) Then copy this file to a directory e.g. /usr/share/tomcat6/.keystore
3) Edit the Tomcat server.xml e.g. /etc/tomcat6/server.xml and add the following section inside the <Service name="Catalina"> tag
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystorePass="yourkeystorepassword" keystoreFile="/usr/share/tomcat6/.keystore"
clientAuth="false" sslProtocol="TLS" />
(replace yourkeystorepassword with the password you used in step 1)
4) Restart Tomcat and test that you can access Tomcat via HTTPS on port 8443 (you will get a certificate error in your browser as it's not a trusted certificate).
Now onto AXIS2:
5) I downloaded the axis2.war file.
6) Extract the war file with unzip to a empty directory.
7) Edit the WEB-INF/conf/axis2.xml file
8) Change this:
<transportReceiver name="http"
class="org.apache.axis2.transport.http.AxisServletListener"/>
to this:
<transportReceiver name="http"
class="org.apache.axis2.transport.http.AxisServletListener">
<parameter name="port">8080</parameter>
</transportReceiver>
<transportReceiver name="https"
class="org.apache.axis2.transport.http.AxisServletListener">
<parameter name="port">8443</parameter>
</transportReceiver>
9) Now restart Tomcat and go to the HappyAxis(https://localhost:8443/axis2/axis2-web/HappyAxis.jsp) page. You'll see you get some internal server error. This is because Tomcat does not have the keystore configured for AXIS2 to use.
I fixed this by adding the following JAVA_OPT options:
JAVA_OPTS="$JAVA_OPTS -Djavax.net.ssl.trustStore=\"/usr/share/tomcat6/.keystore\" - Djavax.net.ssl.trustStorePassword=\"yourkeystorepassword\""
(replace yourkeystorepassword with the password you used in step 1)
10) Check HappyAxis page and WSDL -> https://localhost:8443/axis2/services/Version?wsdl
All done no mess no fuss :)
Monday, October 10, 2016
Thursday, October 6, 2016
Wednesday, October 5, 2016
Spring MVC tutorials for learning
- http://spring.io/team/dsyer
- http://www.baeldung.com/learn-spring-security-course?utm_source=javarevisited&utm_medium=web&utm_campaign=lss&affcode=22136_bkwjs9xa
- https://geowarin.github.io/complete-example-of-a-spring-mvc-3-2-project.html
- https://github.com/geowarin/spring-mvc-examples/tree/master/mvc-base
- https://bowerstudios.com/node/1023
- https://www.javacodegeeks.com/2013/04/spring-mvc-hibernate-maven-crud-operations-example.html
- http://www.codesandnotes.be/2014/10/31/restful-authentication-using-spring-security-on-spring-boot-and-jquery-as-a-web-client/
- http://stackoverflow.com/users/177800/jarrod-roberson
Tuesday, October 4, 2016
Sunday, October 2, 2016
Subscribe to:
Posts (Atom)