Please check your LL2a/LL2b grades
Linux Labs must be done in order and labs cannot be skipped. To this extent, please check your grades to make sure your LL2a and LL2b were correct and accepted. If they were not correct and accepted, please see the assessment notes and correct and resubmit prior to beginning this lab (errors will propagate to later labs causing them to be incorrect and not accepted so we must correct incorrect earlier labs 1st).
Required Reading
As always, please review previous reading and LLs as necessary and read both the Linux Command Line chapter reading identified below and this lab in advance prior to beginning.
The Linux Command Line by Shotts – 1.3, 1.4, 1.5
Assignment Submission Directions
As in the previous assignments, you will access the HVCC Acadnx environment and take periodic screenshots of your terminal as directed below and paste the screenshots into a single LastnameFirstnameLL3 pdf document, 1 screenshot per page with the proper headings (ex. for me I would submit LoobyJamesLL3.pdf and each screenshot would have the exercise number). If you fail to follow this file naming convention your assignment will not be accepted.
Please use the Linux “clear” command where instructed and please try to take a picture of just the CLI/Shell so that the font isn’t very very small. If you fail to clear your screen where directed your assignment will not be accepted.
I expect that everyone will make mistakes from time to time and to this extent I do not need perfect, flawless, error-less screens for assignment submission. Per previous labs this is part of the learning process as we need to see the Linux error messages so when you make a mistake, please just correct your mistakes and ensure that the exercise goal is met with your screenshots. Note correcting mistakes often requires rereading and again students are responsible for reading the lab in its entirely prior to beginning work on the submission. Please understand we are learning the processes necessary for success in this discipline.
Also, please resize/expand/enlarge your Terminal window but note that while the screenshot may not capture every command you have entered, it will demonstrate your present state and that is all that is necessary.
If you need assistance I am of course available but should you need remote assistance, please specify the exercise number and include screenshots and good descriptive narrative as getting and providing help is also an educational endeavor. Please understand this is a discipline wide requirement as information must be complete, accurate, timely and relevant.
Please note the above instructions will be standard for the rest of the course.
Intro ScreenShot
Open or launch your SSH application (e.g. Mac Terminal or Win PuTTy or Chrome SSH extension). Please resize your Terminal to make it larger to capture as much as possible but note you may not capture everything and this will be fine. If possible please take a screenshot/picture of your open terminal as if you include other items the text in the Terminal can be very small making it harder for me to see your commands (Windows snipping tool here). Paste this screenshot into your correctly named pdf document and label or title this screenshot “Intro Screenshot”.
Review and setup
First (as always) we need to both practice our commands from the last lab and confirm that everything is correct. To ease this note the tables with Linux commands at the bottom of each lab and you should do this each lab or each time you login. Note this implicitly requires that students understand the distinction between commands, options and arguments as it is impossible to learn if we do not know base definitions.
Upon logging in, in your home directory, please perform a listing, a long listing and a complete listing showing all files. If you cannot do this you need to read more and review LL2a/LL2b. Now you should only have your ciss100 directory in your home directory displayed with a simple listing (not a complete listing that shows all files).
Next change directories to the ciss100 directory and perform a listing and a complete listing. You should see your FirstnameLastname subdirectory. I specify the complete listing here so that you see and understand the difference between the . directory and the .. directory. If you do not understand this please review the reading.
Next change directories back to your home directory and then change directories directly (single command) to your ciss100/FirstnameLastname directory. For me this would be $ cd ciss100/JamesLooby. Perform a ls in your FirstnameLastname subdirectory as this should be empty. If it is not, please remove any files or directories and then change directories back to your home directory to begin the lab.
3.1 Copying Files
cp (copy)
cp file1 file2 is the command which makes a copy of the source file1 in the current working directory and calls it the destination file2 also located in the current working directory. Note we can copy to and from elsewhere by providing the correct path (i.e. directory path and we can even use the single . as introduced in a previous LL). cp can be used to back up files by providing a .bak extension in the destination file. Also for completeness, to firmly establish correct terminology, cp is a Linux command whereas file1 and file2 are arguments as the Linux creators had no idea what filenames you will have and use in your system. The cp command requires a source file and destination.
3.2 vim Editor
First, we need to get a file to copy and we need to get acquainted with a basic text editor for future work so let’s get started with the vim editor using the following commands in the Terminal (of course this requires that you start the Terminal by connecting via SSH). Please recall I will use the standard pound sign or hash tag for inline comments and it is not necessary to type these comments on the command line. In your home directory enter the following:
$ vim lastnamefirstnameL.txt
Note this creates a .txt file not the file you will submit ( please note the single L as this is an intentional error that we will correct later. Therefore for me I am creating loobyjamesL.txt).
Now type i to enter vim’s insert mode
Type “Lastname Firstname” on the first line (using your last and first name without the delimiting quotes) and [Enter] to move to the next line
Type “Testing testing testing” on the second line and [Enter] to move to the next line
Type/count from 0 to 40 on subsequent lines with 1 number on each line beginning at 0 (i.e. type 0 and [Enter] moving to the next line, type 1 on the next line and [Enter] moving to the next line, 2 on next line… etc. all the way up to 40). We do this so we can have 41 lines as we will need these 41 lines in subsequent labs. Again this is 0-based counting as computers begin counting (and addressing) at 0 (i.e. range is 0-40 with one number on each line but the total number of numbers is 41).
Type “End testing” on the last line.
Now use the esc key to enter vim’s command mode and type :wq to save and quit vim (Note, if you are doing this in a Virtual Machine rather than the HVCC AcadNX server, you may have to hit ctrl-esc.). Also note you can reenter vim using the commands above, the letter i will place you in insert mode and esc followed by :wq will write the file and quit vim).
Now why use an archaic non-graphical editor? When a Unix/Linux system first comes up, you may not have a graphical editor and you may need to perform tasks to get the system up and running. Also, by default, servers may not have a GUI for both security and efficiency. For your reference, and should something go wrong, vim documentation is located here: http://www.vim.org/ noting when something goes wrong we in Comp Sci research to resolve. Note vim is an extension of vi (i.e. we could have done this with vi and this is a viable option if you are having network difficulties) and Unix/Linux also provides the sed and ed editors in a basic non-graphical implementation.
Now let’s perform a directory listing to see our file and note the color coding of files and directories so enter the following:
$ ls # recall we can get a lot more information using ls -la
As I will repeatedly recommend, perform a ls after nearly every file or directory command to verify success and directory contents. This includes when you create a file or directory or when you navigate (e.g. if you change directories, immediately perform a ls to see what’s there and pay attention to your prompt to identify the path and see where you are).
Ok, now let’s copy the file by providing a new name, i.e. lastnamefirstnameLL.txt
$ cp lastnamefirstnameL.txt lastnamefirstnameLL.txt
You should perform a ls to check your work to see that the file was copied correctly. Note, I will not repeat this again as you should perform a ls whenever you create or delete files/directories or change directories to verify your actions were successful.
Continuing on:
Now let’s copy this renamed file to our ciss100/FirstnameLastname subdirectory. There are two ways to do this:
1. We can cp the file to a subdirectory by providing the correct path or
2. We can navigate to the subdirectory and then copy the file to our present working directory.
We will choose the latter so first we have to navigate to ciss100/FirstnameLastname (for me this is ciss100/JamesLooby and note the home directory is implicit) so enter:
$ cd ciss100/FirstnameLastname# you can use the pwd command to verify where you are
Note that we could have changed directories in 2 separate steps, 1st cd to ciss100 and then cd to your FirstnameLastname subdirectory.
Now let’s copy the renamed lastnamefirstnameLL.txt file (for me this is loobyjamesLL.txt) so enter the following:
$ cp ~/lastnamefirstnameLL.txt .
Don’t forget the dot (.) at the end recalling the dot means the current directory and there is a space between .txt and the dot (.) but you should have known this from your readings and research. If you did not notice this or understand this, this is a clear sign that you are not researching the commands enough and this will result in problems in the future. Also recall the ~ is our home or top level directory of our user space so this copied the file from your home directory to your present directory.
Now as I introduced above, I could also have copied the file from my home or top level directory by issuing the following command: $ cp loobyjamesLL.txt ciss100/JamesLooby. In this case my pwd was my home directory so I simply specified the source file and the destination directory.
Also note that I can rename the file whenever I copy it by providing a new file name so the command $cp loobyjamesLL.txt ciss100/JamesLooby/LL.txt would copy the loobyjamesLL.txt file to the ciss100/JamesLooby subdirectory and rename the file LL.txt
Exercise 3.2 – Navigate to your ciss100/FirstnameLastname subdirectory (for me this would of course be ciss100/JamesLooby). Create a backup of your lastnamefirstnameLL.txt file by copying it to a file named lastnamefirstnameLL.ba and then perform a print working directory command and a long listing. Take a screenshot and paste it into your assignment submission file with the correct heading (i.e. exercise 3.2). Note the backup extension misspelling (i.e. .ba rather than .bak) was intentional as this will be corrected later.
Please clear your screen after taking your screenshot and before continuing.
3.3 Moving files
mv (move)
mv file1 file2 #moves (or renames) file1 to file2
To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two.
The mv command can also be used to rename a file, by moving the file to the same directory and giving it a different name.
Let’s use the mv command to correct our previous mistake. Navigate to your ciss100/FirstnameLastname directory if you have changed directories and let’s correct our spelling mistake above and rename the lastnamefirstnameLL.ba file lastnamefirstnameLL.bak.
$ mv yournameLL.ba yournameLL.bak
Excercise 3.3 – Perform a long listing, take a screenshot and paste it into your submission document with the correct heading. Note you can now correct filename spelling mistakes and everyone makes fat finger mistakes.
Please clear your screen after taking your screenshot and before continuing.
3.4 Removing files and directories
Please clear your screen before continuing.
rm (remove), rmdir (remove directory)
Exercise 3.4 – Please navigate to your home directory and remove the lastnamefirstnameL.txt and lastnamefirstnameLL.txt files you originally created using the rm command. Please perform a print working directory and a complete listing and then take a screenshot and paste it into your submission file with the correct exercise heading.
Please clear your screen after taking your screenshot and before continuing.
3.5 Clear #already covered
clear (clear screen)
Before you start the next section, you may like to clear the terminal window of the previous commands so the output of the following commands can be clearly understood.
At the prompt, type
$ clear
This will clear all text and leave you with your prompt at the top of the window.
3.6 Wildcards – the characters * and ?
The character * is called a wildcard, and will match none or more character(s) in a file (or directory) name. For example, in your ciss100/FirstnameLastname directory type
$ ls P*
Did you find anything? Do you know why? Think about what P* will return.
Now type ls with the first letter of your lastname followed by a star. For me, my last name is looby so this would be:
$ ls l* #it finds my loobyjamesLL.txt file
Again you should not be typing comments in. If you do not know what a comment is you have received notice you are not reading enough or in sufficient detail.
The character ? will match exactly one character so ls ?ouse will match files like house and mouse, but not grouse.
Beware – be very careful if using the rm or rmdir command with a wildcard as rm * could be disastrous deleting your entire file system but the wildcard can assist working with/removing a file/filename with spaces noting Linux does not allow spaces in filenames.
Exercise 3.6 – Please navigate to your home directory and take a screenshot and paste it into your document and as always, provide the Exercise 3.6 heading to the screenshot.
Please clear your screen after taking your screenshot and before continuing.
3.7 Filename conventions
Please clear your screen before continuing.
We should reinforce here that a directory is merely a special type of file. So the rules and conventions for naming files also apply to directories.
In naming files, characters with special meanings such as / * & $ , should be avoided. Also, avoid using spaces within names. The safest way to name a file is to use only alphanumeric characters, that is, letters and numbers, together with the _ (underscore) and . (dot). My preference is camel case notation and you should know what this is by this point.
File names conventionally start with a lower-case letter, and may end with a dot followed by a group of letters indicating the contents of the file although Linux does not manage extensions to the same extent as Windows and Mac OS (less management improves OS efficiency). For example, all files consisting of C code may be named with the ending .c, for example, prog1.c . Then in order to list all files containing C code in your home directory, you need only type ls *.c in that directory.
Beware: some applications give the same name to all the output files they generate. For example, some compilers, unless given the appropriate option, produce compiled files named a.out. Should you forget to use that option, you are advised to rename the compiled file immediately, otherwise the next such file will overwrite it and it will be lost.
3.8 Getting Help/Documentation
man – We already introduced this but for completeness, there are on-line manuals which give information about commands, programs, utilities and system configuration files. The manual pages tell you which options a particular command can take, and how each option modifies the behaviour of the command. Type man command to read the manual page for a particular command. For example, to find out more about the wc (word count) command, type
$ man wc
By default the man pages are shown though the less command so we can move forward and backward through the file’s presentation. You may search for a word using the / character followed by the word (‘n’ will search for next occurence and ‘N’ will search for previous instance).
info – the info command provides broader information than man.
whatis – gives a one-line description of the command, but omits any information about options etc. As a result this provides a nice quick intro of the command so try this
$ whatis wc
apropos is used when you are not sure of the exact name of a command so apropos keyword will give you the commands with “keyword” in their manual page header. For example, try typing
$ apropos keyword
Now try
$ apropos copy # zowie hunh 🙂
Exercise 3.8 – Take and paste a screenshot into your submission document and no matter how big your terminal screen it is likely that the screenshot won’t capture everything but that’s ok.
Please clear your screen after taking your screenshot and before continuing.
3.9 Links (Please reread text on links ~page 32)
In Linux there are 2 types of links, hard links and symbolic or soft links. Both types allow you to link to files (recall Linux treats directories as files so links to directories can also be made). Since links are treated as files they can be operated on as files (i.e displaying linked contents, accessing properties, removing them, etc.). Also recall there are only files and processes in Linux). Hard links are typically only used by Sys Admins so we will focus on symbolic/soft links and we will need this knowledge in the final projects. Essentially a soft link creates a pointer (hence symbolic) to a file or directory and you see these in other OSs. The symbolic link format is as follows:
ln -s filename linkfilename
This creates a soft link named linkfilename to the original filename. Another way to think about or remember this is you are creating a link between the source file (filename in this example) and the destination file/link you are creating (i.e. the link or linkfilename in this example) => ln -s sourcefilename linkedfilename.
Now most often we will create links to files throughout the file system so the filenames and linkfilenames will probably include paths as follows:
ln -s /path/filename /linkpath/linkfilename
This creates a soft link named linkfilename in the linkpath to the original file /path/filename. Phrasing it slightly differently, you create a soft link which is a file (albeit a special type of file that points to another file or directory) which in this case, points to a specified file or directory within your filesystem. Note that the existing file and the path must exist and be precisely entered otherwise you will create a broken link which will have to be removed and recreated properly. To this extent, you should always verify the existence of the path and file using listings before creating the link or after if the link shows up as a broken link. To remove a broken link please recall how you remove a file since the link is a special type of file.
One last note, please note the above example paths begin with a / or in the root directory as we have covered this. If you did not catch this you should realize you are not reading/rereading with the exacting precision necessary for success in this discipline.
Continuing on: please remove the lastnamefirstnameLL.txt in your home directory if you did not do so already so: cd ~, then rm this file and verify it is gone with a ls – l. (Again, you should be using listings liberally after every file/directory creation/deletion command to verify results and to see the link properties you will need to perform a long listing.)
Now let’s create a symbolic link to your ciss100/FirstnameLastname/lastnamefirstnameLL.txt file with a similar name in your home directory so please perform the following:
$ ln -s ciss100/FirstnameLastname/lastnamefirstnameLL.txt lastnamefirstnamelink.txt
Now if this didn’t work and you received a failed to create… file exists error message, perform a listing and see if an ambiguity in the namespace exists (i.e. a file by the same name still exists in your home directory). If this is the case you did not read the instructions above carefully enough and you are moving too fast. Note you will also see a broken link displayed in a different color (usually red or blacked out).
When complete you should also perform a ls to see that the linkfile was created and you will note it is probably displayed in a different color font. If you see the file in a blacked out box or a red font you made a spelling error and linked to a non-existent file. To resolve any of these errors, please reread the material and retrace your steps above to properly remove the file and create the correctly linked file.
If you need help I will need screenshots of directory listings that include all relevant directories you are working with (i.e. your home directory, your ciss100 subdirectory and your FirstnameLastname directory) and the required narrative about what your issue is.
Exercise 3.9 – Please perform a long listing in your home directory(noting the new entry and the symbolic links representation/coloring) and take and paste a screenshot into your submission document and no matter how big your terminal screen is you won’t capture everything but thats ok.
Please clear your screen after taking your screenshot and before continuing.
Now I get tired of changing directories and including the full path each time (as an example $ cd ciss100/JamesLooby) so let’s create a symbolic/soft link in our home directory to our ciss100/FirstnameLastname subdirectory and call this directory myStuff. For me I would do this as follows but you will substitute your path name:
$ ln -s ciss100/JamesLooby myStuff
Now let’s test it so 1st perform a ls to see if it is present and correct (correct color).
Now let’s change directories using the linked directory and perform a listing to see the directory contents.
$ cd myStuff
$ ls
Is this the same contents as your ciss100/FirstnameLastname directory? Please verify by navigating (changing directories) to your home directory and then navigating to your ciss100/FirstnameLastname subdirectory using the actual path (i.e. not the myStuff link). When you have verified this please proceed to exercise 3.10.
Exercise 3.10 – (1) Please perform a long listing in your ciss100/firstnameLastname subdirectory to verify the contents, (2) then change directories to your home directory and perform a long listing and (3) then perform a long listing of your myStuff directory from your home directory. Please take a screenshot and paste into your assignment appropriately.
Please check your links (they should be valid meaning they are not red) and if everything looks good, please submit your properly named assignment file in .pdf format. Also note we use long listings to see the link properties.
Troubleshooting and Help
Troubleshooting your system and getting help often follow the same steps. As an example, if you have trouble creating the softlink you should research and look at the command closely (repeated here).
$ ln -s ciss100/FirstnameLastname/lastnamefirstnameLL.txt lastnamefirstnamelink.txt
1. If your link is blacked out or in red denoting a broken link you need to delete the link (delete it just like a file).
2. Perform a listing of your home directory to verify the ciss100 subdirectory exists.
3. Change directory to your ciss100 subdirectory and perform a listing to verify the existance of your FirstnameLastname subdirectory.
4. Change directory to your FirstnameLastname subdirectory and perform a listing to verify the existance of your lastnamefirstnameLL.txt file.
* Of course you could have checked the existence of your directories and file from your home directory by providing the correct path as an argument to your directory listing command. If you do not understand what I have just written => You have not read the material enough as it can take 1, 3 or even 10 readings to understand the material.
Also, to help your debugging process further (or to seek my help), you must print out screenshots and reread the material with the screenshots at your side for investigation.
If you need to contact me for assistance, as in previous and following labs I will need to know the exact step (exercise) you are on and screenshots of all relevant files and directory long listings.
Here is another link demonstration and please understand that I cannot do this for other items moving forward as it is critical that students learn to read and understand technical content (it is a requirement of the discipline and again is likely to require many rereadings)