CSC 204 Lab 1: Intro to Linux & using vim, chmod, tar, rsync
This lab deals with using Linux, one of the world’s most popular and stable computer operating systems and gets you comfortable with the commands vim, tar, & rsync. You will need to login using the MobaXterm software using your cobra account login name & password.
Windows users can get a free copy of this software by googling “download Mobaxterm” and downloading the free home edition. Once you open the software, click on New Session, then SSH, and then input cobra.cs.mercer.edu as the remote hostname. This is a server in the CSC building.
Your login name should be your last name followed by an underscore followed by your first initial. For example, Jane Smith would be smith_j. It will be all lowercase. Your initial password will be your Mercer Student ID.
Mac users will need to use the terminal software found on all Macs. Once you open this software, type ssh loginName@cobra.cs.mercer.edu at the prompt. Substitute your own login name for loginName.
When the screen displays:
type in the user name that you were assigned and press . Note that all user names use lower case characters only. You will now be prompted for your password.
Every account on the system has been assigned a unique password. Notice that when you enter your password, the characters do not appear on the screen. This is a security measure to prevent anyone else from seeing your password and using your account. Your account on the system is for your use only and you are responsible for anything that happens to your account. Do not give your password to anyone! After you have entered your password correctly and pressed , the system will return with the Linux prompt
which indicates that the system is ready for you to enter commands.
A word of warning…Linux is case sensitive, so LS is not the same as ls!
Changing Your Password:
The first thing to do is to change the temporary password you used to login with to one that only you know. Your password can be changed at any time if someone finds out what it is. To change your password simply type:
and the system will respond with:
Changing password for .
(current) Linux password:
Enter your current password. As before, it will not appear on the screen. If you typed it correctly you will be prompted for your new password:
New Linux password:
Re-type new Linux password:
Type your new password. Once again, it will not appear on the screen. If the system does not consider it to be a good password, it will let you know. Once you type your password, the system will ask you to type it again. This is so the system can make sure that you typed it right the first time. When the Linux prompt shows up again, you have successfully completed changing your password. Remember what you typed in because the system will ask for it every time you log on!
There are a variety of different email programs used with Linux. I find alpine to be the easiest to use for simple things. When someone has sent you mail, the system will prompt:
You have new mail.
when you log on. To see your mail or to compose new mail simply type:
Followed by hitting return. From the pine main menu, you can view your mail by going into “Folder List” and hitting return on “INBOX”. To compose new mail, simply hit a capital C from the main menu. To exit, hit Q.
Let’s look at some of the commands available to you through Linux.
The first of these is list. To get a listing of your files on the screen, type
Then hit the return key. Now, create a directory named Lab1 and change into it by typing mkdir Lab1. Now, change into it by typing cd Lab1.
Copying: You can make a copy of a file using the command cp. After the cp, you need to give the source and the destination of the copy.
From time to time I will put files in a public area so everyone can access them. This public area for this class is called /pub/digh/IST126 . To see what’s in the public area, use the command ls followed by the subdirectory you want to list:
There is a file there you will need for this lab, lab1.file. Now, let’s copy this file to your account using this command:
cp /pub/digh/IST126/Lab1/lab1.file lab1.file
Renaming: You can change the name of a file with the mv (short for move) command. After the mv, you have the old name, then the new name, so rename the file lab1.file to sample1, use the command:
mv lab1.file sample1
Viewing: You can view the contents of a file with the command cat (short for concatenate):
will display the contents of the file sample1. If a file is too large for the screen, it will scroll off quickly. To view the file one screenful at a time, use the command more :
The computer will pause after each screen. Type to continue.
Removing files: Use the command rm (short for remove) to delete files:
will remove the file of sample1. Be very careful. It takes very little effort to delete all of the files in a subdirectory!
We will use the vim (short for visual) editor in this class.
The vim editor has two modes (ways of interacting with you): insert mode and command mode. In the insert mode, the characters you type appear on the screen as part of the file. They are inserted into the file. In command mode, the characters you type cause various things to happen to the file. Make sure you have the handout “Linux_vim Handout”. The last page is very helpful.
When you enter vim, you are automatically in command mode. Once you get into insert mode, you can return to the command mode at any time by pressing the escape key. The letter i is one of several letters that allow you to enter the insert mode.
Enter vim to edit the file horton by typing:
Now, let's type the following outline into our first file exactly as it appears below:
Add a line with your name at the top of the file. When you're done typing, hit the escape key and type the command :wq to exit and save your information. (The ‘:’ moves the cursor to the bottom of the screen to receive a command, the ‘w’ writes the file, and the ‘q’ quits.)
Do an ls when you return to your cobra prompt to verify that your work has been saved.
Check yourself. Using vim, open the file horton and verify that your text is all okay. Then exit.
There are on-line manual pages for almost every Linux command. To see the page for the ls command, use the command: man ls
Directory Maintenance & Practice with rsync & tar
There are a number of ways to move around in subdirectories. The command pwd is used to print the name of the directory you're currently in (it stands for "Print Working Directory"). Now, try each of the following :
cd .. To move up one level
cd ~/ To move to your home directory (Just cd will also do this)
cd Lab1 To move to a specified directory in your home directory from your home directory
cd ~/Lab1 To move to a specified directory in your home directory from any other directory
chmod ugo+rw horton To give read & write permission to all with file horton
cp –rR /pub/digh/Concord . To copy a directory & all its subdirectories to your current area (don’t forget the space, dot, and then return at the end)
rsync –azv /pub/digh/Concord ~/backup To remote sync everything from /pub/digh/Concord to a backup directory in your top level
tar –cf concord.tar Concord To mount all the contents of directory Concord to file concord.tar
rm –rf Concord To delete the directory Concord
tar –xf concord.tar To “un-tar” concord.tar & recreate the directory Concord
Short Answers on Linux – Type up the answers to each of the following in a file named lab1.answers in your Lab1 directory of your cobra account. Use your handouts.
1. Next lab, what Linux command will you use to change into your Lab2 subdirectory? ________
2. Next lab, what Linux command will you type to make a directory named Lab2 within the Labs subdirectory? (You will create a new subdirectory for each lab.) ___________________________
3. What Linux command will move you up one level from your current directory? _____________
4. What Linux command would you to use mount multiple folders into a single file? _________
5. What Linux command would let you see who else is logged in? ______________
6. What Linux command could be used to rename the file mydata as input1? _____________
7. What is one vim command that puts you into insert mode? ____________________________
8. What is the only way in vim to leave insert mode and go into command mode? ____________
9. What single letter vim command deletes a character? _________________________________
10. What vim command is best for replacing a letter? ___________________________________
11. What vim command deletes a word? ______________________________________________
12. What vim command deletes a line? _______________________________________________
13. What vim command allows you to save changes to a file without exiting vim? _____________
14. What vim command allows you to exit vim without saving any of your changes? __________
15. What vim command moves you to the end of a file? _________________________________
Now, let's exit your account and return to your personal computer by typing exit. Don't ever leave your account without first exiting it.