Tutorial5: Redirection
Contents
REDIRECTION: STANDARD INPUT / STANDARD OUTPUT / STANDARD ERROR
Main Objectives of this Practice Tutorial
- x
- x
- x
- x
- x
- x
- x
Tutorial Reference Material
Course Notes |
Linux Command/Shortcut Reference |
YouTube Videos | ||
Course Notes:
|
xxx
xxx
|
xxx
|
Brauer Instructional Videos:
|
KEY CONCEPTS
Purpose of Having a Matrix Account
While attending Seneca College, you will be using many different computer systems to perform various operations. Some of these servers include:
my.senecacollege.ca | Learning Content Management System (Student Grades / Notes / Online Quizzes) |
ict.senecacollege.ca | Main ICT Webserver |
wiki.cdot.senecacollege.ca | Course WIKIs for Seneca College Students |
matrix.senecacollege.ca | Linux Account for Student Practice and Assignment submission |
Although you need to study concepts throughout this course, you will also need to learn to issue and memorize simple as well as more advanced Linux commands. This requires that you practice issuing Linux commands on a frequent basis to become more comfortable when working the Unix and Linux command-line environments.
Just like with other operating systems like MS Windows, it is important to learn how to open a command prompt in order to issue commands to perform common tasks. In Unix/Linux, a shell is simply an interface / interpreter to allow a user to communicate with the Linux computer system (server). Linux shells have evolved (improved) over a period of time. You will be using the Bash Shell which is considered to be user-friendly. By understanding how to issue Linux commands, you can create a file consisting of Linux commands and programming techniques called a shell script (learned later in this course) to automate tasks to make you a more productive user and administrator.
Layout of the Matrix Server
The Matrix server consists of several Virtual Computers connected together to form a cluster. A cluster is a cost effective alternative to buying larger servers.
All registered students in this course should have an account on the Matrix server. You will be using this account for the following reasons:
- Issuing Linux commands
- Becoming productive using the Linux command prompt (shell)
- Performing Linux Practice Tutorials
- Performing Linux Assignments (3)
- Practice Issuing Linux Command Review Questions
In the next investigation, you will learn how to connect to and login to your Matrix server account both at a college lab workstation and from a remote computer such as your home computer or your laptop computer.
INVESTIGATION 1: REDIRECTION INVOLVING REGULAR FILES
In this section, you will learn how to access your Matrix Linux account by two different methods:
- From a workstation within a Seneca College lab
- From your own computer within or outside Seneca College
Part 1: Access your Matrix Account from a Seneca College Lab
You will learn how to connect to your Matrix Linux account from a workstation in your computer labs at Seneca college.
This would be useful if you do not have a notebook computer and are required to use one of the workstations available in your Seneca computer lab.
MyApps (AppsAnywhere) is an application streaming service that lets you install software on any Seneca PC on demand. Any software application on the MyApps menu can be used on computers in classrooms, labs, and the Computing Commons.
Reference: https://inside.senecacollege.ca/its/software/myapps/
You will now use MyApps on your Windows workstation in your Seneca lab room to launch an application
to allow you to connect and login to your Matrix server account.
Perform the Following Steps:
- Start your workstation in your lab and login to your Seneca Windows account.
- Make certain that the MyApps window is open. This window should have opened shortly after you logged into your Windows workstation. If the application windows is not open, click on the MyApps icon on the desktop to launch).
- Click on the Search Apps area located in the top right corner of the MyApps window and type the word: ssh
- Several SSH applications will appear.
NOTE: All of these applications allow you to connect to your Matrix account.
We will use the application called SSH Secure Shell Client for this practice tutorial. - Launch the SSH Secure Shell Client application icon to launch this program.
NOTE: Prior to launching the application, you can add this to your favourites which will make it faster
to access this application in the future.
- The main SSH Client window will appear. Click on the Quick Connect button.
NOTE: The Connect dialog box allows the user to specify the server name and your account name
to allow you to connect to the server. - Click on the textbox labelled Hostnanme and enter the text: matrix
NOTE: You can use the hostname matrix since you are located inside Seneca's network.
If you where located outside Seneca's network, then you would need to enter the full domain name: matrix.senecac.on.ca - When connecting securely for the first time, a dialog box will appear to share a "public key" with your Matrix account in order to make your interaction between your workstation and the remote Linux server secure within the network (i.e. encrypted to prevent unauthorized access by other users)
FYI: To make communications over a network secure, a computer generates two keys: a private key that is kept on the computer, and a public key, which can be shared with other computers. Transmissions from your computer uses the private key to encrypt (scramble) transmission to the remote computer, which in turn, uses the public key to decrypt (unscramble) the transmission. Likewise, the remote computer uses the public key to encrypt (scramble) transmissions and your computer uses the private key to decrypt (unscramble) those transmissions. - Click the Yes button to share your public key.
- Next, a dialog box will appear prompting you for your Matrix account password in order to gain entry to your Matrix account. Your Matrix password is identical to your Seneca password. As you type the password, the text will be blocked-out or hidden to prevent others from viewing the screen to obtain your password
- Enter your password and click OK or press ENTER
- Click OK or press ENTER at the Authentication Response dialog box.
NOTE: If you encounter an error message, this can occur for several reasons:- You mis-spelled the name of the server
- You mis-spelled your Matrix username (same username that you connect to my.senecacollege.ca)
- You have CAPS LOCK on by mistake (your username should be lowercase only).
- You mis-spelled your password (same password that you connect to my.senecacollege.ca)
If you encountered an error logging in, issue the same steps to connect to your Matrix account,
but carefully check your server name, username and your password. If you continue to experience the same problems,
you can go to the computer help desk in the learning commons to get help. - If you entered your password correctly, the main SSH Linux shell should appear where you enter Linux commands.
The Matrix server has been configured to allow users to only interact with the Linux OS by issuing commands. There are various reasons for this, but the main 2 reasons are to force students to learn how to issue Linux commands as well as limitations to remote access to a graphical Linux server due to large number of users (students).
Later in the course, your instructor may demonstrate other ways of accessing graphical versions of Linux, and how to launch a shell terminal.
You can configure the SSH application to adjust elements such as the window size and text font type and text font size. We will be showing you how to configure your SSH Secure Shell Client, but the other applications can allow you to configure their settings.
Perform the Following Steps:
- Click on the Edit menu item, and then select Settings in the Edit drop-down menu.
- To change the size of your shell window, under the Global Settings section, click Appearance
- Change the window size both horizontal and vertical to larger values.
- To change the font size, under the Global Settings section, click Font
- Select a larger font size and click OK
- You now should notice that you have customized your SSH shell terminal. You can use the settings screen to also change your background and text colours if you are interested in doing so.
- To exit your Matrix session, type the following command and press ENTER: exit
NOTE: You should notice that the colour of the text changes slightly when disconnected and you are unable to issue Linux commands from that window. - After you have disconnected from your account, close the SSH Secure Shell Client application window.
- It is recommended to repeat these steps with connecting to your Matrix account from a Seneca lab workstation until you become comfortable with the process.
In the next section, you will learn how to connect to your Matrix server account from a different computer
(for example: your laptop computer at Seneca College or your computer at home).
Part 2: Access your Matrix Account From your own computer within or outside the Seneca College Network
You will learn how to connect to your Matrix Linux account from your own computer whether it be a laptop computer or your home computer.
This would be useful if you want to access your Matrix Linux account on your own computer to practice Linux commands or perform your assignment outside of the scheduled class-time.
We will be learning to use a different SSH application called "Putty". In this way, you will be exposed to a few SSH applications to help you decide which SSH application you are most comfortable.
- Perform the following steps:
- Click on the following link to download the Putty executable file:
http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
NOTE: If you are interested in downloading and installing other SSH applications (including the
SSH Secure Shell Client application used in part 1), refer to week 1 links in the ULI101 Weekly Schedule. - The putty executable file does not install the Putty program: Instead, run this program, by opening a file manager, moving to the Downloads directory and double-clicking on the putty.exe file.
- The Putty configuration window will appear.
You can configure the SSH application to adjust elements such as the window size and text font type and text font size. We will be showing you how to configure your SSH Secure Shell Client, but the other applications can allow you to configure their settings. - To change the size of your shell window, click Window
- Change the rows and columns to larger values.
- To change the font size, under the Window section, click Appearance
- In the left window under Font Settings, click the Change button.
- Select a larger font size and click Apply
- You will return to the Putty Configuration window.
- To login to your Matrix Linux account, click on Sessions
- In the Host Name sectionand enter the text: matrix
NOTE: You can use the hostname matrix since you are located inside Seneca's network.
If you where located outside Seneca's network, then you would need to enter the full domain name: matrix.senecac.on.ca - Click on the Open button and the Putty session window should appear.
- Enter your username when prompted.
- Enter your password when prompted.
- When connecting securely from the putty application for the first time, a dialog box will appear to share a "public key" with your Matrix account in order to make your interaction between your workstation and the remote Linux server secure within the network (i.e. encrypted to prevent unauthorized access by other users)
- Click the Yes button to share your public key.
NOTE: If you encounter an error message, this can occur for several reasons:- You mis-spelled the name of the server
- You mis-spelled your Matrix username (same username that you connect to my.senecacollege.ca)
- You have CAPS LOCK on by mistake (your username should be lowercase only).
- You mis-spelled your password (same password that you connect to my.senecacollege.ca)
If you encountered an error logging in, issue the same steps to connect to your Matrix account,
but carefully check your server name, username and your password. If you continue to experience the same problems,
you can go to the computer help desk in the learning commons to get help. - If you followed the login sequence correctly, the Putty Shell window will appear where you can issue Linux commands.
- To exit your Matrix session, type the following command and press ENTER: exit
NOTE: You should notice that the Putty application window will disappear. - It is recommended to repeat these steps with connecting to your Matrix account from a Seneca lab workstation until you become comfortable with the process.
In the next investigation, you will learn how to issue Linux commands and how to setup and perform the first two sections of the online ULI101 assignment #1.
INVESTIGATION 2: REDIRECTION USING PIPES
In this section, you will learn how to use the Linux Shell. Topics in the section include:
- Learn the Linux command structure (arguments and options)
- Learn how to get help for Linux commands with manpages (man command).
- Learn Basic Shell Editing
- Learn how to perform online assignments.
- Perform the first two sections of online assignment #1.
Part 1: Using the Linux Shell
The Bash shell in Matrix allows you to interact with your account by issuing commands.
Some Linux commands can be issued by entering the Linux command line without arguments (e.g. pwd, date, ls, cal),
but some Linux commands can be issued with arguments (e.g. cal 2002, cd /bin, ls -la ).
Linux Command Structure
command argument1 argument2 ...
An argument can be a pathname, text, option, etc.
For example:
- The ls command displays a listing of filenames in the current directory
- The ls /bin command displays a listing of filenames in the /bin directory (as opposed to your current directory)
- The ls -l command displays a detailed listing of filenames in the current directory
- The ls -l /bin command displays a details listing of files in the /bin directory
Getting Help with Linux Commands
With the Linux OS containing over 2500 commands and utilities, it is good for a Linux user or sysadmin to learn about how to use commands “on-the-fly”.
The man command can provide information on how to use a command (i.e. usage, arguments, options, examples).
The commands are classified into sections or “volumes”.
Perform the Following Steps:
- Make certain that you are logged into your Matrix account.
- Issue the following command: man man
How many volume numbers are contained in the man pages (like executable commands/programs, games, or system administrator commands)? - Press the letter q to exit the man command.
- Issue the Linux command to get help with the command: ls
NOTE: You can use the following short-cut keys within the man command to
help navigate throughout this utility to get help with the ls command (refer to table below):Keyboard Shortcut Purpose ENTER Move down one line SPACEBAR Move one screen down <ctrl><f> Move one screen up /pattern/ Search for Pattern q quit man utility - Navigate through the man utility for the ls Linux command and note the option letters that correspond to the following:
- Include directory entries whose names begin with a dot
- List in long format
- Recursively list subdirectories encountered
- Sort files by size
- Display a slash (`/') immediately after each pathname that is a directory
- Exit the man utility for the ls command.
- Issue the ls command for each of those option letters you wrote down to see how this command differs for each option.
NOTE: The man utility can be used with the -k option to help list Linux commands that match a text pattern that is contained within the help screen for a Linux command. - Although we will not be learning about pipeline commands (using the | character) until later, try issuing the following pipeline command: man -k copy | grep 8
How this this pipeline command make it easier to obtain information regarding man command? - If you wish to change your password, you can change it by issuing the command: passwd
What option for the passwd command can be used to change user info (such as name)?
Hint: use the manpages for the passwd command.
NOTE: You are NOT required to change your Matrix password for this tutorial. The Matrix server is "synched" with the my.senecacollege.ca server, so it is better to have your Matrix password changed at the same time that you change your myseneca password.
Command Line Editing
Learning shortcut keys in any OS terminal will allow you to be more productive as a sysadmin. You will focus on learning a few common Bash Shell keyboard shortcut keys and learn where you can access online help for additional shortcuts (if required).
Perform the Following Steps:
- Type the following Linux command, but DON’T press the ENTER key: cd /bin
- Press the ctrl-a key combination. What happens?
- Press the alt-F key combination (ESC+F for Mac OSx). What happens?
- Press the ctrl-w shortcut. What happens?
- Type the following command: ls
- Press the ctrl-e key combination and press ENTER
- Press the up arrow key. What happens?
- Press the ctrl-u key combination. What happens?
- Press the up arrow key combination, and see what happens when you press BACKSPACE , <ctrl><BACKSPACE> and <ctrl><h>. Why is it important to know those series of key combinations?
- Press the ctrl-u key combination to clear the line.
- Press the ctrl-l key combination. What happens? What is the advantage of using this key combination then issuing the clear command?
Part 2: Performing Online Assignments
You are required to perform 3 online assignments during this course. This online assignment is used to teach and reinforce Linux commands are techniques as well as using Linux commands to perform tasks and tests students on their knowledge of issuing Linux commands.
In this section, you will learn to select the correct section for your online assignments, how to perform the first two sections of assignment #1, how to verify that you successfully completed both sections, and how to exit your online assignment #1.
Perform the following steps:
- In your Matrix account, issue the following command:
~uli101/assign1 - A screen similar to the one displayed on the right will appear.
WARNING: You need to select the CORRECT section for the course which you belong to.
If you do NOT select your correct section, your assignment may not be recorded for marks! - Select the letter(s) corresponding to the correct ULI101 section and professor and press ENTER
- After you have selected your course section, There will be a screen that provides several important notes before proceeding.
Please take a few moments to read those notes and press ENTER to proceed. - The assignment main menu will then be displayed.
NOTES:- Near the bottom of the window, you will see "You are currently registered to" followed by the section letter and instructor name. Double-check your course timetable to confirm that this the correct section letter. If you have selected the WRONG section, type C in the menu selection area and press ENTER. You will return back to the original window to select your correct course section.
- Near the top of the window displays the sections to complete in the assignment. You are NOT required to complete all sections at the same time. You can check the assignment #1 link on the ULI101 main WIKI page to note the due date for assignment #1. Sections that are NOT completed will be displayed in reverse text with a blue background. On the other hand, when you compete a section, then the section will appear as regular text
(i.e not in reverse text). - If you want to verify that you have completed sections for the assignment, look for the text "Marks earned so far for ULI101 Assignment:" and it will show how many sections have been completed. When it shows all sections completed, then your assignment is finished and you should receive full marks provided that you have selected your correct course section.
- Near the bottom of the window, you will see "You are currently registered to" followed by the section letter and instructor name. Double-check your course timetable to confirm that this the correct section letter. If you have selected the WRONG section, type C in the menu selection area and press ENTER. You will return back to the original window to select your correct course section.
- At the menu assignment #1 window, enter 1 in the menu selection area to begin the first section called "Introduction to Unix Commands".
- When you have completed this section, you will be returned to the main window.
View the contents of this window to confirm that you completed this section. - When you have time this week, enter 2 in the menu selection area to begin the first section called "Basic Unix Commands".
- When you have completed this section, you will be returned to the main window.
View the contents of this window to confirm that you completed this section.
NOTE: Although you are NOT allowed to use reference sheets for course evaluations, it is recommended to create one for your personal use, and write down Linux commands, their arguments and options, so your can successfully perform quizzes, midterm exam, and final exam. - Proceed to the next section to perform additional practice. Linux is about "doing"! The more practice questions you perform, the better mark you will achieve for this course and have a better foundation of issuing Linux commands to be more productive in your future courses.
LINUX PRACTICE QUESTIONS
The purpose of this section is to obtain extra practice to help with quizzes, your midterm, and your final exam.
Here is a link to the MS Word Document of ALL of the questions displayed below but with extra room to answer on the document to simulate a quiz:
https://ict.senecacollege.ca/~murray.saul/uli101/uli101_week5_practice.docx
Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).
Review Questions:
- x
- x
- x
- x
- x
- x
- x
- x
- Create a table listing each Linux command, useful options that were mentioned in the online assignment #1 and command purpose for the following Linux commands: x , x , x , x , x , x , x , x , x , x