You are on page 1of 1

Lab #6 - Output Redirection, Process Interaction, Bash

Lab Steps:
I.

Stanislav

Redirecting and Piping Standard Output A. If you are not already logged in to GNOME, do so now. Then, open the Terminal application. B. Redirect a full directory listing into the listing file by executing the command ls -a > listing C. Append a “long listing” onto the contents of the first by executing the command ls -l >> listing D. Type cat listing | less to view the contents of the file through less. Press the q key to quit less. E. Type the ls > /dev/null command. This makes all output go into a special device which discards all data which is put into it. This functionality is useful when executing programs with output. Putting Processes Into the Background and Terminating Jobs A. Type tail -f listing to view the file. Tail follows changes as they occur and is great for monitoring log files to see what changes are happening, real-time. B. Press Ctrl + z to put the tail process in the background. Press Enter to show your prompt again. C. Type top and press Enter. This will show you the top 20 processes by CPU usage. Put this into the background as well, again using Ctrl + z. D. Return to the command line and type firefox & command to launch Firefox. E. Type ps ux command to see a list of processes running with their PIDs, statuses, and more. F. Type the jobs command to see what processes are currently in the background. 1. Note: To bring a job back to for foreground (active) type fg <job id> and press Enter. G. Kill the tail process by typing kill -9 <PID> replacing the blank with the tail PID. 1. Note: In your ps ux output, the second column is the process id (PID). H. Kill the process for firefox by typing kill %<job id> using the jobs command to find the job ID.

II.

III. Redirecting Standard Error Output A. Type the find / -name bash -print command to search for a file named bash anywhere on the filesystem. As a regular user, you will receive a lot of errors because you donʼt have full access to the entire filesystem. 1. Note: This process can take a while; be patient and wait for your shell prompt to return again. B. Execute this command again, but redirect output into the file find.out into your home directory. C. Open the find.out file inside of vim and check the contents of the file. D. Execute the find / -name bash -print 1> find.out 2> find.err command. View both files in vim and you will note that find.out contains only results and find.err contains only errors. IV. Using BASH History A. Press the Up Arrow a few times on the keyboard in your Terminal. Observe what is happening. B. You can use a bang (!) in front of a command to search the prompt history for the last occurrence of that command. For example, type !cp and see what the output is. 1. Note: Typing this will execute the command it finds in your history. C. Use the !vim command to execute the last vim command. D. Typing !! and enter will execute the very last command you ran. Using BASH Tab-Completion A. Type cd /usr/loc and press the Tab key. This should autocomplete the directory to /usr/local/. B. Type cd /usr/sb and press the Tab key. Creating BASH Command Aliases A. In your home directory, open the .bashrc file in vim. B. To the last line of the file, add the line alias ll=’ls -l’ and then save the file and exit vim. C. Type source .bashrc and then type ll and Enter to see the new alias working.

V.

VI.