Unix

On This Page


Beginning Unix Tutorial

  1. Logon to the CS system
  2. NT users start up Xwin32
  3. Linux users type telnet xi at the UNIX prompt
  4. You should now be at a Unix prompt on xi.
  5. Enter the following Unix commands at the Unix prompt paying close attention to the effect of each. Commands are case sensitive and should be entered in lower case letters.
Command Effect
pwd Print working directory. Shows where you are.
ls Lists the files in the current directory.
ls -l Lists the files and details about them.
ls -a Lists All the files in the directory including hidden files (dot files).
la -al You guessed it.
man ls Shows the manual page for ls. All Unix commands have a complete explanation on their man page.
Ctrl c Kills the man page.
cd .. Change Directories, up one directory.
pwd Print Working Directory.
ls -al Lists the files in this directory.
ls -al | more Lists the files one page at a time.
cd Change back to your home directory
pwd
mkdir practice Makes a directory named practice in the current directory.
cd practice Change Directory to practice.
pwd
pico file1.txt Opens the pico text editor to create a file named file1.txt.
Ctrl g Get help. Read through the pico help file.
Ctrl x Exits the pico help file.
Practice Text in file1.txt Type in some text such as this.
Ctrl x Exits pico.
Y To save the file
Enter To accept the filename file1.txt.
ls List the files.
cp file1.txt file2.txt Copies file1.txt and renames it file2.txt.
pico file2.txt Opend file2.txt with the pico text editor.
Ctrl x Closes pico.
mv file1.txt file3.txt Renames file1.txt by Moving it to a file named file3.txt.
rm *.* Removes all of the files in the current directory.
cd .. Change Directory, up one.
pwd
rmdir practice Removes the directory named practice.
elm Starts the elm Email program.
Y If elm asks you any questions about directories.
? To pull up the help menu.
? To get a list of commands and their meanings.
q To exit help.
Send an Email message to yourself if you've not used elm before.
q To quit elm.
<Enter> In response to any closing questions.
logout To exit xi.

 


Unix Tutorial 2

 

Review

You should know the effect of the following commands:

ls ls –l ls -a ls - al | more
pwd man cd mkdir
cp mv rm rmdir
logout

 

You should be familiar with the following Unix programs:

Pico Elm

If not, you need to review the last tutorial.

 

New Stuff

Lets discuss in more depth some of what we discovered in the last tutorial.

Dot Files

When the command ls -a is used, all the files in the directory are displayed, including hidden files. In Unix, hidden files are called dot files because they start with a dot (.forward). Most dot files are needed by that the system. Others are needed by programs that you use. All must be handled with care. Here are some brief explanations of some of the dot files that may be in your home directory:

 

.login Unix reads this file when you login and sets up your environment according to the commands listed here.
.logout Unix reads this file when you logout and executes and commands listed here.
.xinitrc Resource file used by X Windows - the windows program for Unix.
.tcshrc Resource file used by the shell program tc shell. Controls the command line interface.
.plan Used by the finger program to display information about you.
.project Used by the finger program to display information about you.
.forward Used by your email program. Forwards your email to any address listed in this file.
.twmrc Used by the twm windows management program. Controls how your windows are displayed.
.netscape/ Directory that Netscape creates.
.xvpics File that the xv program (an image editor) creates.
.elm Directory that Elm creates.
.elm/elmrc Resource file that Elm uses.
.alias Place shortcut commands in this file.

 

More

The more command lists the contents of a file one page at a time. ls –al | more runs the ls command and "pipes" the output to the more command which puts it on the screen one page at a time. The more command c an also be used on files. It allows you to view the contents of files, one page at a time, without editing them.

Try It!

Use the more command on the dot files in your home directory to gain some insight into what they contain.

more .login

will show you what's in your .login file. View the rest of your dot files.

 

Finger

The finger command allows you to see information on users who have accounts on the system. Try the following commands:

Try It! 

finger Shows who is logged onto the system.
Finger (your login name) Shows information about you.
Finger baldauf@cs.fsu.edu Shows information about me including text that I've typed into my .project and .plan files. You can finger any user ate their email address if their system supports the finger program.
Finger @mary.cs.fsu.edu Shows all the users logged onto the mary server. You can finger any system that supports the finger program.

 Feel free to add messages to your .project and .plan files to be viewed by other users via the finger command.

.alias

Unix allows its users to create their own commands to use as shortcuts to long drawn out Unix commands. For instance, typing ls -al | more is rather cumbersome. It would be much easier to use the user created command all in order to accomplish the same task (listing all your files in detail one page at a time).

Try It!

Add the following line to the end of your .alias file (to open .alias use pico .alias).

alias all 'ls -al | more'

Close and save the file. Logoff the computer and log back on to get your new alias to take effect. Once back on, try out your new command (all).

 

Permissions

Use more or pico to read the contents of the README file in your home directory.

Unix provides a means for you to keep other users from accessing your files. By setting the permissions associated with a file, you can control who is able to read it, write to it, and execute it. You can view the permissions of a file with the ls –l command. Try it out on the README file in your home directory. The output should look something like this:

-rwxr-x--- 1 baldauf gs 0 Jan 9 11:13 README

This translates as follows:

Permissions

File Owner

Associated User Group

Date and Time Last Modified

File Name

-rwxr-x---

baldauf

gs

Jan 9 11:13

README

Those dashes and r’s and w’s and x’s preceding the file name in the long listing indicate who can read, write, and execute the file. -rwxr-x--- is read as four separate items, -, rwx, r-x, ---.

File Type

Owner Permissions

Group Permissions

World Permissions

-

rwx

r-x

---

If the item were a directory a d would be in the first position. README is not a directory, so the first position is marked with a dash.

The owner of the file is listed in the column after the permission settings, in the example above it is baldauf. The permissions indicate the baldauf has read, write, and execute permissions on the file (rwx). This is a text file so the Execute permiss ion has little effect.

The group which is associated with this file is gs (grad students) in this example. Any user in the gs group can read and execute this file but cannot write to it (r-x).

Side Note - You can see what groups you belong to by typing groups at the command prompt.

All other users (World) do not have permission to read, write or execute this file (---).

 

Changing the permissions of a file

You can change the permissions of a file with the chmod command. chmod has the following syntax.

chmod <permissions> <filename>

Where permissions are indicated by a number translated from binary and filename is the name of the file to be operated on.

The permissions can be indicated by a number if you view each of the permissions columns as marked if they have a letter in them or unmarked if they have a dash. Check out the following translation of the permissions on README:

Owner Permissions

Group Permissions

World Permissions

ls –al | more

rwx

r-x

---

Binary interpretation

111

101

000

Decimal interpretation

7

5

0

 

Try It!

chmod 000 README

Would have the effect of taking all permissions away from everyone including owner. Try it!

ls -al

---------- 1 baldauf gs 0 Jan 9 11:13 README

Now try to access the file with more or pico.

Permission Denied!

Lets change the permissions so that the file is readable by everyone but writable by only the owner and executable by no one. First translate this to permissions then to binary and then decimal

Owner Permissions

Group Permissions

World Permissions

ls –al | more

rw-

r--

r--

Binary interpretation

110

100

100

Decimal interpretation

6

4

4

 

The command is chmod 644 README try it and check the result with ls -al (or all).

Most files you create should be set to rwx------ (chmod 700) so that they are private to you. Any file you wish to make visible to others should be rwxr-xr-x (chmod 755). Never grant write permission on your files to other users unless you don't care what happens to your files.

Create a new file with pico. Save the file as newfile.txt. Check to see what permissions were automatically assigned to the file. It's important to note what permissions are automatically assigned to the files you create.

 

Review

You should know the effect of the following commands:

ls ls –l ls -a ls - al | more
pwd man cd mkdir
cp mv rm rmdir
logout more chmod finger

 

You should be familiar with the following Unix programs:

pico elm

If not, you need to review the last tutorial.


Unix Tutorial 3

Moving Around the Network

There are a few shortcut symbols that are used with the cd command and other commands. You will need to be familiar with these.

Symbol Meaning Example Example meaning
. The current directory cp CGS3066/file1.txt . Copy the file, file1.txt, which is in the CGS3066 directory, to the current directory that I'm in.
.. One directory level up mv ../file1 . Move the file, file1.txt, which is in the directory above the current one, to the current directory.
~ The home directory of cd ~baldauf Change directories to baldauf's home directory.

 

Reminder: Typing cd by itself will take you back to your home directory.

Try It Yourself!

Work through the following commands (starting in your home directory) and make note of how they work.

Command Effect
pwd Prints your current directory. Make sure that you are in your home directory named after your username.
cd .. Move up one directory level.
pwd Shows current directories name.
ls -al | more List all the files in the current directory in long version one page at a time. See your home directory listed? Make a mental note of the permission settings for your home directory.
cd / Change to the root directory.
pwd
ls
cd /usr/bin This is where all the binary code for Unix commands and programs is listed.
ls -al | more You should see some familiar commands.
cd /home/cs8/CIS3066 This is our class directory.
ls All our web page files are stored in the public_html directory.
cd public_html
ls Take a look.
cd ~baldauf Change directories to baldauf's home directory.
pwd
ls Take a peek.
cd Back to your home directory.
pwd
cp ~baldauf/lab_tricks.txt . Copies the file from baldauf's home directory to yours.
ls
more lab_tricks.txt Allows you to read the contents of lab_tricks.txt.

 

Gopher & Telnet

The last exercise gave you practice at moving around the computer that you're logged on to. How do you log onto other computers on the network from your computer? There are two programs that are designed to help: telnet and rlogin. These programs allow you to log into any system, on which you have an account, on the local network or on the Internet. telnet requires you to login on the remote system while rlogin uses the information from your current login to log you into the remote system.

Try the following commands:

Command Effect
gopher Gopher is a program which lists information about our department and computer system.
Choose [2] CS Dept System Information
Choose [4] Available Hardware
Choose [4] Machine Types and Locations
View the list of machines. You can telnet or rlogin to any of these machines on the CS system.
Exit gopher and continue with the following commands:
telnet biff Connects you to a computer on cs.fsu.edu named sed.
(Login as usual)
pwd Notice you're in your home directory -but on a different computer! You'll find that all of the CS computers have access to the same directory structure. Whenever you login to a machine, it automatically places you in your home directory.
ls -al Yep, those are your files alright.
rlogin upsilon Upsilon is another computer on the cs.fsu.edu system.
(Notice that you aren't required to login)
pwd Yep, you're in your home directory on upsilon.
logout Closes the upsilon connection. Now you're back to sed.
logout Closes the sed connection. Now your back where you started.

 

Redirection

Unix allows you to redirect the output from a command or program to a file instead of the screen. The redirection characters are > and >>.

Try the following commands from your home directory (you should have a copy of a file named lab_tricks.txt in your home directory from the previous exercise):

 

Command Effect
more lab_tricks.txt Shows the contents of lab_tricks.txt
more lab_tricks.txt > trix Redirects the output into a file named trix.
pico trix Look in the trix file with pico.
Ctrl x Exits pico without saving changes.
ls -al > trix Redirects the output of the ls command to the file trix.
pico trix Observe that the ls information has overwritten the lab_tricks.txt data.
Ctrl x Exits pico.
more lab_tricks.txt >> trix A double greater than sign, >>, has the effect of appending the data to the end of the file.
pico trix Note how lab_tricks.txt is added to the file after the ls information.
Ctrl x Exits pico
elm (your_user_name) < trix Fill in your actual user name for your_user_name. Use the less than sign as indicated to show that the trix file is being sent to you using elm. You just mailed yourself the file.

File Compression

A file compression utility program uses special algorithms to transform a file or collection of files into a smaller sized file. This is useful for a number of situations such as saving you space on your hard drive, fitting large files on fl oppy disk, or making for a faster download when transferring the file over a network. A compressed file needs to be uncompressed prior to use. This can be done by the same program (or an associated program) which was used to compress the file. The two pro grams that we'll be using to compress files and directories are tar and gzip.

Tar is a program which is very handy for taking a whole directory structure and collapsing it into one handy file. When the user is ready to uncompress the file, tar is used to recreate the original directory structure.

Gzip is a program which we'll use to take a large file and compress it into a much smaller one. Gunzip is used to uncompress the file into its original form.

Try the following exercise from your home directory:

 

Command Effect
mkdir Zip Make a directory named Zip.
cd Zip Change to the directory named Zip.
cp /home/cs8/CIS3066/practice.tar.gz . Copy the file practice.tar.gz from our class directory to your Zip directory.
ls -al Note the size of practice.tar.gz (200690 bytes).
gunzip practice.tar.gz The .gz extension indicates that this file is zipped (compressed). Gunzip unzips (uncompresses) it.
ls -al Notice that the .gz is removed from the file name. The file is now 755712 bytes in size. Compression made this file shrink to a third of its normal size!
tar -xvf practice.tar The .tar extension indicates that this file is compressed with tar. tar -xvf uncompresses the files -and there are a bunch of them! The -xvf is used to indicate that we're extracting files. Check man tar for details.
ls You should have a directory named unzip --this tarred file contains all of the files for the gunzip program.
cd unzip Change to the unzip directory.
ls Quite a few files have been unzipped.
cd .. Move up a directory.
rm practice.tar Remove the tar file.

 

Now lets try reversing the process. Let's take the directory structure, unzip/, compress it and zip it.

Command Effect
tar -cvf practice2.tar ./unzip -cvf indicates that we want to create a tar file named practice2.tar created from the /unzip directory.
ls Practice2.tar has been created.
gzip practice2.tar Zips the file up and adds the .gz extension to the file name.
ls Notice practice2.tar.gz.
rm -r unzip Removes the unzip directory and all of its files and subdirectories. -r stands for recursive and should be used with caution. Use it only when your sure that you want everything in the directory erased. This is a shortcut to avoid having to remove all of the files prior to using the rmdir command.

Practice unzipping, zipping, tarring and untarring this file. When done practicing, remove the Zip directory and all contents in order to save disk space.

 

Printing

To print files from the Unix command prompt use one of the following commands:

Command Effect
lpr -Ppclab filename pclab is the name of the line printer in the hall to which the file will be printed. filename is the name of the file to be printed.
lpr -Pmajors filename Prints the file, filename, to the laser printer named majors, in the lab.

 

That's all for now! J