File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes simulate unix commands with java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "simulate unix commands with java" Watch "simulate unix commands with java" New topic
Author

simulate unix commands with java

Rajag raja
Greenhorn

Joined: Jul 12, 2013
Posts: 5
Dear All,

Please help me in simulating Unix commands in JAVA

ls command of Unix with options like –l,-t,-P,-R

grep Command in Unix with options
a) to print lines matching patterns in file b) Line number in file matching the pattern
c)no. of times the pattern is present in file

to simulate menu driven program for commands
a) Head b) Tail c) diff d) comm.


simulate a Pass-1 of an Assembler for sample ALP code
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

What exactly do you mean by "simulating" what those programs do with Java?

Do you mean write Java programs which do what ls, grep, etc. do? That would not be very easy. Implementing grep is not simple, and writing an assembler is also definitely something that will take a lot of time.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rajag raja
Greenhorn

Joined: Jul 12, 2013
Posts: 5
Yes.Simulating means to write java programs which do what ls,grep,etc do.

i have searched in google for grep.java,ls.java ,etc.

please check links whether they can help you make me understand the code

https://github.com/breeves/lsd/blob/master/Ls.java
http://www.ontko.com/moss/filesys/ls.java
http://introcs.cs.princeton.edu/java/72regular/Grep.java.html
http://alvinalexander.com/java/jwarehouse/jEdit/bsh/commands/dir.java.shtml
http://www.phillipkuo.com/blog/?p=56
http://jsesoft.sourceforge.net/
https://github.com/RoxasShadow/sJOS/blob/master/modules/Mv.java
http://introcs.cs.princeton.edu/java/96optimization/Diff.java.html
http://trac.mucommander.com/browser/trunk/source/com/mucommander/file/util/Chmod.java?rev=35

54
http://docs.oracle.com/javase/tutorial/essential/io/examples/Chmod.java
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18748
    
  40

Rajag raja wrote:
ls command of Unix with options like –l,-t,-P,-R


The ls command just list files (and directories) in directories. I guess you should start with the java.io.File class. There are methods that list files.

Rajag raja wrote:
grep Command in Unix with options
a) to print lines matching patterns in file b) Line number in file matching the pattern
c)no. of times the pattern is present in file


This one is a little bit harder. The "re" in "grep" is short for regular expressions -- so you would likely need to learn regular expressions first. In Java, regular expressions are accomplished by the java.util.regex.Pattern and java.util.regex.Matcher class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rajag raja
Greenhorn

Joined: Jul 12, 2013
Posts: 5
Thanks for the reply.But these programs are given as simple programs as part of lab exercise for B.E course.Please help me with the code for which i will be thankful to you.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41583
    
  54
Sure. What do you have so far, and where are you stuck making progress? If you haven't started, what ideas have you had?

Note that people here will not write the code for you, though. That would unfairly rob you of the educational value of figuring it out yourself.


Ping & DNS - my free Android networking tools app
Rajag raja
Greenhorn

Joined: Jul 12, 2013
Posts: 5



O.K. what about System Programming in Java?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41583
    
  54
What about it?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: simulate unix commands with java