Difference between revisions of "CSC231 Bash Lab 1"

From dftwiki3
Jump to: navigation, search
(Creating Subdirectories)
(A view from the Home Directory)
Line 132: Line 132:
 
You should have seen all 4 prog*.asm files.  Yes?
 
You should have seen all 4 prog*.asm files.  Yes?
 
   
 
   
 +
<br />
 +
{| style="width:100%; background:yellowgreen"
 +
|-
 +
|
  
 +
==Challenge #1: A New Directory Tree==
 +
|}
 +
[[Image:QuestionMark1.jpg|right|120px]]
 +
<br />
  
  

Revision as of 20:51, 2 February 2017

--D. Thiebaut (talk) 17:04, 2 February 2017 (EST)



This tutorial introduces the basic navigation commands, and will show you how to create directories (folders) and move in and out of them. I have used and adapted much of the information that is presented in several excellent tutorials:



Switching to the Bash Shell


By default, your student account using the shell called tcsh. We will be using another shell that is more friendly: bash.
Open a terminal or console window and connect to aurora.smith.edu with your class account. Here we assume that your class account is of the form 231b-xx where xx are two unique letters associated with your personal account.
Run these commands at the Linux prompt:

cd 
cp  .login  .login.bak
cp  .bashrc  .bashrc.bak
cp  ~231b/.login  .login
cp  ~231b/.bashrc  .bashrc


What this does is to copy the a file from your instructors account (~231b) into your account (~231b-xx). This file is read automatically every time you login to your account and will set the shell to bash.

  • logout of your account
  • log back in. You should see something like this:


231b-xx@aurora.smith.edu's password: 
Welcome to Linux Mint 17 Qiana (GNU/Linux 3.13.0-24-generic x86_64)

Welcome to Linux Mint
* Documentation:  http://www.linuxmint.com
Last login: Thu Feb  2 16:59:49 2017 from 131.229.199.140
bash: setenv: command not found
231b-xx@aurora ~ $ 


Backing up your files


Just in case you mess up and erase files in your account that you'd like to keep, you will make an archive of all your files and save it in your instructor's account:

cd
tar -czvf backup.tgz *
rsubmit backup backup.tgz

That's it! Your instructor should now have a copy of all the files you may have created in your home account, and in case you delete some by mistake, they should be recoverable.


Creating Subdirectories


We are going to create the following tree of directories shown below. Note that you do not need to create the 231b-xx folder, as it is by default already there: it's your home directory.

TreeOfFolders231.jpg


Type in the following commands to create the tree and put files in the different folders. Note: you will use the getcopy command that is not a Linux command, but rather a program created for the CS department accounts.

  mkdir lab1
  mkdir hw1
  mkdir misc
  ls

You should see the 3 directories in your account.

Let's go in the misc folder:

  cd misc
  ls

Let's create 2 subdirectories there: demo and pictures:

  mkdir demo
  mkdir pictures
  ls


Navigating the Subdirectories


Now, let's go "up" one level and look at what we have created and what they contain (the subdirectories should all be empty at this point):

  cd ..
  ls
  ls hw1
  ls lab1
  ls misc
  ls misc/demo

Let's go into lab1 and put the file prog1.asm there. We'll get prog1.asm from the instructor's handout directory:

  cd lab1
  getcopy prog1.asm
  ls

Now let's go into hw1, which is at the same level as lab1 and put prog2.asm into it:

  cd ../hw1
  getcopy prog2.asm
  ls
  cat prog2.asm 

Same thing with misc and prog3.asm

  cd ../misc
  cd demo
  getcopy prog3.asm

and finally we'll get prog4.asm and put it into pictures.

  cd ../pictures
  getcopy prog4.asm
 


A view from the Home Directory


Let's go back "home" and see if we can see the different prog*.asm files without actually "cd"-ing to the folders:

To go "home" we simply type:

cd

And we can look at the contents of the different sub- and sub-sub-directories:

ls lab1
ls hw1
ls misc
ls misc/demo
ls pictures/demo

You should have seen all 4 prog*.asm files. Yes?


Challenge #1: A New Directory Tree

QuestionMark1.jpg