Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

00-1.pdf Adobe Acrobat Reader DC dit View Window Help me Tools Lab00-1.pdfx 1 6 The goal of this lab is to introduce the Linux environment

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

00-1.pdf Adobe Acrobat Reader DC dit View Window Help me Tools Lab00-1.pdfx 1 6 The goal of this lab is to introduce the Linux environment and some tools you will use throughout the semester. Read through this tutorial and practice the steps multiple times. Complete the lab by performing the steps in Part VI. Part I - Logging in to the CSE using SSH and SFTP Locate and start the PuTTY application. For the hostname, enter one of the following hosts, making sure the Connection Type is SSH and the Port number is 22. or Se cse01.cse.unt.edu cse02.cse.unt.edu cse03.cse.unt.edu cse04.cse.unt.educse05.cse.unt.edu cse06.cse.unt.edu Co Click Open to connect to the host. You will be prompted for your username and password. This is your EUID usemame and password. Note that your password will not appear as you type. After logging in, you will be at the Linux command line prompt. Do En Now, locate and start the WinSCP application. Click New to start a new session. Like with PuTTY, enter one of the hostnames above into the Host name field, making sure the File protocol is set to SFTP with Port number 22. The username and password is your EUID username password. Once entered, click Login to connect to the server. You now have two applications that will allow you to access the CSE servers. PuTTY is used to access the command prompt so you can perform operations, write scripts, compile and run programs, etc. Win will allow you to transfer files between your computer and the server using drag and drop Part II - Basic Linux Operations Type here to search Tools Lab00-1.pdf x 1 1 6 10696 Part II - Basic Linux Operations isting Directories Listing directories is done using the ls command. Type ls at the command prompt and hit enter to see the files and subdirectories in your directory, which is known as your home directory. You can get more detailed information by using additional options. For example, try the following commands and note the differences . ls-a .ls-al Now try listing files in another directory. Enter the following commands 1s ~dmk0080/public/1040/1abs/zero -l . 1s dmk0080/public/1040/labs/zero/programs -1 You can use the tab key to auto complete when typing a directory or file name. For example, type the last listing command over, but this time, only type the first two letters of a directory name and press the tab key to auto complete. Sometimes you may need to type more than two letters because the auto complete needs enough characters to distinguish from similar names. You can also use the arrow keys, up and down, to scroll through previous commands Creating Directories Type here to search 1.pdf Acrobat Reader DC File Edit View Window Help Home Tools Lab00-1.pdfx 106% Creating directories is done using the mkdir command. To create a directory within the directory you are cuirrently in called tutorial, enter mkdir tutorial at the command prompt and use Is to see the created directory. Try this now: Adob mkdir tutorial 1s Conve or Exc Now create a subdirectory within tutorial called temp. You can do this by changing directories first (changing directories will be discussed next) or by listing the parent directories for the new directory. So for example, try the following. It works by having the system descended into the tutorial directory, which is in the current directory, and then creating the directory temp Select Lab Conve mkdir tutorial/temp Micr .is tutorial . 1s tutorial/temp Englisi tories name will Changing directories is done using the ed command. This command followed by a subdirectory move you to that subdirectory. For example, try .cd tutorial .cd temp You are now in the tutorial/temp directory. The Linux file directory is viewed as a hierarchy in which subdirectories are children of one parent directory. This "one parent has many children relationship" means we can move up to a parent directory without knowing its name. This is done by using . (two O Type here to search r DC ile Edit View Window Help Home Tools Lab00-1.pdf 26 You are now in the tutorial temp directory. The Linux file directory is viewed as a hierarchy in which subdirectories are children of one parent directory. This "one parent has many children relationship' means we can move up to a parent directory without knowing its name. This is done by using.. (two periods) to designate you want to move up one directory in the hierarchy. So if you are in the tutorial temp directory, you can do cd.. to move up to the tutorial directory. Or to get lack to the parent of tutorial, try cd ..// to move from temp, to tutorial, to its parent. Try this from the temp directory cd 1s You can mix them together. For example, ed ./tutorial from the temp directory will move you into the tutorial directory because of the first ../, the next ../ moves you into the parent of tutorial, and tutorial moves you into the tutorial directory. Needless to say, this example is trivial because you could have done it by typing cd/ from the temp directory. The idea is that you can quickly navigate the hierarchy in a single com if you know how it is organized. Some other useful ways to change directories include: Do . c ~ returns you to your home directory. You can build paths using this, e g cd tutorial temp ed - displays the full path from the root to the current directory ed /changes to the root directory of the drive. You can build paths from the root, e.g cd /home/ tutorial/temp Removing Directories and Files Removing directories is done using the command rm. This command actually has two functions: removing directories and removing files, but in order to remove a directory, you have add the-r option. This option does a recursive deletion which will remove the files and subdirectories of the directory you want to remove. So try to remove your tutorial directory using: O Type here to search Lab00-1.pdf Adobe Acrobat Reader DC File Edit View Window Help Home Tools Lab00-1.pdfx 106% rm -r tutorial Note that the removal of files and directories is permanent when using the command line and there ma not be a delete confirmation. There is no recycle bin like in Windows, so make surg you are not deletin something you want to keep Removing files is the same except the -r option in not necessary. Create a file by issuing this command: . touch temp file touch is a utility that changes the file's timestamp: however, if the file does not exist, it will create the file with no contents. If you do the directly listing with -I, you should see the file temp file. You can use the command cat temp file to view the contents of the file, which should be none. Perform a directory listing. try touch temp file again, do a directory listing, and compare the timestamps of temp file. Now remove the file: . rm temp file Copying d Moving Files Copying files uses the command cp. The two parameters needed with the command are the location and filename to copy and destination for the copy. Let's walk through an example that will help you later in this lab. First, make a directory called Tutoriall next, issue this command cp -r dmk0080/public/1040/1abs/zero/* Tutoriall O Type here to search 1.pdf Adobe Acrobat Reader DC File Edit View Win Help Home Tools Lab00-1.pdf x 106% The -r option is a recursive operation that will copy all the subdirectory along with the files selected. In this case, the wildcard character * (asterisk) is used to select all the files. Replacing with a single file name will only copy that one file. So this command will copy everything from the public 1040 lab zero directory to your Tutoriall directory. Now, let's practice copying one file. Change to the Tutorial l directory and do a listing of the files. Copy the file integers to the subdirectory programs. Perform a listing to make sure the file was copied. Also, the wild card character can be used to specify a group of files that have similar names. For example, Is *.txt will list all the files in the direction that end with.txt Adob Conver or Exce Moving a file is almost the same except the command is mv and it will not create a copy. As an example create a file in the Tutoriall directory called move this by typing in the command Select I . touch move this Convert Now, move this file to the programs directory Micro . mv move this programs / 1s English t . 1s programs mv programs/move this ./ 1s mv move this programs/move this2 1s . ls programs/ Con Some notes about copying and moving Type here to search 1.pdf Adobe Acrobat R Edit View Window Help r DC ome Tools Lab00-1.pdf x l. Just as before, you can use the directory hierarchy with directory names and the .. to designate paths for the copy 2. Move and copy can be used to rename files quickly. Copy is particularly useful when programming because you can quickly create a backup version of a program before making changes. For example, this would create a copy of the file under a different name allowing you to have the version 1 backup while you edit helloworld.c ep helloworld.c helloworld v1.c And this would simply rename the file mv helloworld.c helloworld vi.c 3. Files and folders have access permissions. When you do a listing with using Is -1, you can see the ten places that are used to designate permissions for a file. The first place indicates whether it is a directory (d) or a file (). The next three are used to determine the owner permissions which can be read (r), write (w), or execute (x). Similarly, the next three indicate permission for a group that has some access to it, and the last three are access rights for others outside of the group or owner The example below shows a file in which the owner can read, write, or execute the file, but the group can only read or execute it while others can only execute it. The same basic principle applies to This means that the copying and moving of files depend on permissions; for example, you may not be able to copy all the files from another directory to your own. -rwxr- 0 Type here to search Home Tools Lab00-1.pdf x 106% -rwxr-x--X Type User Group Other Do a file listing of -dmk0080/public/1040/1abs/zerol and its subdirectories and compare it to a listing of your Tutoriall directory and subdirectories. Are there any files that were not copied because of the permissions? Part III - Redirection Input and output of many programs in the Linux environment use something called standard in and standard out. This allows you to enter information into a program, typically, by keyboard and to see output on the screen. Actually, you have already experience this with the commands you have been using. For example, when you issued the command cp or mv, the filenames are placed into the copy program as standard in. Redirection allows you to enter data into a program from a file but treated as standard in, or to capture output from standard out into a file. For example, let's use the Linux program sort to sort some integers Find the file integers in your Tutorial1 directory. You can quickly view the contents of this file by using the command cat as shown below cat integers This is a list of unsorted integers. We need to give the sort program this file using standard in. Type here to search Lab00-1.pdf- Adobe Acrobat File Edit View Window Help DC Home Tools Lab00-1.pdfx 5 6 Redirection involves two symbols . direct contents out of standard out and into a file. Trying this with sort, we would issue this command to see the integers sorted (note they are in alphabetical order, not numerical): .sort sorted integers cat sorted integers A final note about these commands and programs: You can use the command man to find out more about these commands and programs as well as many other Linux utilities. For example, try man cp or man mv to find out more information about how these work. You can often receive help on the command by adding the option -help. eg. ed -help. Co Part IV- Compiling a C program The GNU C compiler (gcc) takes C code written in text and produces an executable file. Any file created for this compiler requires the c extension, e.g. helloworld.c, but the file can be created and edited in just about any text editor. The gec compiler requires, at the very least, the e file to compile. For example suppose you have a file called helloworld.c. To compile this on the CSE machines, the command is gec helloworld.c (assuming helloworld.c is in the current directory). The result is an executable file called a.out. In order execute this file in the current directory, you must add./before the file name, i.e. ./a.out, so Linux knows you want to execute it in the current directory. Let's try an example l. 2. Change to the programs directory in your Tutoriall directory. Compile the program dice.c using the gee compiler Type here to search 1 pdf-Adobe Acrobat Reader DC File Edit View Window Help Home Tools Lab00-1.pdfx 106% 1. Change to the programs directory in your Tutoriall directory 4 2. Compile the program dice.c using the gec compiler 3. Run the program and roll the dice 1,000 times: /a.out 1000 Ado You can use control-c to break the execution of a program, which is useful in thel event your program executes out of control. Run the dice program again except with 1,000,000,000 rolls of the dice this time Break the program using control-c while it is still running. Con or Ex You can also name your executable file using the -o option with gcc instead of staying with the default a out file name. For the dice.c program, run these commands Selec 1. 2. gec dice.c-o dice /dice 1000 Conv Part V-Other Useful Information Now that you have a feel for Linux, here are some additional helpful tools and commands. Use man and the internet to read about them and practice. 1. Find out how to copy and paste using PuTTY (this is not a Linux thing, but will be useful when programming.) Find out what pwd does. 2. 3. Find out more about file permissions and the command chmod to change them. Practice this by creating some files and changing the permissions. Also, look into the command chown, which allows you to change the owner of a file, and the Linux file mask. Practice changing owners of a file with a classmate 4. Read about and practice the commands find and grep, and how to pipe commands together using the nine character O Type here to search Lab00-1.pdf Adobe Acrobat Reader DC File Edit View Window Help Home Tools Lab00-1.pdf x 1. rima oui now to copy ana paste usig PUTI (unIs is IIOi a LIIux unmg, uut wl ve useur wnen programming.) 2. Find out what pwd does. 3. Find out more about file permissions and the command chmod to change them. Practice this by creating some files and changing the permissions. Also, look into the command chown, which allows you to change the owner of a file, and the Linux file mask. Practice rhanging owners of a file with a classmate Read about and practice the commands find and grep, and how to pipe commands together using the pipe character: I 4. There are many text editors installed on the CSE machines that will allow you to edit files while connected using PuTTY including vi (or vim), pico, and joe. These editors are often helpful because you can edit your program files right on the CSE machines and often color code your program syntax to make it easier to read. Because they are command line based, they often use unusual shortcut keys to perform operations, but once learned, it can be more efficient than using a mouse. For each of these, at the very least, learn how to open files, save files, delete a line, copy and paste, and how to exit. 5. O Type here to search df Adobe Acrobat Reader DC Hel Tools Lab00-1.pdfx Part VI- Assignment In this section, you will need to perform the following operations. You will have to submit the files so be sure to save them. 1. Create a directory call 2. Copy the files from -dmk0080/public/1040/labs/zero/into your Lab0 directory 3. Manually count the number of files that were not copied and place this in a file named count. 4. Create a copy of integers in the same directory and name this integers vl 5. Create a listing of your Lab0 directory and redirect the output to the file Lab0 listingl 6. Create a listing of your subdirectory programs using redirection and name the file Lab0 listing2 7. Sort the integers using redirection and redirect the output to a file named sorted 8. Submit count, Lab0 listingl, Lab0 listing2, sorted using Blackboard. ed Labo Type here to search

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions