home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / unixref.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  11.8 KB  |  319 lines

  1.  Subj : General UNIX reference guide                                            
  2. ────────────────────────────────────────────────────────────────────────────────
  3.  
  4. Below you will find a quick reference on basic navigation within the UNIX
  5. environment.  The target audience is introductory level UNIX.  Any switches
  6. described are straight from the man pages.  Previous experience operating
  7. from a command line interface like MS-DOS is assumed.
  8.  
  9.  
  10. First you need access to a UNIX box or a shell account.  For the purpose of my
  11. audience I will assume shell in my examples, though there is no difference.
  12.  
  13.  
  14. You'll find the directory structure strikingly similiar to DOS on appearance.
  15. The big difference you'll see right off is the use of / instead of \ when
  16. seperating directories.  Besides that, individual files have permissions
  17. instead of attributes.  Another thing to consider and know is that UNIX is
  18. case sensitive, myfile.doc and Myfile.doc are considered two different files.
  19.  
  20. You can get further information on any command in UNIX by typing man
  21. <command>.
  22.  
  23.  
  24. Changing directories:
  25.  
  26. Same as in DOS, cd <target dir>.  For example, to switch to a directory called
  27. "mydir" off the root I would type cd /mydir (using the begining / to signafy
  28. from the start of everything).
  29.  
  30. You can use cd .  - to change to the root dir (remember, UNIX has permissions,
  31. you may not have permission to do this or to list the contents).
  32.  
  33. cd .. will change up a step on the directory tree, for example if you are
  34. currently in /home/mydir and you want to go to /home, then cd .. will get you
  35. there.
  36.  
  37.  
  38. Listing the Contents of a directory:
  39.  
  40. Instead of using dir, like in DOS, in UNIX use ls.  Using ls alone lists the
  41. files like the DOS command dir /w would.  A common way is to use ls -l, which
  42. will show you the file permissions, size, and other information.  You see the
  43. permissions as letters:
  44.  
  45.          r  the file is readable;
  46.          w  the file is writable;
  47.          x  the file is executable;
  48.          -  the indicated permission is not granted.
  49.  
  50.  
  51. Below you will find all the switches for ls and what each does:
  52.  
  53.      -a   List all  entries;  in  the  absence  of  this  option,
  54.           entries  whose  names  begin  with a `.' are not listed
  55.           (except for  the  super-user,  for  whom  ls,  but  not
  56.           /usr/5bin/ls,  normally  prints  even  files that begin
  57.           with a `.').
  58.  
  59.      -A   (ls only)  Same as -a, except that `.' and `..' are not
  60.           listed.
  61.  
  62.      -c   Use time of last edit (or last mode change) for sorting
  63.           or printing.
  64.  
  65.      -C   Force multi-column output, with entries sorted down the
  66.           columns;  for ls, this is the default when output is to
  67.           a terminal.
  68.  
  69.      -d   If argument is a directory, list only its name (not its
  70.           contents);  often  used  with -l to get the status of a
  71.           directory.
  72.  
  73.      -f   Force each argument to be interpreted  as  a  directory
  74.           and  list  the  name  found  in each slot.  This option
  75.           turns off -l, -t, -s, and -r,  and  turns  on  -a;  the
  76.           order  is  the  order  in  which  entries appear in the
  77.           directory.
  78.  
  79.      -F   Mark directories with a trailing slash  (`/'),  execut-
  80.           able  files  with  a  trailing asterisk (`*'), symbolic
  81.           links  with  a  trailing  at-sign  (`@'),  and  AF_UNIX
  82.           address  family  sockets  with  a  trailing equals sign
  83.  
  84.  
  85.      -g   For ls, show the group ownership of the file in a  long
  86.           output.   For  /usr/5bin/ls,  print a long listing, the
  87.           same as -l, except that the owner is not printed.
  88.  
  89.      -i   For each file, print the i-number in the  first  column
  90.           of the report.
  91.  
  92.      -l   List in long format,  giving  mode,  number  of  links,
  93.           owner, size in bytes, and time of last modification for
  94.           each file.  If the file is  a  special  file  the  size
  95.           field  will  instead contain the major and minor device
  96.           numbers.  If the time of last modification  is  greater
  97.           than  six  months ago, it is shown in the format `month
  98.           date year';  files  modified  within  six  months  show
  99.           `month  date time'.  If the file is a symbolic link the
  100.           pathname of the linked-to file is printed  preceded  by
  101.           `->'.  /usr/5bin/ls will print the group in addition to
  102.           the owner.
  103.  
  104.      -L   If argument is a symbolic link, list the file or direc-
  105.           tory the link references rather than the link itself.
  106.  
  107.      -q   Display non-graphic  characters  in  filenames  as  the
  108.           character ?; for ls, this is the default when output is
  109.           to a terminal.
  110.  
  111.      -r   Reverse the order of sort to get reverse alphabetic  or
  112.           oldest first as appropriate.
  113.  
  114.      -R   Recursively list subdirectories encountered.
  115.  
  116.      -s   Give size of each file, including any  indirect  blocks
  117.           used  to  map  the  file, in kilobytes (ls) or 512-byte
  118.           blocks (/usr/5bin/ls).
  119.  
  120.      -t   Sort by time modified  (latest  first)  instead  of  by
  121.           name.
  122.  
  123.      -u   Use time of last access instead  of  last  modification
  124.           for  sorting (with the -t option) and/or printing (with
  125.           the -l option).
  126.  
  127.      -1   (ls only) Force one entry per line output format;  this
  128.           is the default when output is not to a terminal.
  129.  
  130. SYSTEM V OPTIONS
  131.  
  132.      -b   Force printing of non-graphic characters to be  in  the
  133.           octal \ddd notation.
  134.  
  135.      -m   Stream output format; the file names are printed  as  a
  136.           list  separated by commas, with as many entries as pos-
  137.           sible printed on a line.
  138.  
  139.      -n   The same as -l, except that the owner's UID and group's
  140.           GID  numbers  are  printed,  rather than the associated
  141.           character strings.
  142.  
  143.      -o   The same as -l, except that the group is not printed.
  144.  
  145.      -p   Put a slash (`/') after each filename if that file is a
  146.           directory.
  147.  
  148.      -x   Multi-column output with entries sorted  across  rather
  149.           than down the page.
  150.  
  151.  
  152. Copying and Moving Files
  153.  
  154. To copy a file use cp, cp <source> <target>.  To copy the file myfile.txt to
  155. another directory from the current directory you would type (without the ")
  156. "cp myfile.txt /home/mydir/myfile.txt".
  157.  
  158. cp switches:
  159.  
  160.      -i   Interactive.  Prompt for confirmation whenever the copy
  161.           would  overwrite  an existing file.  A y in answer con-
  162.           firms that the copy should proceed.  Any  other  answer
  163.           prevents cp from overwriting the file.
  164.  
  165.      -p   Preserve.  Duplicate not only the contents of the  ori-
  166.           ginal file or directory, but also the modification time
  167.           and permission modes.
  168.  
  169.      -r
  170.      -R   Recursive.  If any of the source files are directories,
  171.           copy  the directory along with its files (including any
  172.           subdirectories and their files); the  destination  must
  173.           be a directory.
  174.  
  175.  
  176.  
  177. To move a file type mv <source> <target>, see the example above and switch mv
  178. with cp.
  179.  
  180. To rename a file use the mv command.  To rename myfile.txt to yourfile.txt
  181. type "mv myfile.txt yourfile.txt".
  182.  
  183. mv switches:
  184.  
  185.      -    Interpret all the following arguments  to  mv  as  file
  186.           names.  This allows file names starting with minus.
  187.  
  188.      -f   Force.  Override  any  mode  restrictions  and  the  -i
  189.           option.  The -f option also suppresses any warning mes-
  190.           sages about  modes  which  would  potentially  restrict
  191.           overwriting.
  192.  
  193.      -i   Interactive mode.  mv displays the name of the file  or
  194.           directory  followed  by a question mark whenever a move
  195.           would replace an existing file or  directory.   If  you
  196.           type  a  line  starting  with y, mv moves the specified
  197.           file or directory, otherwise mv does nothing with  that
  198.           file or directory.
  199.  
  200. To delete a file use rm.  Careful with rm!!!  We all shoot ourselves in the
  201. foot with this one once in a while, be especially careful if you are running
  202. from root as to what directory you are in before typing rm -f *...we all think
  203. we are in another directory when that one first bites us.  rm -rf * is worse,
  204. but you'd have to be really ignorant to type that by accident.
  205.  
  206. The switches for rm are as follows:
  207.  
  208.      -f   Attempt to remove files without displaying permissions,
  209.           asking questions or reporting errors.
  210.  
  211.      -i   Ask whether to delete each file, and, under -r, whether
  212.           to   examine  each  directory.   Sometimes  called  the
  213.           interactive option.
  214.  
  215.      -r   Recursively delete the contents  of  a  directory,  its
  216.           subdirectories, and the directory itself.
  217.  
  218.  
  219. Making and Deleting Directories:
  220.  
  221. To make a directory use mkdir.  To remove one use rmdir.
  222.  
  223.  
  224. Setting Permissions:
  225.  
  226. UNIX has file and directory permissions.  You can assign and remove the
  227. ability for others to read, write, or even see specific files or directories.
  228. To set and change these permissions we use chmod <mode> <filename>.
  229.  
  230. You see permissions in an ls -l and they look something like this:
  231.  
  232. -rwxr-x---  1 root          871 Sep 30 15:08 foo.sh
  233. drwxr-x---  1 root         1024 Sep 30 15:08 mydir
  234.  
  235. After the first letter (signafying a directory or file, the letters are
  236. grouped in threes ((r)ead, (w)rite, (x)ecute) for owner, group, other.  chmod
  237. assigns numbers to each as follows:
  238.  
  239. Owner:
  240.      r - 400
  241.      w - 200
  242.      x - 100
  243.  
  244. Group:
  245.      r - 40
  246.      w - 20
  247.      x - 10
  248.  
  249. Other:
  250.      r - 4
  251.      w - 2
  252.      x - 1
  253.  
  254.  
  255. So if I wanted the owner (chances are you, unless your administering a server)
  256. of the file only to be able do do everything with it and everyone else not to
  257. be able to do anything then yoy want the permissions to look like this:
  258.  
  259. -rwx------
  260.  
  261. This means you are using only the owners set of numbers, so add them up...
  262.  
  263. 400+200+100 = 700
  264.  
  265. so chmod 700 myfile.
  266.  
  267. Say you want to be able to do everything to your file, but you also want to
  268. give a certain group of people the ability to read it, but not write to it.
  269. That means you want the permissions to look like this:
  270.  
  271. -rwxr-----
  272.  
  273. So use only those numbers and add them:
  274.  
  275. 400+200+100+40 = 740
  276.  
  277. So,
  278.  
  279. chmod 740 myfile
  280.  
  281. get it?  good.  Some common settings:
  282.  
  283.      rwx------ -> 700 - only you have permissions
  284.      rwxr--r-- -> 744
  285.      rwxrw-r-- -> 764
  286.      rwxrwx--- -> 770
  287.      rwxr-xr-x -> 755 - common web setting
  288.  
  289.  
  290.  
  291.  
  292.  
  293. That should give you some of the basics for working in UNIX.  I will continue
  294. with this series as I have time.  The next one will be on using a default
  295. editor like vi, using ftp, and some other items.
  296.  
  297. I am posting these in the interest of rebuilding 2600 into a group for more
  298. than just spam and other "l33t" crap!  This was once a great group, I remember
  299. (been in the field for over 15 years), now it is laughable.
  300.  
  301. I will also be answering posts in here when I have the time, been doing it for
  302. a little while now anyway, I have no sig at all...why waste the space...  I
  303. post from a number of different accounts, but really don't care about who
  304. knows my identity...ask and I'll tell you.  I just use a false email address
  305. so that my mailbox doesn't fill up with crap.
  306.  
  307. I offer only information that I think others may find useful, from newbies on
  308. up, I will not respond to flames, challenges, can-i-crack-this, who's
  309. "l33ter", or any posts with too many z's in them  ;)  I only think that
  310. contributes to the degradation of the group.
  311.  
  312. If someone finds what I say to be inacurate, or wishes to expand upon
  313. it...feel free to say so in an intelligent manner.  If you find fault with my
  314. grammer or spelling...tough...I don't get paid for that...I get paid for my
  315. systems knowledge, besides I intentionally mistype some words all the
  316. time...for a reason.  In short, lets have an intelligent well thought out
  317. discussion, not a flamefest.
  318.  
  319.