Develop a program that simulate a Linux file system and a terminal to interact with the "simulated" file system.
Develop a Java program that uses:
The goal of this assignment is to make a basic directory maintenance simulator that processes basic Unix/Linux commands.
We will use a tree to represent the directory structure: see image.
For simplicity, we will use the same type of node to represent a file or a directory. Also, since we will need to traverse the tree towards the root for some commands, it is useful to maintain a reference within each node that points to its parent.
This Project We will simulate several of the UNIX/Linux operating system commands for a directory system in order to add directories, add files, list directory contents, etc. Issuing a command to create a directory, or example, should not result into creating an actual directory in your file system, but rather a node in your simulated directory tree.
Your application must function as described below:
Commands
We will implement the following commands:
ls // lists all files and directories in the current directory,
// indicating whether the entry is a file or directory. See the test cases
mkdir < dirname> // creates a new directory if it does not already exist
cd < dirname> // changes into specified directory if it exists
cd .. // changes to the parent directory
pwd // specifies the current directory: root/nextdir/etc/
touch < filename> // adds a file to the current directory
mv < fname1> < fname2> //change the name of the file or directory to the new name
rm < filename> // locate and remove the file or directory
exit // ends the session
For simplicity, commands are expected to operate on the current directory only. In other words, you will NOT need to handle cases such as touch test/dir1/dir2.
The following is a sample run of the File System Simulator:
$ pwd
/root
$ mkdir test
$ cd foo
No such file or directory
$ cd test
$ ls
$ mkdir dir
$ pwd
/root/test
$ ls
d dir
$ cd dir
$ pwd
/root/test/dir
$ cd anothertest
No such file or directory
$ mkdir dir2
$ touch dir2
File or directory already exists
$ ls
d dir2
$ touch file
$ ls
f file
d dir2
$ mv dir2 dir
$ ls
f file
d dir
$ rm file
$ ls
d dir
$ rm nofile
No such file or directory
$ pwd
/root/test/dir
$ wrongcommand
unknown command
$ touch
improper command
$ exit