ops102_2_1.pdf
Document Details
Uploaded by VibrantSwamp
2024
Tags
Full Transcript
Matrix, Commands, File Systems OPS102 Week 2 Class 1 Tiayyba Riaz May 5, 2024 Seneca Polytechnic Outline Introduction and How This Course Works Recap From/Upcoming In Week One Connecting to matrix Simple Commands to Start With Hierarchical File Systems Files and Folders Paths: Absolute, Relative, Re...
Matrix, Commands, File Systems OPS102 Week 2 Class 1 Tiayyba Riaz May 5, 2024 Seneca Polytechnic Outline Introduction and How This Course Works Recap From/Upcoming In Week One Connecting to matrix Simple Commands to Start With Hierarchical File Systems Files and Folders Paths: Absolute, Relative, Relative to Home Current Working Directory OPS102 W2C1 - Matrix, Commands, File Systems 1/38 Introduction and How This Course Works Welcome to OPS102 OPS102 – Operating Systems for Programmers An introduction to Linux and Windows For software developers First offered Fall 2023, replacing ULI101 for SDDS students See the official OPS102 course outline OPS102 W2C1 - Matrix, Commands, File Systems 2/38 Course and Mark Breakdown Labs – 20% 10 labs throughout the term Quizzes – 25% 7 quizzes throughout the term, top 5 results are used Mid-Term Test – 25% Week 7, just before the study break Final Test – 30% Final week of the term OPS102 W2C1 - Matrix, Commands, File Systems 3/38 Swapping Weeks 1 and 2 For OPS102 sections ZBB and NCC In calendar week one, I’ll present course week two material In calendar week two, I’ll present course week one material Why? Because I think the week two topics will help you in your other courses (e.g. IPC C Programming) OPS102 W2C1 - Matrix, Commands, File Systems 4/38 Recap From/Upcoming In Week One Recap From/Upcoming In Week One Course introduction and overview Operating system basics, components, and interfaces A bit of history Command line basics A little bit about licensing OPS102 W2C1 - Matrix, Commands, File Systems 5/38 Connecting to matrix Connecting to matrix For your coursework, you will have access to machines running both Windows OS and Linux OS. Most (all?) lab computers have Windows 10 installed on them. Linux is available on a server cluster called “matrix”. All Seneca students get an account on matrix. You will connect with matrix and practice Linux commands. The matrix cluster has been configured to allow users to only interact with the Linux OS using a command line interface (CLI). In the next few slides, you will learn more about matrix and how to connect to it. OPS102 W2C1 - Matrix, Commands, File Systems 6/38 More About matrix The matrix server consists of several computers running “CentOS” (a version of Linux) all working together to form a cluster. I think matrix is a set of virtual machines (VM’s) on HyperV, with a big disk partition on one node, shared via NFS, fronted by some sort of load balancer? A cluster is a cost effective alternative to larger servers. All registered students in this course have access to an account on Matrix. You will be using your matrix account for: practicing Linux commands performing Linux labs reference during quizzes and tests OPS102 W2C1 - Matrix, Commands, File Systems 7/38 More About matrix - the Picture OPS102 W2C1 - Matrix, Commands, File Systems 8/38 To connect to matrix, You Must be “On Campus” The matrix cluster is at Seneca, on the Newnham campus Only very limited access to matrix is allowed from off campus Web access is allowed, but not command line login To access matrix, you must be either On campus, in a lab, or connected to SenecaNet Or, off campus, and connected to the Seneca VPN For information about VPN access, see https://students.senecapolytechnic.ca/spaces/186/itservices/wiki/view/1024/vpn OPS102 W2C1 - Matrix, Commands, File Systems 9/38 Using SSH to Connect to matrix You can connect to matrix from any Seneca lab workstation, or from your personal computer. Since you will be connecting to a remote computer using your login and password, it is important that the connection is secure. We will use ssh (secure shell) to connect to matrix. SSH is a protocol for secure remote login/connection from one computer to another. The ssh command implements the SSH protocol. Applications using SSH provide secure, encrypted communications over a network connection. More on SSH (link): Extra Topics - SSH - week 13 OPS102 W2C1 - Matrix, Commands, File Systems 10/38 Accessing matrix from Windows If you are running Windows 10 or newer versions, you can use Windows CMD window to run the ssh command. Alternately you can download and install a third party SSH client program, such as: SSH Secure Shell Client PuTTY Or see the list at: https://en.wikipedia.org/wiki/Comparison_of_SSH_clients The next two slides show connection to matrix using windows CMD and the third party tool PuTTY. You will use the same user and host names with any SSH client. OPS102 W2C1 - Matrix, Commands, File Systems 11/38 Connecting to matrix from Windows CMD Open a Windows CMD window, and then (in the terminal), type the following command and press the enter key: ssh [email protected] Remember to replace senecausername with your actual username. Type yes and press the enter key for any questions it may ask. On your first connection, it will ask you to confirm the “fingerprint” of matrix – enter yes. Type your Seneca password at the password: prompt and press the enter key. You should see a prompt from bash something like this: [senecausername@mtrx-node01pd ~]$ OPS102 W2C1 - Matrix, Commands, File Systems 12/38 Oh oh! Something Didn’t Work! If you encounter an error message, and don’t get properly logged in to matrix – don’t worry! Read the error message you received. Problems can occur for several reasons: You mis-spelled matrix.senecapolytechnic.ca 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 use to connect to my.senecacollege.ca) OPS102 W2C1 - Matrix, Commands, File Systems 13/38 The Look of Success OPS102 W2C1 - Matrix, Commands, File Systems 14/38 Connecting to matrix Using PuTTY Download PuTTY for Windows from Download PuTTY and run the installer Run the PuTTY command and use the settings: Host Name: matrix.senecapolytechnic.ca Port: 22 Connection Type: SSH and click Open A terminal window should pop up, asking you to confirm the matrix signature, and then asking for who to login as (your username) and then your password. OPS102 W2C1 - Matrix, Commands, File Systems 15/38 The Look of PuTTY - Part 1 OPS102 W2C1 - Matrix, Commands, File Systems 16/38 The Look of PuTTY - Part 2 OPS102 W2C1 - Matrix, Commands, File Systems 17/38 Connecting to matrix from MacOS In Finder window, open Applications > Utilities > Terminal And then continue the same as in Windows CMD on slide 16 ssh [email protected] On a Linux machine? Same thing. OPS102 W2C1 - Matrix, Commands, File Systems 18/38 Remember to Log Out! When you’re finished on matrix, remember to log out Don’t just close your terminal window Use the exit or logout commands to disconnect from matrix You can also use ctrl-D to exit – why? Because ctrl-D means “end of file” See the linux man page for ASCII: man ascii Why exit cleanly? To help make sure you haven’t left anything running. OPS102 W2C1 - Matrix, Commands, File Systems 19/38 Simple Commands to Start With The Command Prompt Command line interfaces almost always start each line with a “prompt string” before waiting for you to type a command. The prompt will often contain useful information But usually in a terse format So as not to use a lot of space on the line OPS102 W2C1 - Matrix, Commands, File Systems 20/38 Linux Default Command Prompt A common default bash shell prompt string: tiayyba.riaz: username of the current user mtrx-node04pd: local name of the computer ∼: shorthand for the user’s home directory Every user has a default “home directory” (default folder) $: a dollar (or percent) sign indicates a normal user #: a hash or number sign indicates administrator permissions (“root” permissions) OPS102 W2C1 - Matrix, Commands, File Systems 21/38 Windows CMD Default Command Prompt The standard Windows CMD prompt string: C:\Users\tiayyba.riaz: Indicates the current directory In this case, the home directory of the user “tiayyba.riaz” Home directories are usually named for the user’s username Both Windows and Linux allow you to set your prompt to (almost) anything you want. OPS102 W2C1 - Matrix, Commands, File Systems 22/38 General Linux and Windows Commands Now that you have successfully connected to matrix, and you also have access to Windows CMD, let’s look at some basic commands: Windows Linux Description echo echo Print something on the screen cal Display calendar date /t date The date command in Linux shows date and time. quser who Prints information about the currently logged in user(s) (quser – Windows server only) whoami whoami Prints name of current user cls clear Clears the terminal screen and shows prompt in first line tree tree Shows the folder (and file) hierarchy in tree format dir ls List information about files/folders OPS102 W2C1 - Matrix, Commands, File Systems 23/38 Hierarchical File Systems File Systems A file system is a method of organizing and retrieving files efficiently from a storage medium e.g a hard disk. Both Linux and Windows use hierarchical file systems Files are organized in folders and subfolders The original (pre-GUI) name for folders is “directories” In Windows File System, the hierarchy starts from drives: C, D etc There are no drive letters like C, or D in Linux In Linux, The topmost directory is the root (/) All files and directories appear under root Windows has a per-drive root directory e.g. C:\ OPS102 W2C1 - Matrix, Commands, File Systems 24/38 File Systems in Pictures OPS102 W2C1 - Matrix, Commands, File Systems 25/38 Files and Folders Files and Folders (Directories) Virtually everything in a modern computer system is a file or a folder Folders, like their real-world counterparts, are containers that can have files and other folders (called sub-folders). Some Examples: Home folder Desktop folder Root Folder Files are used to save user data (or any data) in them Files can be of many different types, for example: Word DOC document file C programming language source file Compiled object code file sqlite database file OPS102 W2C1 - Matrix, Commands, File Systems 26/38 Files and Folders (Directories) - cont’d Types of files are identified from their extensions – the 3 or 4 last characters after a period/dot. Examples:.docx – Microsoft Word documents.exe – an executable program on Windows.txt – a text file You need a specific program or application to open each file. Windows examples: Notepad program opens a.txt file MS Word opens a.docx file You can use an image viewer program (like MS Paint) to open.png or.jpg files If your system does not have a required program for a particular file type, you cannot open that file properly. File extensions are less important on Linux, and not used on MacOS. OPS102 W2C1 - Matrix, Commands, File Systems 27/38 File and Folder Names Before learning to create directories, it is important to understand what represents an appropriate filename. Here are some guidelines: Unix/Linux is case sensitive! Windows is not case sensitive for file names. Adopt a consistent file naming scheme – this will help you find your files later. Make your file and folder/directory names meaningful. Avoid non alphanumeric characters, as they may have a special meaning to the system that will make your work more difficult. Avoid using spaces in file names – consider periods, hyphens, and underscores instead, spaces in file names can lead to inconsistent results while working in command line interface. More later about other special characters to avoid. OPS102 W2C1 - Matrix, Commands, File Systems 28/38 Linux Hierarchical File System A standard Linux distribution follows a directory structure like this: OPS102 W2C1 - Matrix, Commands, File Systems 29/38 Linux – Standard Directories Common top-level directories that you should be aware of: Directory Purpose / Root, top of file system hierarchy /bin Common system binaries (commands) /home Contains users’ home directories /usr This is called “user”, where user related programs live /usr/bin Common utilities (commands) for users /usr/sbin Common utilities for system administration /etc System configuration files (eg. passwd) /var Dynamic files (log and mail files) /tmp /var/tmp Temporary files for programs /dev Device driver files (terminals, printers, etc) /opt Additional installed application programs OPS102 W2C1 - Matrix, Commands, File Systems 30/38 Paths: Absolute, Relative, Relative to Home File and Directory Paths A path specifies a unique location of a file or directory in the file system. The file system location is found by following the directory tree hierarchy. A path is written as a string of characters in which directories are separated by the path separator: a (forward) slash “/” in Linux and MacOS, or a backslash “\” in Windows. There are multiple ways of specifying pathnames Absolute pathnames Relative pathnames Relative to home pathnames Examples /home/cory /home/jono/work C:\Users\Natali OPS102 W2C1 - Matrix, Commands, File Systems 31/38 Pathname Types Absolute pathname: A full pathname that starts from the root of the hierarchy. Examples: /home/jones/Desktop/paris.jpg D:\Trips\Paris\Louvers\ Relative pathname: A pathname that does not start with a slash is a relative pathname, and is interpreted relative to the current directory. Example (the argument to cat is relative to CWD): [jane@machine: /home/jane/Documents/]$ cat./Math/marks.txt Relative to home pathname – on Linux/Unix a tilde (“∼”) is used as a shorthand for the user’s home directory. Example: from anywhere show the contents in Documents folder [jane@machine: /var/log/]$ ls ~/Documents/ OPS102 W2C1 - Matrix, Commands, File Systems 32/38 Current Working Directory Current Working Directory Current working directory is the folder/directory where you are working at a given time. If you are viewing Documents folder in file explorer, then Documents is your current working directory If you are viewing pictures from your Photos folder, then Photos folder is your current working directory Current working directory is a more important concept, when you are interacting with your system through a command line interface. Whenever a user opens a terminal, their home directory is their current working directory. We can navigate in the file system and change our current working directory any time using the cd (change directory) command (Linux and Windows). OPS102 W2C1 - Matrix, Commands, File Systems 33/38 Changing the Current Working Directory In a CLI, we use the command cd to change our current working directory. The argument can be any type of path (absolute, relative or relative to home). Examples of cd in Linux cd /bin change directory to "/bin" cd change directory to your home directory cd ∼ change directory to your home directory cd.. Change to parent directory OPS102 W2C1 - Matrix, Commands, File Systems Examples of cd in Windows cd D:\Courses\OPS102 change directory to "D:\Courses\OPS102" cd display current directory cd.. Change to parent directory 34/38 Listing the Contents of a directory Often you would need to list the contents of a directory when you are working in CLI. In Linux, the command ls is the most commonly used command to display a list of files and subdirectories in the current directory or of any other directory. The equivalent command in Windows is dir Examples of ls in Linux ls List the contents of current directory ls /bin List the contents of /bin OPS102 W2C1 - Matrix, Commands, File Systems Examples of dir in Windows dir List the contents of current directory dir D:\ List the contents of D drive 35/38 Checking File Types in Linux with ls Use ls -l (detailed listing) and the first character indicates the file type: OPS102 W2C1 - Matrix, Commands, File Systems 36/38 Checking File Types in Linux with ls - cont’d Character b or c d l p s Meaning a regular file a device special file a directory a symbolic link (like a Windows shortcut) a named pipe, for inter-process communication (IPC) a Unix domain socket, also for IPC OPS102 W2C1 - Matrix, Commands, File Systems 37/38 Summary Introduction to matrix and SSH Some simple commands Hierarchical file systems Files and folders (directories) Pathnames – absolute, relative, relative to home Current working directory, and directory contents OPS102 W2C1 - Matrix, Commands, File Systems 38/38