Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This week\'s lab will require you to log in to the Unix system, where you will e

ID: 3639602 • Letter: T

Question

This week's lab will require you to log in to the Unix system, where you will execute commands we have covered this week. The lab is broken down into three different activities. In the first activity, you will use the command line in Unix. In the second activity, again on the Unix system, you will traverse the directory structure to locate a specific file and read its contents. In the last part of this lab, you will be using a file located in Doc Sharing to identify Unix commands embedded in the text.

To complete the lab assignment, you'll need to use the iLab link above to log on to the Element K iLab portal. Here are some instructions to help you get started with Unix and the ElementK Virtual Machine: Element K Hints.

Deliverables

You will submit a single file to the dropbox this week. For the first activity, you will submit a report specifying the result of each of the commands executed. For the second activity, you will submit your favorite line from the file "Texas.txt." For the last section of this lab, you will submit a list of the commands found in the "Who(1)'s on what(1)?" story, as well as an example of how to use each of the commands.


L A B S T E P S

PART 1: Executing Commands
Back to top

For each of these commands, you will execute the command in the Element K Unix environment. You can find information on how to enter this environment in the Element K iLab tab under Course Home. Document your results using the lab report document provided in Doc Sharing. The list below shows you which commands you will be using. Please note that the lab report contains the actual command you will type. Document the result of each of the commands you execute, whether there is an observable result or not.

COMMAND

who
whoami
date
cal
clear
ls
cd
pwd
man
printenv
sleep
history

PART 2: Locating a File Within the Directory Structure
Back to top

Your objective in this activity is to locate a file called Texas.txt. It is located in a subdirectory of: /home. This exercise is designed to give you experience in navigating the Unix/Linux directory structure.

Here is an example of the commands and process you can use to locate the Texas.txt file:

Go to the /home directory

cd /home/xxxxx (where xxxxx is the name of your login)

Change Directory (cd) to some of the directories in /home/xxxxx to find the Texas file.
Find out which directory you're in by typing:

pwd (which means "print working directory")

Use cd and ls until you find the file Texas.txt.
Once you find the file Texas.txt, read it by typing:

more Texas.txt

In your lab report, include your favorite line from the Texas.txt file and the full path name of the directory where the file is located.

PART 3: Identifying UNIX Commands
Back to top

The story "Who(1)'s on what(1)?" is a very old and funny "story" about Unix. You can find this file in Doc Sharing. Follow the instructions below.

Read the story.
Identify all of the Unix commands and utilities to which it refers.
Look up each command or utility in the man pages.
In your lab report, include a description and an example usage of each of the commands or utilities you have identified.

Explanation / Answer

public class Hello { static public void main (String[] args) { try { String[] cmds = { "/bin/sh", "-c", "ls -l *.java | tee tmp.out"}; Process p = Runtime.getRuntime().exec (cmds); p.waitFor (); System.out.println ("Done."); } catch (Exception e) { System.out.println ("Err: " + e.getMessage()); } } } String cmd = "system_profiler -detailLevel full -xml > "+System.getProperty( "user.home" )+"/sysinfo.plist"; Process p = Runtime.getRuntime().exec(cmd); public class ShellTest { public static void main(String[] args) throws java.io.IOException, java.lang.InterruptedException { // Get runtime java.lang.Runtime rt = java.lang.Runtime.getRuntime(); // Start a new process: UNIX command ls java.lang.Process p = rt.exec("ls"); // Show exit code of process System.out.println("Process exited with code = " + rt.exitValue()); } } public class ShellTest { public static void main(String[] args) throws java.io.IOException, java.lang.InterruptedException { // Create ProcessBuilder instance for UNIX command ls -l java.lang.ProcessBuilder processBuilder = new java.lang.ProcessBuilder("ls", "-l"); // Create an environment (shell variables) java.util.Map env = processBuilder.environment(); env.clear(); env.put("COLUMNS", "3"); // See manpage ls(1) // You can change the working directory pb.directory(new java.io.File("/Users")); // Start new process java.lang.Process p = pb.start(); } } public class ShellTest { public static void main(String[] args) throws java.io.IOException, java.lang.InterruptedException { // Get runtime java.lang.Runtime rt = java.lang.Runtime.getRuntime(); // Start a new process: UNIX command ls java.lang.Process p = rt.exec("ls"); // You can or maybe should wait for the process to complete p.waitFor(); System.out.println("Process exited with code = " + rt.exitValue()); // Get process' output: its InputStream java.io.InputStream is = p.getInputStream(); java.io.BufferedReader reader = new java.io.BufferedReader(new InputStreamReader(is)); // And print each line String s = null; while ((s = reader.readLine()) != null) { System.out.println(s); } is.close(); } } public class ShellTest { public static void main(String[] args) throws java.io.IOException, java.lang.InterruptedException { java.lang.Runtime rt = java.lang.Runtime.getRuntime(); java.lang.Process p = rt.exec("ls"); p.waitFor(); System.out.println("Process exited with code = " + rt.exitValue()); // Get process' input: its OutputStream java.io.OutputStream os = p.getOutputStream(); os.write("my input".getBytes()); os.close(); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote