TUCoPS :: Unix :: General :: unixref.txt

General Unix Reference Guide

 Subj : General UNIX reference guide                                            
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

Below you will find a quick reference on basic navigation within the UNIX
environment.  The target audience is introductory level UNIX.  Any switches
described are straight from the man pages.  Previous experience operating
from a command line interface like MS-DOS is assumed.


First you need access to a UNIX box or a shell account.  For the purpose of my
audience I will assume shell in my examples, though there is no difference.


You'll find the directory structure strikingly similiar to DOS on appearance.
The big difference you'll see right off is the use of / instead of \ when
seperating directories.  Besides that, individual files have permissions
instead of attributes.  Another thing to consider and know is that UNIX is
case sensitive, myfile.doc and Myfile.doc are considered two different files.

You can get further information on any command in UNIX by typing man
<command>.


Changing directories:

Same as in DOS, cd <target dir>.  For example, to switch to a directory called
"mydir" off the root I would type cd /mydir (using the begining / to signafy
from the start of everything).

You can use cd .  - to change to the root dir (remember, UNIX has permissions,
you may not have permission to do this or to list the contents).

cd .. will change up a step on the directory tree, for example if you are
currently in /home/mydir and you want to go to /home, then cd .. will get you
there.


Listing the Contents of a directory:

Instead of using dir, like in DOS, in UNIX use ls.  Using ls alone lists the
files like the DOS command dir /w would.  A common way is to use ls -l, which
will show you the file permissions, size, and other information.  You see the
permissions as letters:

         r  the file is readable;
         w  the file is writable;
         x  the file is executable;
         -  the indicated permission is not granted.


Below you will find all the switches for ls and what each does:

     -a   List all  entries;  in  the  absence  of  this  option,
          entries  whose  names  begin  with a `.' are not listed
          (except for  the  super-user,  for  whom  ls,  but  not
          /usr/5bin/ls,  normally  prints  even  files that begin
          with a `.').

     -A   (ls only)  Same as -a, except that `.' and `..' are not
          listed.

     -c   Use time of last edit (or last mode change) for sorting
          or printing.

     -C   Force multi-column output, with entries sorted down the
          columns;  for ls, this is the default when output is to
          a terminal.

     -d   If argument is a directory, list only its name (not its
          contents);  often  used  with -l to get the status of a
          directory.

     -f   Force each argument to be interpreted  as  a  directory
          and  list  the  name  found  in each slot.  This option
          turns off -l, -t, -s, and -r,  and  turns  on  -a;  the
          order  is  the  order  in  which  entries appear in the
          directory.

     -F   Mark directories with a trailing slash  (`/'),  execut-
          able  files  with  a  trailing asterisk (`*'), symbolic
          links  with  a  trailing  at-sign  (`@'),  and  AF_UNIX
          address  family  sockets  with  a  trailing equals sign


     -g   For ls, show the group ownership of the file in a  long
          output.   For  /usr/5bin/ls,  print a long listing, the
          same as -l, except that the owner is not printed.

     -i   For each file, print the i-number in the  first  column
          of the report.

     -l   List in long format,  giving  mode,  number  of  links,
          owner, size in bytes, and time of last modification for
          each file.  If the file is  a  special  file  the  size
          field  will  instead contain the major and minor device
          numbers.  If the time of last modification  is  greater
          than  six  months ago, it is shown in the format `month
          date year';  files  modified  within  six  months  show
          `month  date time'.  If the file is a symbolic link the
          pathname of the linked-to file is printed  preceded  by
          `->'.  /usr/5bin/ls will print the group in addition to
          the owner.

     -L   If argument is a symbolic link, list the file or direc-
          tory the link references rather than the link itself.

     -q   Display non-graphic  characters  in  filenames  as  the
          character ?; for ls, this is the default when output is
          to a terminal.

     -r   Reverse the order of sort to get reverse alphabetic  or
          oldest first as appropriate.

     -R   Recursively list subdirectories encountered.

     -s   Give size of each file, including any  indirect  blocks
          used  to  map  the  file, in kilobytes (ls) or 512-byte
          blocks (/usr/5bin/ls).

     -t   Sort by time modified  (latest  first)  instead  of  by
          name.

     -u   Use time of last access instead  of  last  modification
          for  sorting (with the -t option) and/or printing (with
          the -l option).

     -1   (ls only) Force one entry per line output format;  this
          is the default when output is not to a terminal.

SYSTEM V OPTIONS

     -b   Force printing of non-graphic characters to be  in  the
          octal \ddd notation.

     -m   Stream output format; the file names are printed  as  a
          list  separated by commas, with as many entries as pos-
          sible printed on a line.

     -n   The same as -l, except that the owner's UID and group's
          GID  numbers  are  printed,  rather than the associated
          character strings.

     -o   The same as -l, except that the group is not printed.

     -p   Put a slash (`/') after each filename if that file is a
          directory.

     -x   Multi-column output with entries sorted  across  rather
          than down the page.


Copying and Moving Files

To copy a file use cp, cp <source> <target>.  To copy the file myfile.txt to
another directory from the current directory you would type (without the ")
"cp myfile.txt /home/mydir/myfile.txt".

cp switches:

     -i   Interactive.  Prompt for confirmation whenever the copy
          would  overwrite  an existing file.  A y in answer con-
          firms that the copy should proceed.  Any  other  answer
          prevents cp from overwriting the file.

     -p   Preserve.  Duplicate not only the contents of the  ori-
          ginal file or directory, but also the modification time
          and permission modes.

     -r
     -R   Recursive.  If any of the source files are directories,
          copy  the directory along with its files (including any
          subdirectories and their files); the  destination  must
          be a directory.



To move a file type mv <source> <target>, see the example above and switch mv
with cp.

To rename a file use the mv command.  To rename myfile.txt to yourfile.txt
type "mv myfile.txt yourfile.txt".

mv switches:

     -    Interpret all the following arguments  to  mv  as  file
          names.  This allows file names starting with minus.

     -f   Force.  Override  any  mode  restrictions  and  the  -i
          option.  The -f option also suppresses any warning mes-
          sages about  modes  which  would  potentially  restrict
          overwriting.

     -i   Interactive mode.  mv displays the name of the file  or
          directory  followed  by a question mark whenever a move
          would replace an existing file or  directory.   If  you
          type  a  line  starting  with y, mv moves the specified
          file or directory, otherwise mv does nothing with  that
          file or directory.

To delete a file use rm.  Careful with rm!!!  We all shoot ourselves in the
foot with this one once in a while, be especially careful if you are running
from root as to what directory you are in before typing rm -f *...we all think
we are in another directory when that one first bites us.  rm -rf * is worse,
but you'd have to be really ignorant to type that by accident.

The switches for rm are as follows:

     -f   Attempt to remove files without displaying permissions,
          asking questions or reporting errors.

     -i   Ask whether to delete each file, and, under -r, whether
          to   examine  each  directory.   Sometimes  called  the
          interactive option.

     -r   Recursively delete the contents  of  a  directory,  its
          subdirectories, and the directory itself.


Making and Deleting Directories:

To make a directory use mkdir.  To remove one use rmdir.


Setting Permissions:

UNIX has file and directory permissions.  You can assign and remove the
ability for others to read, write, or even see specific files or directories.
To set and change these permissions we use chmod <mode> <filename>.

You see permissions in an ls -l and they look something like this:

-rwxr-x---  1 root          871 Sep 30 15:08 foo.sh
drwxr-x---  1 root         1024 Sep 30 15:08 mydir

After the first letter (signafying a directory or file, the letters are
grouped in threes ((r)ead, (w)rite, (x)ecute) for owner, group, other.  chmod
assigns numbers to each as follows:

Owner:
     r - 400
     w - 200
     x - 100

Group:
     r - 40
     w - 20
     x - 10

Other:
     r - 4
     w - 2
     x - 1


So if I wanted the owner (chances are you, unless your administering a server)
of the file only to be able do do everything with it and everyone else not to
be able to do anything then yoy want the permissions to look like this:

-rwx------

This means you are using only the owners set of numbers, so add them up...

400+200+100 = 700

so chmod 700 myfile.

Say you want to be able to do everything to your file, but you also want to
give a certain group of people the ability to read it, but not write to it.
That means you want the permissions to look like this:

-rwxr-----

So use only those numbers and add them:

400+200+100+40 = 740

So,

chmod 740 myfile

get it?  good.  Some common settings:

     rwx------ -> 700 - only you have permissions
     rwxr--r-- -> 744
     rwxrw-r-- -> 764
     rwxrwx--- -> 770
     rwxr-xr-x -> 755 - common web setting





That should give you some of the basics for working in UNIX.  I will continue
with this series as I have time.  The next one will be on using a default
editor like vi, using ftp, and some other items.

I am posting these in the interest of rebuilding 2600 into a group for more
than just spam and other "l33t" crap!  This was once a great group, I remember
(been in the field for over 15 years), now it is laughable.

I will also be answering posts in here when I have the time, been doing it for
a little while now anyway, I have no sig at all...why waste the space...  I
post from a number of different accounts, but really don't care about who
knows my identity...ask and I'll tell you.  I just use a false email address
so that my mailbox doesn't fill up with crap.

I offer only information that I think others may find useful, from newbies on
up, I will not respond to flames, challenges, can-i-crack-this, who's
"l33ter", or any posts with too many z's in them  ;)  I only think that
contributes to the degradation of the group.

If someone finds what I say to be inacurate, or wishes to expand upon
it...feel free to say so in an intelligent manner.  If you find fault with my
grammer or spelling...tough...I don't get paid for that...I get paid for my
systems knowledge, besides I intentionally mistype some words all the
time...for a reason.  In short, lets have an intelligent well thought out
discussion, not a flamefest.


TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2024 AOH