Assignment Submission Directions
As in the previous assignments, you will take periodic screenshots as directed below (Screenshot instructions provided in the previous assignments) and paste the screenshots into a single LastnameFirstnameLL2.odt LibreOffice Word document. You should preface each screenshot with the the exercise number as listed in the tutorial.
Please name the assignment LastnameFirstnameLL2.odt (ex. LoobyJamesLL2.odt) and upload this file to BB as directed in the LM when complete. Please note that the screenshot even with an expanded terminal screen may not capture every command you have entered but it will demonstart your present state and that is all that is necessary so let’s begin.
Required Reading – from Ubuntu texts, man pages and WWW as necessary. Recall you should read about every command in the LLs prior to their use. You will also find that you may have to review previous labs as I will draw on this content.
2.1 Copying Files
cp file1 file2
is the command which makes a copy of file1 in the current working directory and calls it file2. Note we can copy it elsewhere by providing the correct path (i.e. directory path and we can even use the single . as introduced in a previous LL). 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.
What we need to do first is get a file to copy and we need to get acquainted with a basic text editor for future work so let’s get and start the the vim editor using the following commands in the Terminal (of course this requires that you start the Terminal). Also 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.
Note VMWare/VB users will have to install vim using the following installation command however vim is already available in the HVCC VDI Ubuntu installation so sudo apt-get install vim is not necessary in the OpenNX/NoMachine instance.
$ sudo apt-get install vim
Provide your password to install and accept noting that your password will not be displayed as you type. Also, please recall you should be researching all commands you use rather than following them blindly so you should be researching “sudo”, “apt-get”, “install” and “vim” in isolation and together.
Now that vim is installed let’s create a file to work with.
$ vim lastnamefirstnameL.txt # note this creates a .txt file not the .odt file you will submit (i.e. please note the single L as this is an intentional error and 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) 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 40+ lines as we will need these 40 lines in subsequent labs. Again this is 0-based counting as computers begin counting (and addressing) at 0.
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 you can reenter vim using the commands above, i will place you in insert mode and esc followed by :wq will write the file and quit vim).
Now you’re wondering why I made you use this archaic non-graphical editor. Well… 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.
Believe it or not, vim is an update to the vi editor (which is available by default but I was able to get you to use sudo apt-get to obtain vim) that I learned on as it was the only editor available back in my day… slightly after the Civil War during the age of slide rules . You can imagine the excruciating pain of writing a lengthy C or Java program using vim in your 1st programming course. Now for your reference, vim documentation is located here: http://www.vim.org/ and this applies to vi (i.e. we could have done this with vi and this is a viable option if you are having network difficulties). Note that Unix/Linux also provide 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
Ok, now let’s copy the file by providing a new name, i.e. lastnamefirstnameLL.txt
$ cp lastnamefirstnameL.txt lastnamefirstnameLL.txt
Now let’s copy this renamed file to our ciss100/UserName subdirectory. There are two ways to do this as we can cp the file to a subdirectory by providing the correct path or alternatively 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/Username (for me this is ciss100/JamesLooby) so enter:
$ cd ciss100/UserName # you can use the pwd command to verify where you are
Note that we could have done this in 2 separate steps, 1st cd to ciss100 and then cd to Username. Now let’s copy the renamed lastnamefirstnameLL.txt file (for me this is loobyjamesLL) 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. Now as I introduced above, I could have copied the file from my home or top level directory by issuing the following command:
$ cp loobyjamesLL.txt ciss100/JamesLooby #of course you will use your file/directory name
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 file to the ciss100/JamesLooby subdirectory and rename the file LL.txt
Navigate to your ciss100/UserName subdirectory
Perform a print working directory command and a long listing.
Take a screenshot and paste it into the .odt file.
2.2 Moving files
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.
Navigate to your ciss100/UserName directory
Create a backup of the recently copied usernameLL2.txt file by copying it to a backup file titled usernameLL2.bak. (Please read this direction carefully)
Perform a long listing
Take a screenshot and paste it into your .odt file
2.2 Removing files and directories
rm (remove), rmdir (remove directory)
To delete (remove) a file, use the rm command. As an example, let’s create a copy of a file then delete it.
Inside your ciss100/UserName directory create a copy of your usernameLL.txt file titled temp.txt using the cp command introduced above.
Inside your ciss100/UserName directory create a directory titled TempDirectory using the mkdir command previously introduced.
Perform a long listing, take a screenshot and paste it into your .odt file.
Ok, now please remove the recently created file and directory by issuing the the rm temp.txt and rmdir TempDirectory commands.
Perform a long listing, take a screenshot and paste it into your .odt file.
2.3 Displaying the contents of a file on the screen
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
This will clear all text and leave you with your prompt at the top of the window.
2.4 Graphical Editor
Ok, so you were introduced to vim and this was necessary for the reasons identified above however once your system/GUI are up and running there is no need to put yourself through that painful experience. Ubuntu offers you gedit and this can be used to edit your text files and Linux scripts (like your startup files). You can launch gedit from the command line by itself and then create or open and save a file or you can open the file directly. Try the following and file this knowledge away as you will need to modify text files and scripts in future labs.
$ gedit lastnamefirstnameLL.txt #install it with sudo apt-get install gedit if necessary
Close the gedit window and return to you Terminal.
Please submit your assignment in BB as previously directed and don’t forget to properly shut down your Ubuntu system when done and last reminder to take periodic snapshots.
Lastly for completeness know there are other editors and one CISS 100 student introduced me nano which is another nice elegantly simple editor.
||copy file1 and call it file2|
||move or rename file1 to file2|
||remove a file|
||remove a directory|
|clear||clear the terminal screen|