How to run the Linux "cd" command from Java?
<p>I want to write a Java program to delete ~12 directories or files which are under my home directory. I am able to do this by using </p>

<pre><code>Process proc = Runtime.getRuntime().exec("rm -rf *path*") 
</code></pre>

<p>But I have to run this command 12 times or I can keep it in loop. What I really want is to have a file in my home directory that contains the names of all the directories and files to delete in it. My Java program should go to the home directory, read the file, and delete all the specified files.</p>

<p>I am stuck at the very first step – I am not able to cd to the home directory. Please let me know how can I achieve this.</p>

<hr>

<p>Thanks for all of your replies.</p>

<p>But, here I don't really want to use the Java util classes  rather I want to learn a way using which I can run Linux commands in my Java class. Being a deployment Intern, I have to reset the environment every time before deploying a new environment for the customer. For this, I repeatedly use some basic Linux commands. I can write a shell script to do this but for this time, I want to write a Java class in which I can put all these Linux commands and run from one class.</p>

<p>The commands which I use are:</p>

<ol>
<li>kill all java processes which are started by the admin ONLY – for this I need to use multiple Linux commands with “pipe” </li>
<li>Remove all 12-directories/files from home directory</li>
<li>stop some services (like siebel, etc.) – for this I need to go under the particular directories and run ./shutdown.sh or ./stop_ns, etc.</li>
<li>run some database scripts – to reset the database schemas</li>
<li>again start the services – same as step 2 except this time I need to run ./start_ns, etc.</li>
</ol>

<p>I really appreciate if you can let me know 
a.  How can I navigate into a directory using Java code
b.  How can I run multiple Linux commands using pipe using Java code</p>
