How to Convert doc File to txt File using Mac Terminal

The Mac terminal provides a powerful “textutil” command, which can be used to convert .doc files to .txt files directly from the terminal without opening the .doc file.

Here is the command which can be used for the same :

$ textutil -convert txt yourdocfile.doc

Here, the doc file “yourdocfile.doc” will be converted to txt file and a new file “yourdocfile.txt” will be created in the folder with the contents of the doc file.

How to Check Environment Variables in Mac

Here is how we can check the environment variables on Mac.

You can execute the following command on your terminal window.

$ env

This will display all the environment variables set to you Mac, including SHELL variable, USER, JAVA_HOME, M2_HOME, HOME and all other variables that are set on your Mac. If you are missing any variable in this, then that means that variable is not set up correctly on your system.

Moving a File from One Folder to Another Using Mac Terminal

In this article. you will see how to move a file from one folder to another without using Mac terminal.

For this, I have with me, two folders : “junk” and “junk1”. Now lets list the contents of those two folders before we start.

:junk admin$ ls -l

total 16

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

 

:junk1 admin$ ls -l

Here, you can see that the folder “junk” contains two files : file1.txt and file2.txt. And the folder “junk1” is empty with no files.

Lets say you want to move file1.txt from the folder “junk” to “junk1” in my “Desktop”.

First ‘cd’ into your source folder. In this case, its the “junk” folder. Now, here is how you can do the copy :

:junk admin$ mv file1.txt ../junk1

As you can see, we are using the ‘mv’ command. The ‘../’ pattern will point to the parent path of the current working directory.

Now you can list the contents of the folder “junk”.

:junk admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

Here you can see that the file, “file1.txt” is not there in the “junk” folder now.

Next you can ‘cd’ into your “junk1” folder and list the contents of the same. You will see something like this :

:junk1 admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

From this, you can see that the file is moved to your destination folder.

Copying Files from One Folder to Another without Using Path in Mac Terminal

In this article. you will see how to copy a file from one folder to another without using path in Mac terminal.

For this, I have with me, two folders : “junk” and “junk1”. Now lets list the contents of those two folders before we start.

:junk admin$ ls -l

total 16

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

:junk1 admin$ ls -l

Here, you can see that the folder “junk” contains two files : file1.txt and file2.txt. And the folder “junk1” is empty with no files.

Lets say you want to copy file1.txt from the folder “junk” to “junk1” in my “Desktop”.

First ‘cd’ into your source folder. In this case, its the “junk” folder. Now, here is how you can do the copy :

junk admin$ cp file1.txt ../junk1

As you can see, we are using the ‘cp’ command and not giving the full path of the destination folder. Rather, we are using the ‘../’ pattern to point to the parent path of the current working directory.

Next you can ‘cd’ into your “junk1” folder and list the contents of the same. You will see something like this :

:junk1 admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  32 Nov 27 10:24 file1.txt

From this, you can see that the file is copied to your destination folder.

Finding the Difference in Two Files using Mac Terminal

In this article. you will see how to find the difference between the contents of two files using Mac terminal.

For this, I have with me, two text files with names “file1” and “file2”. Now lets see what the contents of those files are. For this, we can use the ‘cat’ command.

$ cat file1.txt

File Content :

file1

content A

$ cat file2.txt

File Content :

file2

content B

New line in file2

Now here is how you can find the differences in the contents of those two files :

$ diff file1.txt file2.txt

3,4c3,5

< file1

< content A

> file2

> content B

> New line in file2

Here, in the result of the ‘diff’ command, you can see that the contents that are different corresponding to both the files are listed. First, it will list the difference in content of the first file we are giving as parameter. For better understanding, lets change the order of file arguments and see :

$ diff file2.txt file1.txt

3,5c3,4

< file2

< content B

< New line in file2

> file1

> content A

 

Here, you from the result, you can see that when we change the order of parameter, the order of differences displayed by the ‘diff’ command also changes.

 

 

Copying Files from One Folder to Another From Another Folder using Mac Terminal

In this article. you will see how to copy a file from one folder to another while you are in an entirely different folder using Mac terminal.

For this, I have with me, two folders : “junk” and “junk1” in my “Desktop”. Now lets list the contents of those two folders before we start.

:junk admin$ ls -l

total 16

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

:junk1 admin$ ls -l

Here, you can see that the folder “junk” contains two files : file1.txt and file2.txt. And the folder “junk1” is empty with no files.

Lets say you want to copy file1.txt from the folder “junk” to “junk1”. Here is how you can do this :

:Desktop admin$ cp /Users/admin/Desktop/junk/file1.txt /Users/admin/Desktop/junk1

As you can see, we are using the ‘cp’ command and giving the full path of both the source file and the  destination folder.

Next you can ‘cd’ into your “junk1” folder and list the contents of the same. You will see something like this :

:junk1 admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  32 Nov 27 10:20 file1.txt

From this, you can see that the file is copied to your destination folder.

Comparing Two Files using Mac Terminal

In this article. you will see how to compare two files to see whether there is any difference between two files using Mac terminal.

For this, I have with me, two text files with names “file1” and “file2”. Now lets see what the contents of those files are. For this, we can use the ‘cat’ command.

$ cat file1.txt

file1

$ cat file2.txt

file2

As you can see, the contents of files ‘file1.txt’ and ‘file2.txt’ are “file1” and “file2” respectively. Now here is how we can compare those two files :

$ cmp file1.txt file2.txt

file1.txt file2.txt differ: char 5, line 1

Here, in the result of the ‘cmp’ command, you can see that the compared files are showing one difference and that difference is in line 1, character 5. Now if you look at the contents of the file, you can see that it is true.

Copying Files from One Folder to Another using Mac Terminal

In this article. you will see how to copy a file from one folder to another using Mac terminal.

For this, I have with me, two folders : “junk” and “junk1”. Now lets list the contents of those two folders before we start.

:junk admin$ ls -l

total 16

-rw-r–r–  1 admin  staff  32 Nov 27 09:20 file1.txt

-rw-r–r–  1 admin  staff  50 Nov 27 09:20 file2.txt

:junk1 admin$ ls -l

Here, you can see that the folder “junk” contains two files : file1.txt and file2.txt. And the folder “junk1” is empty with no files.

Lets say you want to copy file1.txt from the folder “junk” to “junk1”. Here is how you can do this :

:junk admin$ cp file1.txt  /Users/admin/Desktop/Desktop\ v\ 2.0/junk1

As you can see, we are using the ‘cp’ command and giving the full path of the destination folder. Another thing you should note is that we are in the source folder so we can give the file name itself.

Next you can ‘cd’ into your “junk1” folder and list the contents of the same. You will see something like this :

:junk1 admin$ ls -l

total 8

-rw-r–r–  1 admin  staff  32 Nov 27 10:13 file1.txt

From this, you can see that the file is copied to your destination folder.

How to List Files of a Folder without cd-ing in Mac Terminal

Normally, if you want to list the contents of a folder, you will have to ‘cd’ into that folder and then use the ‘ls’ command to list the files inside. But there is another way in which you can list the contents of a folder without ‘cd’-ing into that folder. Here is how you can do it.

ls /Users

And the result will look like this :

Guest Shared admin

Now if you want to use the detail listing command, it will look like this with the result :

ls -l /Users

total 0

drwxr-xr-x+ 11 201         _guest   374 Oct 15  2012 Guest

drwxrwxrwt  12 root        wheel    408 Oct 24 19:38 Shared

drwxr-xr-x@ 79 admin       staff   2686 Nov 24 11:51 admin

In these commands, what you are doing is that you are passing the folder name whose contents list you want to get along with your ‘ls’ command.

Maven Sample App Generation Structure

You must have Java and Maven installed in order to do this.

From command line (shell prompt or terminal window) type mvn -version to confirm that Java and Maven are working

mvn -version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T02:28:10+05:30)
Maven home: /Developer/apache-maven-3.2.3
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10", arch: "x86_64", family: "mac"

Generate a sample Maven Java application from hundreds of samples as below

mvn archetype:generate

Choose the default archetype number, it my case 495 for the sample Java application template/structure

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 495:
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6:
Define value for property 'groupId': : com.schogini.sree
Define value for property 'artifactId': : SreeM2Test
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  com.schogini.sree: :
Confirm properties configuration:
groupId: com.schogini.sree
artifactId: SreeM2Test
version: 1.0-SNAPSHOT
package: com.schogini.sree
 Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: /Users/sree/Downloads/junk
[INFO] Parameter: package, Value: com.schogini.sree
[INFO] Parameter: groupId, Value: com.schogini.sree
[INFO] Parameter: artifactId, Value: SreeM2Test
[INFO] Parameter: packageName, Value: com.schogini.sree
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /Users/sree/Downloads/junk/SreeM2Test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 38.845 s
[INFO] Finished at: 2014-11-01T12:19:58+05:30
[INFO] Final Memory: 14M/245M
[INFO] ------------------------------------------------------------------------

Above command would have created the application folder, in my case SreeM2Test

cd SreeM2Test

Take the look at the folders and files Maven created. I created several folders and placed to Java class files, one is the main class and the other class for unit testing.

SreeM2Test/
├── pom.xml
└── src
    ├── main
    │   └── java
    │       └── com
    │           └── schogini
    │               └── sree
    │                   └── App.java
    └── test
        └── java
            └── com
                └── schogini
                    └── sree
                        └── AppTest.java

Maven also created a maven configuration xml called pom.xml at the root as below. This file tell Maven about the dependencies etc.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.schogini.sree</groupId>
  <artifactId>SreeM2Test</artifactId> <——— this is the final name of the class within the package
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging> <——————— packaging format

  <name>SreeM2Test</name> <—————— application name
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId> <—————— there is only one dependency for this sample app JUnit
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Maven created a Java class file at src/main/java/com/schogini/sree/App.java 

package com.schogini.sree;

/** * Hello world! * */
public class App
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

Maven created another Java class for unit tests at src/test/java/com/schogini/sree/AppTest.java

package com.schogini.sree;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/** * Unit test for simple App. */
public class AppTest
    extends TestCase
{
    /** * Create the test case * *@param testName name of the test case */
    public AppTest( String testName )
    {
        super( testName );
    }

    /** *@return the suite of tests being tested */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /** * Rigourous Test :-) */
    public void testApp()
    {
        assertTrue( true );
    }
}

Now, compile the application using Maven command.

mvn compile

After the compilation is completed, Maven would have created a new folder called target at the root of your application folder

SreeM2Test/
├── pom.xml
├── src
│   ├── main
│   │   └── java
│   │       └── com
│   │           └── schogini
│   │               └── sree
│   │                   └── App.java
│   └── test
│       └── java
│           └── com
│               └── schogini
│                   └── sree
│                       └── AppTest.java
└── target
    ├── classes
    │   └── com
    │       └── schogini
    │           └── sree
    │               └── App.class
    └── maven-status
        └── maven-compiler-plugin
            └── compile
                └── default-compile
                    ├── createdFiles.lst
                    └── inputFiles.lst

now type the command

mvn package

Package command will first do the unit tests and it the tests are successful will generate the jar package (as mentioned in the pom.xml file)

See the additional files created in the target folder

└── target
    ├── SreeM2Test-1.0-SNAPSHOT.jar
    ├── classes
    │   └── com
    │       └── schogini
    │           └── sree
    │               └── App.class
    ├── maven-archiver
    │   └── pom.properties
    ├── maven-status
    │   └── maven-compiler-plugin
    │       ├── compile
    │       │   └── default-compile
    │       │       ├── createdFiles.lst
    │       │       └── inputFiles.lst
    │       └── testCompile
    │           └── default-testCompile
    │               ├── createdFiles.lst
    │               └── inputFiles.lst
    ├── surefire-reports
    │   ├── TEST-com.schogini.sree.AppTest.xml
    │   └── com.schogini.sree.AppTest.txt
    └── test-classes
        └── com
            └── schogini
                └── sree
                    └── AppTest.class

 

This is would have created the jar in the target folder as below 

└── target
    ├── SreeM2Test-1.0-SNAPSHOT.jar
    ├── classes
    │   └── com
    │       └── schogini
    │           └── sree
    │               └── App.class
    ├── maven-archiver
    │   └── pom.properties
    ├── maven-status
    │   └── maven-compiler-plugin
    │       ├── compile
    │       │   └── default-compile
    │       │       ├── createdFiles.lst
    │       │       └── inputFiles.lst
    │       └── testCompile
    │           └── default-testCompile
    │               ├── createdFiles.lst
    │               └── inputFiles.lst
    ├── surefire-reports
    │   ├── TEST-com.schogini.sree.AppTest.xml
    │   └── com.schogini.sree.AppTest.txt
    └── test-classes
        └── com
            └── schogini
                └── sree
                    └── AppTest.class

In order to run the jar file created above, mention it’s location as the class path parameter to Java and then mention the main class name, which is App in our case.
Please note that instead of compile and package commands, we could have just used the package command alone, which would have compiled anyway! 

java -cp target/SreeM2Test-1.0-SNAPSHOT.jar com.schogini.sree.App
 
Hello World!

That is it, you have created a sample java application, compiled, packaged and executed all using Maven tool!
In Maven commands can be chained… e.g.: mv clean compile