Git Product home page Git Product logo

unix4j's Introduction

unix4j Build Status Coverage Status Maven Central

Unix4j is an implementation of Unix command line tools in Java. You can use the commands that you know from Unix in a Java program---you can pipe the results of one command to another as you know it from Unix.

Unix4j gives you the power of unix commands, e.g. text processing, file management, with the benefits that come from a strongly typed and testable language such as Java.

In Unix, you might see a command such as:

cat test.txt | grep "Tuesday" | sed "s/kilogram/kg/g" | sort 

In Unix4j this would look like:

Unix4j.cat("test.txt").grep("Tuesday").sed("s/kilogram/kg/g").sort();

Currently supported commands are: cat, cd, cut, echo, find, grep, head, ls, sed, sort, tail, uniq, wc, xargs.

Maven

<dependency>
	<groupId>org.unix4j</groupId>
	<artifactId>unix4j-command</artifactId>
	<version>0.6</version>
</dependency>

Easy text processing

Working in the finance industry in Melbourne, the authors of Unix4j spent a lot of time writing complex text processing applications in bash. Frustrated with the inherent limitations of the bash language; lack of language support, IDEs, test frameworks etc, the authors decided to try and bring the convenience of some of the Unix commands into the Java language.
You may notice that the implemented commands are more bent towards text processing rather than OS and file manipulation. This is intended as we see text processing to be the real benefit of Unix4j. Not to say that this will always be the case.

Simple to use

Using Unix commands, it is very easy to achieve powerful text processing with very concise expressions. Achieving the same thing in Java is often very verbose. For Unix4j to be useful it had to be simple to use. The authors have gone to great lengths to provide an API which hopefully achieves this.
To emulate the "piping" that is used within Unix, a feature which is embraced to great length in Unix4j is "method chaining". e.g.:

String result = Unix4j.fromString("hello world").grep("hello").wc().toStringResult();

Providing such method chaining whilst still keeping a clean and well structured code base has been a real challenge. It may have increased the complexity of the code base in some instances. But we feel that Unix4j must be easy to use, and must result in code which is concise and easy to read.

Remaining true to the behaviour of the emulated Unix commands

Where possible we have tried to stick as closely to the behaviour of the original command as much as possible. Options and argument names have also been aligned with those in the original Unix commands.

Examples:

//list all files and directories in the long listing format (unix: ls -la)
Unix4j.ls(Ls.Options.l.a).toStdOut();

//print all lines of the file "fruitlist.txt" that are not containing "apple" (unix: grep -v apple fruitlist.txt)
Unix4j.grep(Grep.Options.v, "apple", "fruitlist.txt").toStdOut();

Some command usage examples

CommandBuilderTest.java

ExampleTest.java

FAQ

Questions & Answers

Download

Sources and binaries can be downloaded from maven central:

https://search.maven.org/search?q=g:org.unix4j

API Javadoc

Latest Version

Newest Snapshot

unix4j's People

Contributors

ahadas avatar benjwarner avatar dependabot[bot] avatar pthariensflame avatar terzerm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.