430 likes | 523 Views
Interacting with a UNIX computer in the MathCS Lab: Listing the content of directories. Introduction. The computers in the MathCS lab are using the UNIX Operating System Most students have not used a computer that is controlled by the UNIX Operating System. Introduction (cont.).
E N D
Interacting with a UNIX computer in the MathCS Lab: Listing the content of directories
Introduction • The computers in the MathCS lab are using the UNIX Operating System • Most students have not used a computer that is controlled by the UNIX Operating System
Introduction (cont.) • It is extremely important that you attend all labs • If you don't understand some part of the lab, please ask the Teaching Assistant for help They are paid to explain the material to you; so take advantage of this service. • The labs is an essential part of the course and supplements the lecture materials that are best taught hands on (such as the material in this webnote) • If you miss a lab, make sure you do (most) the lab on your own before coming to the next lab And if you don't understand some part of the lab, ask the Teaching Assistant for help during the next lab • Important notice:
Log in • Log in procedure: • Use your Emory ID as ID • Use your Emory password as password
Log in (cont.) • After a successful login, you should see a desktop that look something like this:
Log in (cont.) (You can see a larger picture by clicking here: http://192.168.1.3/~cheung/teaching/web/170/Syllabus/02/FIGS/solaris-desktop01.png) The (white) window in the center of the desktop is a Terminal application This is a UNIX "shell" program that allow you to interact with the computer through command lines typed from the keyboard
Launch a new "Terminal" app with Launch bar • To launch another Terminal application, do the following: • Left click on the Launch button in the lower left corner of the desktop • Left click on the Application entry • Left click on the Utilities entry • Finally, left click on the Terminal entry
Launch a new "Terminal" app with Launch bar (cont.) Graphically: (You can see a larger picture by clicking here: http://192.168.1.3/~cheung/teaching/web/170/Syllabus/02/FIGS/solaris-desktop02.png)
Launch a new "Terminal" app with Launch bar (cont.) • Result:
Launch a new "Terminal" application from a Terminal window • To launch another Terminal application using a command line (that must be entered in a Terminal window), type the following command in a Terminal window: and hit the ENTER key • gnome-terminal
Launch a new "Terminal" application from a Terminal window (cont.) • Graphically:
Lab exercise • Perform this task now: • launch a terminal
Directories and their usage • A directory is a computer folder that can contain (hold): • Files are electronic documents that contain information • Directories are electronic folders that let the user organize his files • files • (other) directories
Identifying a directory • We need to identify a directory before we can perform an operation (like delete) on the directory. (There is a need to identify things stored inside a computer uniquely. Just like using Social Security Numbers to identify people uniquely) • The mean to identify a directory unique inside a UNIX file system is: • a directory path
Identifying a directory (cont.) • There are 2 kinds of directory paths: We will explain the absolute directory path here and discuss the relative path later. • Absolute directory paths • Relative directory paths
Concept: absolute directory path • Absolute directory path: • An absolute directory path tells the computer how to find a directorystarting from the root directory • An absolute directory path of a particular directory x consists of a list of directory namesstarting from the root directory "/" to the directory x • The list of directory names is separated by the "/" symbol
Concept: absolute directory path (cont.) • Example 1: • The directory path for the highlighted directory is: • /bin
Concept: absolute directory path (cont.) • Note: • The exact path should be: "//bin". • The first "/" is the symbol for the root directory. • The second "/" is a separating "/" symbol. • The root "/" (the first "/") can be omitted for brevity
Concept: absolute directory path (cont.) • Example 2: • The directory path for the highlighted directory is: • /home/bin
Concept: absolute directory path (cont.) • Example 3: The directory path for the highlighted directory is: • /home/km/bin
Concept: absolute directory path (cont.) • Some facts: • There may be multiple directories with the same name (but not inside the same directory) • An absolute directory path will uniquely identifyone particular directory. (In fact, the absolute directory path is the "official" name of a directory) • An absolute directory pathalways starts with the symbol / • A directory path is case-sensitive
Concept: the home directory • Each user in UNIX is assigned a unique user ID • Each user in UNIX is assigned a home directory (folder) where he/she can store his/her files. • The (absolute) directory path of the user with the user ID "X" is: Example: • /home/X The home directory of Prof. Mandelberg whose user ID is km is: /home/km
Reminder: how to make a computer do things for you • Running (executing) a program (that contains the machine instructions that accomplish the task) • We make a computer do a task (for us) by: • Also • People have written downcomputer programs (applications) to do frequently performed tasks • Some well known computer applications: • Web browser (e.g., Internet Explorer) • Editor (e.g., Microsoft Word) • and so on...
Reminder: how to make a computer do things for you (cont.) Now it's time to learn to use some of these applications to become a skillful computer operator
Tasks that are performed very frequently • Operations on directory (folder): • Frequently performed tasks: (you will practice these in Lab 1) • Print the path of the current (working) directory • List the content of a directory • Navigate the directory tree • Create a directory • Delete a directory • Rename a directory • Move a directory to somewhere else
Tasks that are performed very frequently (cont.) • Operations on files • Print a file out to the terminal • Delete a file • Rename a file • Move a file from one directory (folder) to another directory (folder) • Create a file must be done through an editor application which will be explained in a later lab
Tasks that are performed very frequently (cont.) • You will be executing a computer program to perform each of the task above • Some times, you will be executing the same program to do different tasks • (Because some programs are like a Swiss army knife that can do many different tasks) • Remember: • We will also need to learn some concepts (and terminology) associated with these tasks
Prelude to the examples • The concepts and command are illustrated from the user with user ID cheung (That's because Prof. Cheung has developed this course material)
Prelude to the examples (cont.) • The directory structure that is relevant to the example is as follows:
Prelude to the examples (cont.) This is what you would see when you browse the /home/cheung/cs170 directory:
Prelude to the examples (cont.) • Some facts about the user "cheung": • absolute path of his home directory = /home/cheung • There is a directory named cs170 inside the home directory
Concept: Current directory (a.k.a. working directory) • Computer applications often uses information (= data) stored in some file Files in a computer systems are stored in some directory • Every computer application has a working directory (= the directory where the application is working in)
Concept: Current directory (a.k.a. working directory) (cont.) • Print the path of the current (working) directory: • The application that instruct the computer to print the path of the working directory is: • pwd
Concept: Current directory (a.k.a. working directory) (cont.) • You can run this application from a Terminal window by typing in the name of the application Example:
Task: List the content of a directory • The command (= application) that is used to list the content of a directory: (ls is an abbreviation of the word list) The ls command (application) will list the names of the files and the directories stored in the specified directory in alpha-numerical order Note: ls DIRECTORY-PATH • The ls command will give you the same information as a file browser (such as "Window Explorer" on a PC)
Task: List the content of a directory (cont.) • Example 1: " ls /" --- give the list of directory and files stored in the root directory / Browsing the directory with a File Explorer Output of the ls command
Task: List the content of a directory (cont.) • Example 2: " ls /etc" --- give the list of directory and files stored in the directory /etc Browsing the directory with a File Explorer Output of the ls command
Listing vs. Browsing a directory: • Browsing is slow (You need to click a lot before you can reach the desired directory that you want to browse) I can type in a directory path a lot a faster than I can click... • Browsing produce a nicer output (If you become a Computer Scientist, you will learn that only information matters, not a nicer look) • Bottom line: geeks prefer the speedier directory listing method
Concept: Relative directory paths • Suppose Prof. Cheung wants to list the content of the cs170 directory in his home directory He would execute this command: ls /home/cheung/cs170
Concept: Relative directory paths (cont.) Example: Browsing the directory with a File Explorer Output of the ls command
Concept: Relative directory paths (cont.) • If the current directory is his home directory (/home/cheung), then he can use a shorter form by using a relative directory path • Relative directory path: • An relative directory path tells the computer how to find a directorystarting from the current (working) directory • An relative directory path a particular directory x consists of a list of directory namesstarting from the current directory to the directory x • A relative path does not start with the "/" symbol • (If a path starts with a "/" symbol, it is assumed to be an absolute directory path) • The list of directory names is separated by the "/" symbol
Concept: Relative directory paths (cont.) • Suppose that current directory = /home/cheung • I want to list the content of the directory /home/cheung/cs170 • Starting from /home/cheung, the relative path to the directory /home/cheung/cs170 is: • We need to add the blue part (/cs170) to get to the target directory • So we use this command to list the cs170 directory: • Example: /home/cheung/cs170 ls cs170
Concept: Relative directory paths (cont.) • Actual execution: