Unix101 Lesson 1

Concepts we covered

  • Logging into a remote computer / server
  • Your home directory
  • Carrying out basic commands
  • Pipes: sending text output from one command to the next
  • Editing text files and creating scripts
  • Using the man command

Commands we used

  • ssh
  • ls
  • mkdir
  • rmdir
  • cd
  • mv
  • rm
  • nano hello.txt
  • man
  • pwd
  • echo
  • fortune
  • cowsay
  • chmod
  • mail

Commands required for homework

  • whoami
  • hostname

Exercises

Use the “man” command to read up on all the commands we used. You will also need to read about the 2 commands that we didn’t use (listed above).

Remember: To make a script called scriptname and run it, you must follow these steps

  • Write script with nano scriptname and exit Nano
  • carry out the following command : chmod +x scriptname
  • run it as follows (and whilst in the same directory): ./scriptname

Create a directory called “homework101” in your home directory. The three scripts you write should be located here.

Exercise 1

Write a script called info.sh that outputs the following:

Hello world!
I am a script located in the following location:
<working directory here>

I am being run by the following user:
<you_username>
on the following system:
<hostname>
Goodbye.

Exercise 2

Next write a script called mailme.sh that takes the output from the “info.sh” script, puts it in a cow and sends it in a mail with

  • You as the receiver
  • The subject line “homework”

Exercise 3

Finally, create a directory called “backup” in your home directory. Write a script called backup-homework.sh that copies everything in your homework directory into the backup directory:

  • The script should copy all the stuff in the homework directory, regardless of what’s in it. In other words, you should not be explicitly specifying by name which files to copy.
  • HINT: You will probably need to “recursively” copy. Check out the cp man-page. Or use the “*” option

References

For information on Nano text editor: http://www.debianadmin.com/nano-editor-tutorials.html

Pipes (goes a little beyond what we did): http://www.december.com/unix/tutor/pipesfilters.html