Presented by....

UNIX can be defined as a computer operating system providing multithreaded, multi-user, and multitasked services.

Technically speaking, the UNIX kernel "is" the operating system. It provides the basic full time software connection to the hardware.

By full time, I mean that the kernel is always running while the computer is turned on. When the system boots up, the kernel is loaded. Likewise, the kernel is only exited when the computer is turned off.

The UNIX kernel is built specifically for a machine when it is installed. It has a record of all the pieces of hardware it needs to talk to and knows what languages they speak (how to turn switches on and off to get a desired result). Thus, a kernel is not easily ported to another computer. Each individual computer will have its own tailor- made kernel. And if the computer's hardware configuration changes during its life, the kernel must be "rebuilt" (told about the new pieces of hardware).

However, though the connection between the kernel and the hardawre is "hardcoded" to a specific machine, the connection betwen the user and the kernel is generic. That is the beauty of the UNIX kernel. From your perspective, regardless of how the kernel interacts with the hardware, no matter which UNIX computer you use, you will have the same kernel interface to work with. That is beacuse the hardware is "hidden" by the kernel. The kernel also handles memory management, input and output requests, and process scheduling for time-shared operations (we'll talk more about what this means later).

To help it with its work, the kernel also executes daemon programs which stay alive as long as the machine is turned on and help perform tasks such as printing or serving web documents.

However, the task of hiding the hardware is a pretty much full time job for the kernel. As such, it does not have too much time to provide for a fancy user-friendly interface. Thus, though the kernel is much easier to talk to than the hardware, the language of the kernel is still pretty cryptic.

Fortunately, the UNIX operating system has built in "shells" which wrap around the kernel and provide a much more user-friendly interface. Let's take a look at shells.

SHELLS

As we said, since the kernel is responsible for so many complex tasks (translation, memory and file system management, etc), it typically cannot spend too much time making life too easy for the person using it. Its user interface, though much better than that of the hardware, still sucks for the average user.

Fortunately, UNIX implements another layer of abstraction that envelops the kernel. This next layer is called a shell.

The benefit of a shell, of course, is that it is built primarily for people. Time and energy have been taken to develop a user-friendly interface with a language more intelligible than either the language of the hardware or that of the kernel.

The most basic UNIX shell provides a "command line" which allows you to type in commands which are translated by the shell into kernel speak and sent off to the kernel.

However, UNIX has not kept its head in the sand completely in the age of GUI. There are many excellent windowing systems which provide a much better user interface than a command line such as what is available through X-Windows or IRIX.

As we said, you use the command line to send commands to the shell. The shell translates those commands into kernel speak. And finally, the kernel sends them on to the hardware.

Layers= Hardware > Kernel > Shell > User

At this point you might be wondering why the heck there are so many translator layers between you and the hardware.

Well, this architecture follows the most basic principle of UNIX development:

Thou shalt design a community of small objects which will do only one thing, but do that one thing very well.

The developers of UNIX realized that several pieces which each do their one job well and know how to cooperate is a much better way to design software than to create one monolithic, all-knowing monster which is always breaking out of its cage and doing unpredictable and destructive things.

Thus, in UNIX, the hardware can focus solely on electronics, the kernel can focus on talking to the hardware and the shell can focus on talking to the user. Each piece has a limited task so it is able to that one task with efficiency and simplicity.

Of course, nothing is ever as simple as it is in theory. Though you will always use a shell when you are doing your work, "which" shell you will use will depend on the system you are working on. There are several basic command-line shells in use today and each has a slightly different interface and capabilities. Fortunately, they do share most of the same generic properties so it is fairly easy to switch between them.

The first UNIX shell was the Bourne Shell which is commonly abbreviated as "sh". Though this is the default shell which comes with every version of UNIX, it is the oldest and least snazzy of the shells since it has not been modified in several decades and has thus not kept up with interface advances.

The C Shell was created next at Berkeley and added several cool features like command line editing and history management. Unfortunately it was not particularly compatible with the Bourne Shell.

The Korn came next to take the good from both the C Shell and the Bourne Shell.

Bourne Shell sh The oldest of the shells which was designed by Steve Bourne. It is considered a bit primitive but very good for scripting.

C Shell csh The C Shell is probably the most popular. However, though it adds many nice features (like history and job control) unavailable in the Bourne Shell, it is quite buggy for heavy users.

Korn Shell ksh David Korn wrote this shell to be compatible with the Bourne Shell but include the cool features introduced by the C Shell. However, it did the C Shell one step further and introduced history editing.

Bourne Again Shell bash Similar to the Korn Shell but with some additional features like a built in help command.

tcsh tsch An extended version of the C Shell with the features introduced by ksh and bash.

I use TCSH and the ZSH shells exclusively. Tcsh because it is the BSD shell, and ZSH because of its exceptional power and adaptability. I use it for the following:: # Command line editing:

# programmable completion: incorporates the ability to use the full power of zsh's globbing and shell programming features, # multi-line commands editable as a single buffer (even files!), # variable editing (vared), # command buffer stack, # print text straight into the buffer for immediate editing (print -z), # execution of unbound commands, # menu completion in two flavours, # variable, editing function and option name completion, # inline expansion of variables and history commands.

# Globbing --- extremely powerful, including:

# recursive globbing (cf. find), # file attribute qualifiers (size, type, etc. also cf. find), # full alternation and negation of patterns.

# Handling of multiple redirections (simpler than tee). # Large number of options for tailoring. # Path expansion (=foo -> /usr/bin/foo). # Adaptable messages for spelling, watch, time as well as prompt (including conditional expressions). # Named directories. # Comprehensive integer and floating point arithmetic. # Manipulation of arrays (including reverse subscripting). # Associative arrays (key-to-value hashes) # Spelling correction

Running Programs

To use utilities, you must use the shell. Specifically, you tell the shell to execute a utility on your behalf.

The most basic tool provided by the shell is the command interpreter. Specifically, the shell executes utilities (or programs) specified by the user. To execute a utility, you must follow the basic format of command followed by a "-" followed by optional options and arguments as in:

command -options arguments

Right off the bat, you may execute any of the utilities found in "/bin" or "/usr/bin". You can also use the command interpreter to execute any executable utility that you install.

On GUI enabled Linux and BSD systems, each application, represented by an icon or list name within the menu system of a Window Manager/Desktop Manager will automatically execute the command line for the user via a simple click of the mouse.

However, there are strict CLI commands that every user should know. The first one I would like to present is the "man" command, issued in a terminal.... after the "prompt" $ or % or # in the case of

An excellent resource on all UNIX systems that allows you to get the documentation for any installed utility is the "man" utility.

After opening a terminal, the user types "man" (without the quotes) followed by the name of the application, utility, or even command for which one needs information.

Here's what "man man" comes up with on my system::

***************************************

Last login: Tues Apr 22 10:49:05 on ttyp1 Live Free or Die! [Kaos:~] kaos% man man

MAN(1) System General Commands Manual MAN(1)

NAME man - format and display the on-line manual pages

SYNOPSIS man [-adfhkotw] -m -p -M -P -S [section] name ...

DESCRIPTION Man formats and displays the on-line manual pages. This version knows about the MANPATH and PAGER environment variables, so you can have your own set(s) of personal man pages and choose whatever program you like to display the formatted pages. If section is specified, man only looks in that section of the manual. You may also specify the order to search the sections for entries and which preprocessors to run on the source files via command line options or environment variables. If enabled by the system administrator, formatted man pages will also be compressed with the `%compress%' command to save space.

The options are as follows:

-M path Specify an alternate manpath. By default, man uses manpath(1) (which is built into the man binary) to determine the path to search. This option overrides the MANPATH environment variable.

-P pager Specify which pager to use. By default, man uses %pager%. This option overrides the PAGER environment variable.

-S list List is a colon separated list of manual sections to search. This option overrides the MANSECT environment variable.

-a By default, man will exit after displaying the first manual page it finds. Using this option forces man to display all the manual pages that match name, not just the first.

-d Don't actually display the man pages, but do print gobs of debugging information.

-f Equivalent to whatis.

-h Print a one line help message and exit.

-k Equivalent to apropos.

-m machine As some manual pages are intended only for specific architectures, man searches any subdirectories, with the same name as the current architecture, in every directory which it searches. Machine specific areas are checked before general areas. The current machine type may be overridden using this option or by setting the environment variable MACHINE to the name of a specific architecture. This option overrides the MACHINE environment variable.

-o Look for original, non-localized manpages only.

By default, man searches for a localized manpage in a set of locale subdirectories of each manpath(1) component.

Locale name is taken from the first of three environment variables with a nonempty value: LC_ALL, LC_CTYPE, or LANG, in the specified order.

If the value could not be determined, or is not a valid locale name, then only non-localized manpage will be looked up.

Otherwise, man will search in the following subdirectories, in the order of precedence:

<lang>_<country>.<charset> <lang>.<charset> en.<charset>

For example, for ``de_DE.ISO8859-1'' locale, man will search in the following subdirectories of the /usr/share/man manpath component:

/usr/share/man/de_DE.ISO8859-1 /usr/share/man/de.ISO8859-1 /usr/share/man/en.ISO8859-1

Finally, if the search of localized manpage fails, it will be looked up in the default /usr/share/man directory.

-p string Specify the sequence of preprocessors to run before nroff or troff. Not all installations will have a full set of preprocessors. Some of the preprocessors and the letters used to designate them are: eqn (e), grap (g), pic (p), tbl (t), vgrind (v), refer (r). This option overrides the MANROFFSEQ environment variable.

-t Use %troff% to format the manual page, passing the output to stdout. The output from %troff% may need to be passed through some filter or another before being printed.

-w Don't actually display the man pages, but do print the location(s) of the files that would be formatted or displayed.

ENVIRONMENT LC_ALL, LC_CTYPE, LANG These variables specify the preferred language for manual pages. (See the -o option above.)

MACHINE If MACHINE is set, its value is used to override the current machine type when searching machine specific subdirectories.

MANPATH If MANPATH is set, its value is used as the path to search for manual pages.

MANROFFSEQ If MANROFFSEQ is set, its value is used to determine the set of preprocessors run before running nroff or troff. By default, pages are passed through the table preprocessor before nroff.

Cron jobs and cleanups:::

It's a bit early for this because I have not yet explained the "sudo" command, but I can't resist::

A Unix OS will periodically run a background tasks that removes system files that are no longer needed for its use. This process will include purging information from log files and deleting temporary items.

This will not happen if your machine and you are turned off and taking a nap.

If you do not make sure that these cleaning tasks are not done the files will become VERY, VERY LARGE.

And you know that you don't want that, do you ??

These automatic tasks are often set up to run between 03:00 to 06:00 am based off the time set on your machine.

these tasks are collectively called "cron jobs" and could lead to loss of sleep if they are not set by the user to reasonable times. I will explain how to do that later, when I fully explain "sudo"....

You can open up your terminal and run this yourself.

Step #1 - Open you Terminal. Step #2 - Type this in your terminal - sudo sh /etc/daily

"daily" will do the cleaning that is scheduled to be done daily " weekly" will do the cleaning that is scheduled to be done weekly " monthly" will do the cleaning that is scheduled to be done monthly

I do not recommend running the "monthly" however. Later, we will set this to be launched automatically at a reasonable time.

Step #3 - Press return/enter Step #4 - Now enter your Admin password when you are asked, then press return/enter. Step # 5 - Quit the terminal app.

You are good to go.

Now re-do these steps for the other and you will ALL CLEAN.

Rich's Question Re: CRON JOBS AND CLEANUPS

Heh, heh, well I gave it the royal try, but the results are kind of interesting. I got the following.

####@#######$ sudo sh /etc/daily

We trust you have received the usual lecture from the local System Administrator. It usually boils down to these two things:

#1) Respect the privacy of others. #2) Think before you type.

rich is not in the sudoers file. This incident will be reported.

So, tell me, how do I get on the sudoers file, and where exactly was I reported? LOL I tried to do this. Honest, I really tried. I do not wish to have bloat from not cleaning things up. That is why I jumped on it so fast.

Rich's Question Answered

The sudo configurations are stored in /etc/sudoers. This file should be edited using visudo, which locks the file to prevent simultaneous changes and checks for valid grammar and syntax.

That said::::

# root and users in group wheel can run anything on any machine as any user root ALL = (ALL) ALL

...is a sample sudoers file. As I said, you cannot edit this with anything BUT vi..., or visudo to be exact.

Here is MY sudoers file::

# sudoers file. # # This file MUST be edited with the 'visudo' command as root. # # See the sudoers man page for the details on how to write a sudoers file. #

# Host alias specification

# User alias specification

# Cmnd alias specification

# Defaults specification

# User privilege specification root ALL=(ALL) ALL **************************

So this means that you "rich" will have to become a member of "wheel" and/or "admin". You can do this via the mandrake control center. I forgot where exactly because I am on BSD now. It's the place where you manage logins, logouts, and users.

You could try to edit the "/etc/sudoers" file via the KFMsu or the "KDE File Manager Super User Mode" Just navigate using the file manager to the /etc/sudoers file then make sure that the file looks like what is above. That's all.

Then add the user "rich" to the wheel and the admin groups via the Mandrake Control Center.

But before you do that make sure that you see this in your sudoers file::

# User privilege specification root ALL=(ALL) ALL

NOTE::if your system has #admin ALL=(ALL) ALL, just leave it like that.

If not, then edit it yourself. If the KDEsu method does not work, then you'll have to login as root and issue the command "visudo" <enter>. this will bring up the vi text editor with the /etc/sudoers file opened and ready for editing. Take a deep breath before editing. The format is important. Don't forget that your prompt will be #, which signifies root in bash. Within vi, you must use the arrows on the keyboard to move the cursor within the text to edit. After the editing is done, type :q to quit.

The object is to add rich to admin and/or wheel groups. I am sure this can be done by the Mandrake Control Center. If you succeed in that, try the sudo commands again to see if everything works properly. You may have to logout and back in before the system realized there is a "rich" in "wheel" and "admin."

If my Linux memory serves me right, the following addition to the sudoers file should work just fine for you.

Assuming that your "user" is named rich.

# User alias specification User_Alias SENIORADMIN=rich User_Alias ASSISTANTS=(here you can add martha or another user that has a login account)

# User privilege specification

SENIORADMIN ALL=ALL ASSISTANTS ALL=ALL

Don't forget this is an ADDITION to the file... don't delete what's there. I have an idea: copy the file and post it here and I look at it first if you want.. You add this to the sudoers file using the command "visudo" as root.... The hash mark in this case means a hashed-out comment line that is for humans only, in other words, the machine doesn't read the lines beginning with "#" in a config file you write. ############################### WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW ###############################

The following is for later::: and not necessary to get sudo working..., but it's nice to know.

To add another user use the "useradd" command..

type:::

sudo useradd (name of newuser)

if your sudo is working,. If not you'll have to use root.

That will add a new user in the /etc/passwd file and in /etc/shadow if you use shadow passwords, which you probably do by default in Mandrake.

You still have to create a password for the new user Type:::

passwd (newusername)

You will then be prompted to enter a password for the new user twice. After it is accepted, it will be encrypted and stored in the /etc/shadow file. But don't create a new user unless you want to have an additional home directory for that new user. On will be created when you create a new user like that.

So Richard..., it boils down to two thingies (I love that tech talk)::::

You add "rich" to the admin and/or wheel group(s).... via the GUI in the Mandrake Control Center..., or you add "rich" to the "sudoers" file in the way I mentioned above.

The next subjects will follow in this order (more or less)::

...sudo

...cron

...other basic terminal commands

...editing system files with jEdit, pico or NEdit (all easy), and just why Emacs (ridiculously difficult) sucks...

...editing with Vi and/or Vim (just because it's always there on every Unix system)...

...using Pine mail..., which should act as a practice application to enable the user to become familiarized with non-GUI and semi-GUI applications, installations, and configuration editing...

...permissions, users, groups, etc.

How to perfectly install tarballs and source tar files on any Unix system..., while meeting all dependencies, which should make the user totally independent of glitchy automated software installers and enable the user to have a customized system that meets particular needs.

and the list is so long, I need a break. I'll continue the list after I write a few of the above-mentioned articles.

I am now in the process of building/configuring a mini server on my system that will enable any one or all of you to click on my URL and see my screen in real time, terminal, apps running and all. This will be useful for answering individual questions about commands etc. All you'll have to do is to watch my arrow and see just how I do stuff.

FOR RED HAT LINUX USERS::

1. Download Apt4rpm for Red Hat Linux 9 2. Open a console and su root 3. rpm -Uvh apt*rpm 4. apt-get update 5. apt-get install synaptic 6. synaptic 7. Welcome to the candy store.

::::::::ABSOLUTE & RELATIVE PATHS::::::::

The first thing we need to understand is how the file system is addressed. That is, how do you know where within the file system you are or where your file is located?

UNIX has an address system based upon file paths. A file path specifies the route that you need to take in order to find a file within the file tree much like a map directs you from one location to another.

In UNIX, all paths start from the "root" directory. The root directory is specified by a single slash "/" character. From there, steps along the path are separated by successive slash characters.

Thus, the path "/usr/butthead/public_html/index.html" specifies a file called "index.html" which is located in the "public_html" directory, which is a sub-directory of "butthead", which is a sub-directory of "usr", which is itself a sub-directory of "root"!

This type of path is called an absolute path because it references a file or directory absolutely from the root.

However, paths can also be relative to your current location within the file system. To specify a relative path, you do not specify the path from "root" by not including the initial slash character.

For example, if we were currently located in the "butthead" sub-directory, we could refer to the file "index.html" using the path "public_html/index.html". Notice that since we do not include the initial "/" UNIX will assume that the specified path is relative to your current location which is "/usr/butthead".

Two final important path tools are the ".." and "." notations. In short, ".." stands for the directory directly above the present directory and the "." refers to the present directory.

Thus, if we were in the "public_html" directory from our example above, "./.." would stand for the "butthead" directory and "./../.." would stand for the "usr" directory. If this is all a bit confusing now don't worry, you can learn this by actually doing it on a UNIX machine. It will all make more sense when you can do it yourself.

Relative paths are pretty useful, but how do you know where you are in order to determine the relative location of something you want to access?

Well, UNIX provides the "pwd" utility just for this purpose. The "pwd" utility lets you know in which directory you currently are in such as in the following example in which I have used the pwd utility. You can see that the result was "/home/butthead" which means that we are located in the butthead directory which is a subdirectory of home which is located in the root directory itself. ################# kaos% pwd /Users/kaos/butthead [Kaos:~/butthead] kaos

The CD command

In the terminal you will often need to be able to do is move from where your are to someplace else. To do so, you will use the "cd" (change directory) command.

################################ Last login: Wed Apr 23 15:46:08 on ttyp1 Live Free or Die! [Kaos:~] kaos% pwd /Users/kaos [Kaos:~] kaos% cd /usr/bin [Kaos:/usr/bin] kaos% pwd /usr/bin [Kaos:/usr/bin] kaos% cd /usr/local [Kaos:/usr/local] kaos% cd [Kaos:~] kaos% ###############################

As you can see I took a trip around the system using "cd" and verifying where I was after each change with the "pwd" command.

The last command I gave was simply "cd" which takes one back to the home [~/] directory. Her are the basic "cde" commands::

cd / Goes directly to the root directory

cd Moves you from anyplace on the system directly to your home directory

cd .. Moves you one directory up

cd /usr Moves you directly to the /usr directory

cd /usr/bin cd lib Moves you to the /bin directory and then moves you to the lib sub-directory relative to bin.

:::THE SUDO COMMAND:::

So, now that you know how to change directories within your system as a whole, what does on do when you get to wherever you're going? Before we get into that, and the most powerful Unix command of them all the rm -rf, I will have to briefly explain SUDO.

"sudo" is short for "superuser do", which means that you will be allowed to execute any command, change or edit any file, delete any directory, as if you were logged in as ROOT. The difference is that the sudo command is valid for the operation at hand, determined by a "timeout". No need to worry about the timeout, because it is already set on Unix systems. Normally one uses the user password and not the ROOT password when using sudo, because sudo applies to one or more users on the system, and the system only verifies if the authorized user is attempting the sudo command. Thus it asks for the user's password. If the user in question is on the authorized list, he will be granted a certain time to accomplish whatever tasks he has in mind, as if he were the ROOT user with full system read/write/execute access.

BTW "sudo" is pronounced SOO-doo, and not "pseudo"...

NOTE: Only people with administrator may use the sudo command.

Let's say that you have a file you want to trash called whatdafuck. Now whatdafuck happens to be in the root directory and you do not want to logout and back in as root because you may be connected to the web at the time and being full root, would be totally insecure. "whatdafuck" is located at /usr/local/hodpodge/whatdafuck. You can't just drag it to the trash, because that would require root privs. Here's how to do it with sudo: Open a terminal... type "sudo rm /usr/local/hodgepodge/whatdafuck

That's it after a password verification.

Now what if you wanted to delete the "hodgepodge" DIRECTORY in which the file "whatdafuck" is located? Here is the command. NOTE that this is the most powerful and potentially destructive of all Unix commands.

sudo rm -rf /usr/local/hodgepodge

That means:

"sudo" = give me the power

rm = remove (totally trash)

-r = and all the directories/files inside it

-f = force if necessary

I once deleted "/usr/local"... all of it... form my machine because I accidentally inserted a space after the "local".... I wanted to delete "/usr/local/netscape", and I mistakenly typed "/usr/local /netscape"... I just silently watched as 55 MB of files went down the drain in a few seconds.

There will be much more on the sudo command soon, like how to edit the sudoers file to add and change users.... with sudo privs.

::: THE ls COMMAND ::: ::: and hidden files :::

ls +

-A Lists "ALL" files (including hidden ones) but not the current or parent directories ("." or ".."). -a Lists "ALL" files including hidden ones and both current and parent directories ("." and ".."). -C Lists files in columns sorted from top to bottom, left to right. -d lists directory names only. This is very useful since "ls directory_name" will give you the listing of that directory rather than showing you if the named directory is actually in the current. -F Adds a "/" for directories and a "*" for executables. -i Lists the inode number. -l Provides a "long" listing with details about such things as file permission, age, date created, date of last modification, etc. -r Reverses the sort order. -R Lists sub-directories recursively. -x Lists files in columns sorted from left to right then top to bottom.

************************************** Here's an example from my system:::::::::: **************************************

Last login: Wed Apr 23 16:18:11 on console Live Free or Die! [Kaos:~] kaos% ls #Xauth-OSX DEADJOE Movies basefiles miscellaneous #Xauthority Desktop Music bin nano.save #cshrc Desktop Folder Pictures butthead new #pico00500# Documents Public db-4.1.24 pico.save BBEditS Downloads Sites dcc ports Background Icons Works dead.letter tarballs Bookmarks Library XX.Xclients geekcode.sig wget Choices Mail Xthemes log.0000000001 xfskins

***************************************** Example 2 ::::::::::::::::::::::::::::::::::: ***************************************** [Kaos:~] kaos% ls -a #Xauth-OSX .deskmenurc .pinerc Sites #Xauthority .emacs .tcsh_history Works #cshrc .emacs.d .tcshrc XX.Xclients #pico00500# .esd_auth .tcshrc~ Xthemes . .ispell_english .thumbnails basefiles .. .java BBEditS bin .AbiSuite .jcrontab Background butthead .CFUserTextEncoding .jedit Bookmarks db-4.1.24 .DS_Store .jpi_cache Choices dcc .ICEauthority .links DEADJOE dead.letter .MCXLC .login Desktop geekcode.sig .MacOSX .logout Desktop Folder log.0000000001 .OpenTerminalHere .mailfilterrc Documents miscellaneous .Trash .mc Downloads nano.save .addressbook .mcop Icons new .addressbook.lu .mcoprc Library pico.save .autosave .mucommander Mail ports .bash_history .pine-debug1 Movies tarballs .cedit .pine-debug2 Music wget .cvspass .pine-debug3 Pictures xfskins .desklaunchrc .pine-debug4 Public [Kaos:~] kaos% **************************************

Note that the first "ls command gives the basic stuff whereas in the second example the "ls -a" command shows all the hidden files.

Notice in the example above, the ls command turned up quite a different file list than the ls -a even though they were listing the same directory. This is because the ls -a command lists hidden files as well as normal files.

A Hidden File is a file whose name begins with a period. These files are usually administrative files and are often distracting when you are doing your daily work. Thus UNIX hides them unless you specifically ask to see them with the -a option

Focus on the "-l" Option Before moving on, we should say a little bit more about the "-l" option because you will find yourself using this one quite a bit when you want to know more information about the files and directories in a listing.

The image below shows a typical "-l" listing. In the image you will see that there are several fields listed for each file.

************************************

Last login: Wed Apr 23 16:40:45 on ttyp1 Live Free or Die! [Kaos:~] kaos% ls -l total 496 -rw------- 1 kaos staff 0 Nov 8 07:24 #Xauth-OSX -rw------- 1 kaos staff 0 Feb 24 20:39 #Xauthority -rw-r--r-- 1 kaos staff 373 Apr 1 20:09 #cshrc -rw------- 1 kaos staff 1455 Nov 10 19:35 #pico00500# drwxr-xr-x 10 kaos staff 340 Feb 13 20:34 BBEditS drwxr-xr-x 25 kaos staff 850 Apr 21 13:00 Background drwxr-xr-x 9 kaos staff 306 Apr 23 09:11 Bookmarks drwxrwxr-x 4 kaos staff 136 Jan 8 08:56 Choices -rw------- 1 kaos staff 2302 Apr 1 09:41 DEADJOE drwxr-xr-x 13 kaos staff 442 Apr 23 16:38 Desktop drwxr-xr-x 4 kaos staff 136 Dec 16 00:00 Desktop Folder drwxrwxrwx 226 kaos staff 7684 Apr 23 10:33 Documents drwxr-xr-x 29 kaos admin 986 Apr 23 12:31 Downloads drwxr-xr-x 13 kaos staff 442 Apr 9 20:53 Icons drwxr-xr-x 30 kaos staff 1020 Apr 23 07:32 Library drwxrwx--- 45 kaos staff 1530 Apr 15 18:34 Mail drwxr-xr-x 3 kaos staff 102 Apr 3 13:54 Movies drwx------ 4 kaos staff 136 Oct 16 2002 Music drwxrwxrwx 16 kaos staff 544 Apr 21 21:17 Pictures drwxr-xr-x 4 kaos staff 136 Oct 5 2002 Public drwxr-xr-x 6 kaos staff 204 Nov 1 15:49 Sites drwxr-xr-x 5 kaos staff 170 Oct 9 2002 Works -rwxr--r-- 1 kaos staff 639 Feb 13 19:39 XX.Xclients drwxr-xr-x 7 kaos staff 238 Mar 2 11:30 Xthemes drwxr-xr-x 5 root staff 170 Nov 7 21:57 basefiles drwxr-xr-x 3 kaos staff 102 Dec 4 07:25 bin drwxr-xr-x 2 kaos staff 68 Apr 23 15:38 butthead drwxr-xr-x 58 kaos staff 1972 Nov 27 16:22 db-4.1.24 drwx------ 2 kaos staff 68 Feb 27 21:42 dcc -rw------- 1 kaos staff 336 Jan 30 10:38 dead.letter -rw-r--r-- 1 kaos staff 250 Jan 7 14:41 geekcode.sig -rw-r----- 1 kaos staff 64 Nov 27 14:52 log.0000000001 drwxrwxrwx 17 kaos staff 578 Apr 2 19:10 miscellaneous -rw------- 1 kaos staff 0 Aug 13 2002 nano.save drwxr-xr-x 10 kaos staff 340 Mar 22 21:05 new -rw-r--r-- 1 kaos staff 16 Sep 15 2002 pico.save drwxr-xr-x 5 kaos staff 170 Feb 10 01:49 ports drwxr-xr-x 3 kaos staff 102 Jan 21 19:02 tarballs -rwxr-xr-x 1 root staff 220592 Nov 28 09:59 wget drwxr-xr-x 2 kaos staff 68 Mar 5 09:21 xfskins [Kaos:~] kaos% ***************************************************

The following overviews the information provided by the -l option...

File Type Is this a regular file or a directory. "-" denotes a regular file, "d" denotes a directory, "c" denotes a character special file, a "b" specifies a block special file, a "l" represents a symbolic link, and a "p" specified a named pipe.

Permissions User, Group and World privileges. We will discuss this in much greater detail in just a moment

Link Count The number of names for this file or directory

Owner We will discuss this later

Group We will discuss this later

Size The size of the file in bytes

Modification... Date The last time the file was modified File name... The file's name

The ls -l option also includes several options that affect the listing. These options are shown below:

-c Sorts by the last time the inode was changed with the -t option -t Sorts listing by modification time. -u Sorts by the last time accessed.

:::::::::::::::::THE "touch" COMMAND::::::::::::::::

Often, you will need to create new configuration files on your system. This could be "rc" or menu files, that is to say, files that control the default shell, issue automatic system commands, control the look and feel of everything from the terminal, access to man pages, menu systems for Blackbox, XFce, IceWM, etc. Many do this by opening Pico, a text editor, or vi/Vim. For example, if you wanted to create a ~/.bashrc, ~/.tcshrc, or a ~/.profile file in your home directory, you would type "pico," "nano," or "vi" in the terminal. For creating files in the root section to which the user does not usually have read/write/execute access for editing files, you would type "sudo pico /file/you/want/to/create" and at the prompt, type in your user password followed by <enter>. That's your user password, not your root password usually...., if you have sudo set up that way. Then you create the text that goes in the file. In the case of nano and pico, you hit "ctrl-X" to exit. You will be prompted to save the file. At the prompt hit "y" for yes, then enter. In vi it is much the same except for exiting, you do a ":q" for quit, then the same prompts apply.

That's pretty complicated for just making a blank file that you could access later to edit with any editor of your choice. This id where the "touch" command comes in. The "touch" command serves two primary purposes: it can be used to create empty files (to be edited later), and it can be used to modify the last access or last modification time of an existing file.

The basic format is::

touch filename

...where "filename" is the name of the file you wish to create or modify.

Use "sudo touch filename" to create a file in one of the many root directories.

Here is what "man touch" gives on my system::

**********************************************************************************

Thu Apr 24 06:27:56 on console
Live Free or Die! [Kaos:~] kaos% man touch

TOUCH(1) System General Commands Manual TOUCH(1)

NAME touch - change file access and modification times

SYNOPSIS touch [-acfhm] -r [-t [[CC]YY]MMDDhhmm[.SS]] file ...

DESCRIPTION The touch utility sets the modification and access times of files to the current time of day. If the file doesn't exist, it is created with default permissions.

The following options are available:

-a Change the access time of the file. The modification time of the file is not changed unless the -m flag is also specified.

-c Do not create the file if it does not exist. The touch utility does not treat this as an error. No error messages are displayed and the exit value is not affected.

-f Attempt to force the update, even if the file permissions do not currently permit it.

-h If file is a symbolic link, access and/or modification time of the link is changed. This option implies -c.

-m Change the modification time of the file. The access time of the file is not changed unless the -a flag is also specified.

-r Use the access and modifications times from the specified file instead of the current time of day.

-t Change the access and modification times to the specified time. The argument should be in the form ``[[CC]YY]MMDDhhmm[.SS]'' where each pair of letters represents the following:

CC The first two digits of the year (the century). YY The second two digits of the year. If ``YY'' is specified, but ``CC'' is not, a value for ``YY'' between 69 and 99 results in a ``CC'' value of 19. Otherwise, a ``CC'' value of 20 is used. MM The month of the year, from 1 to 12. DD The day of the month, from 1 to 31. hh The hour of the day, from 0 to 23. mm The minute of the hour, from 0 to 59. SS The second of the minute, from 0 to 61.

If the ``CC'' and ``YY'' letter pairs are not specified, the values default to the current year. If the ``SS'' letter pair is not specified, the value defaults to 0.

The touch utility exits 0 on success, and >0 if an error occurs.

SEE ALSO utimes(2)

COMPATIBILITY The obsolescent form of touch, where a time format is specified as the first argument, is supported. When no -r or -t option is specified, there are at least two arguments, and the first argument is a string of digits either eight or ten characters in length, the first argument is interpreted as a time specification of the form ``MMDDhhmm[YY]''.

The ``MM'', ``DD'', ``hh'' and ``mm'' letter pairs are treated as their counterparts specified to the -t option. If the ``YY'' letter pair is in the range 69 to 99, the year is set to 1969 to 1999, otherwise, the year is set in the 2000's.

STANDARDS The touch utility is expected to be a superset of the IEEE Std 1003.2 (``POSIX.2'') specification.

HISTORY A touch utility appeared in Version 7 AT&T UNIX.

BUGS A symbolic link can't be a reference file of access and/or modification time.

BSD April 28, 1995 BSD ^[[B[Kaos:~] kaos%

:::::::: SUDO :::::::::

For more info on the sudo command and how to edit sudoers visit http://www.quicktopic.com/21/H/5qkvhgEJEsCQ and read messages 21 +... In the meantime, type "man sudo" in a terminal.

Read the following also:::

Sudo in a Nutshell

Sudo (superuser do) allows a system administrator to give certain users (or groups of users) the ability to run some (or all) commands as root while logging all commands and arguments. Sudo operates on a per-command basis, it is not a replacement for the shell. It's features include:

¤ The ability to restrict what commands a user may run on a per-host basis.

¤ Sudo does copious logging of each command, providing a clear audit trail of who did what. When used in tandem with syslogd, the system log daemon, sudo can log all commands to a central host (as well as on the local host). At CU, all admins use sudo in lieu of a root shell to take advantage of this logging.

¤ Sudo uses timestamp files to implement a "ticketing" system. When a user invokes sudo and enters their password, they are granted a ticket for 5 minutes (this timeout is configurable at compile-time). Each subsequent sudo command updates the ticket for another 5 minutes. This avoids the problem of leaving a root shell where others can physically get to your keyboard. There is also an easy way for a user to remove their ticket file, useful for placing in a .logout file.

¤ Sudo's configuration file, the sudoers file, is setup in such a way that the same sudoers file may be used on many machines. This allows for central administration while keeping the flexibility to define a user's privileges on a per-host basis. See the samples sudoers file below for a real-world example.

http://www.courtesan.com/sudo/sample.sudoers

:::::: xargs :::::::

Last night, as I began experimenting with phpnuke, I noticed it had an instruction step that read:

"Set all files to 666 permission; set all directories to 777." Although this is relatively trivial for multiple identical items (chmod 777 *), it's a bit trickier when files and directories are mixed in the structure, with sub-directories and sub-files, and different settings for directories and files. The phpnuke package installs literally hundreds of files, and probably 25-50 subdirectories. Would I be reduced to mass changing everything in a folder (chmod 666 *), and then setting the directories by hand. That would take quite a while!

Luckily my Unix angel who is named memory and looks rather like a raven whispered the solution in my ear::

find . -type f | xargs chmod 666 find . -type d | xargs chmod 777

You may have to use "sudo" with internal files. Simply begin the command with "sudo" followed by a

This does exactly what I needed it to do. 'xargs' is an interesting command, and well worth reading up on ('man xargs'). It basically executes the command specified (chmod in this case) for each item passed to it (the results of the 'find' command, routed via the pipe '|' symbol). It's fairly easy to see how powerful xargs can be, given its ability to act on a series of things passed to it. One note of caution in this example - the 'find' command will search DOWN through the directory structure from where you start, so make sure you want to effect EVERYTHING in that path before issuing a command like that. As with many commands, don't "experiment" with this one. Use it when you must, and only then. ******* NOTE::: Next, we shall examine the subject of permissions and all the commands associated with it...... ******

:::::::::::::::::::PERMISSIONS::::::::::::::::::

In our discussion of the ls -l option, we promised to explain what we meant by permissions, owner and group. Permissions are a basic part of the UNIX security system. In short, they define who gets to do what with which files.

Specifically, permissions define who gets to:

• Read a File • Modify or delete a file • Execute a file (if it is a program)

Your access privileges are defined in the password and group files. Before we get into the nitty gritty of permissions, let's take a look at these files.

As far as UNIX is concerned, you "are" your entry in the password file that is usually stored as "/etc/passwd". Some security conscious sysadmins hide the file elsewhere, but there is a good chance that you can find the "passwd" file on your system if you do "cd /etc" then issue and "ls" command.

The password file contains single line entries for each user of the system. Each line contains 7 fields delimited by a colon ":" character that define you in a security sense. A sample line is shown below:

kaos:B8776ERDS:42:101:whassdisss:/usr/home/kaos:/usr/bin/tcsh

The fields correspond to the following index:

Field Explanation username Username for logging in password Encrypted Password or either an "x" or "*" character to specify that the password is stored in a shadow file for heightened security userid A number that identifies you uniquely to the UNIX system internals. groupid A number that specifies your login group. We'll discuss this in just a bit Comment This field can be used to store any info desired by the sysadmin. Usually it contains your name, but it can contain any desired text. home directory This is the location of your home directory (where you arrive when you first login.) shell The name of the shell you are using.

Besides the password file, you are also defined by your entry in the group file that we will look at now.

The group file contains information about UNIX groups. UNIX groups allow multiple users to be related for security purposes. This is best seen by example.

Imagine a situation in which all engineers can modify technical notes, but marketing employees can only read them. They cannot modify them. Thus, there are two groups: marketers and engineers, each with different rights in the system.

The group file is also a colon delimited file of multiple lines which looks something like this:

doctors:*:101:kaos glanz butthead

The fields are:

group name:password:group id:users

So how do you know who you are?

So how do you know who you are?

So who are you...what is recorded in your password file?

The most exacting way to find out is to look at the passwd and group files themselves. We will talk about reading files a bit later.

But another quick way to check who you are is to use the "who" utility. To do so, simply type "who am i" at the command line. UNIX will respond with your username. Sometimes when you are switching between multiple accounts, this utility can be very handy.

For a more detailed response, you might try the "id" utility that gives you your userid and groupid.

******************************************************** Last login: Wed Apr 23 21:45:23 on ttyp1 Live Free or Die! [Kaos:~] kaos% who am I kaos ttyp1 Apr 23 21:55 [Kaos:~] kaos% id uid=501(kaos) gid=20(staff) groups=20(staff), 0(wheel), 3(sys), 80(admin) [Kaos:~] kaos% ********************************************************

Okay, here is a test...when you typed in "who am i" at the command line, what utility were you using? Well the answer to that is you were using the "who" utility. "am" and "i" were simply options to the "who" utility. As you might expect, who has several other options that you may find very useful. The following table outlines those options::

If you want to sort the output of who, you can use "who | sort". Likewise, if you are only interested in a certain user, you might pipe the output of grep such as "who | grep kaos". We will talk more about grep tomorrow. however, always remember that although a user may be logged in, they may not be looking at their monitors. Sometimes people leave the station without logging off.

[Kaos:~] kaos% who | sort kaos console Apr 23 21:10 kaos ttyp1 Apr 23 21:57 ******************** [Kaos:~] kaos% who | grep kaos kaos console Apr 23 21:10 kaos ttyp1 Apr 23 21:57 *********************

Option Explanation -u Responds with the list of users currently logged on as well as their last input -am i Responds with your own username -A Responds with UNIX accounting information -T Indicates if the terminal is set to allow messages from other users -l Lists lines waiting for login -H Displays the header line -q Displays a space separated list of usernames and a list count. -d lists expired processes that have not been respawned -t Notes the last time the system date was changed -a Displays all available info -s Just like the -u option but displays only name, line and time file Specifies an alternative file from which to get login info.

:::::::::::::EXTENDED FIND:::::::::::::::::

:::::: ONE USE FOR "find":::::::

Since most of you use linux, here's a trick in BASH rather than my usual tcsh or zsh.

Using 'find' is a ONE approach to apply the same command to many files. You can write the following script to make this simpler.

#!/bin/sh if [ "$1" = " ]; then echo "Usage: `basename $0` filetype command to" exit fi

if [ "$2" = " ]; then find . -name "$1" else find . -name "$1" -exec $2 {} \; fi

This script is written in /bin/sh Don't forget to make the script file executable.

will list all matching files in the current directory and subdirectories.

will display them.

:::::MISCELLANEOUS ESSENTIAL COMMANDS:::::

Determine a file's type with "file"...

Linux does not rely on file extensions to determine file types. In Linux and other Unix operating systems, one can use the "file" command.

The following command shows what type of file /usr/local/bin/jmacs is::

Live Free or Die! [Kaos:~] kaos% file /usr/local/bin/jmacs /usr/local/bin/jmacs: symbolic link to joe

:::::::::::::::::::::::::::::::::::::::::::: Copying files and directories with "cp" ....

The cp command copies files from one place to another.

The formula is:: cp /old/place /new/place or sudo cp /old/place /new/place

sudo cp /usr/local/butthead /usr/butthead

will make a copy of butthead and place it in /usr

You may also rename a file during the copying process::

sudo cp /usr/local/butthead /usr/buttface

As you can see, a copy of butthead was renamed and moved to /usr where it will repose happily as buttface.

To copy a DIRECTORY as well as all its files and subdirectories, use the "-r" [recursive] option to copy the directory recursively.

cp -r /tmp/foofoo /fun/foofoo

I copied that from /tmp to /fun..... ********************************************** ::::::::::The "mv":::::: or move command::::::::::

The mv command is used to move files or directories. The same rules apply to mv as to cp. The only limitation is that the mv command will not move directories across different file systems. When you need to do this, you must use the "cp" command with the "-r" option, after which you may remove the old directory with the "rm" command. *************************************** :::::::::::The "rm" command::::::::::::

To delete a file or a directory, use the "rm" command. The syntax is as follows:: rm file|or|directory|name.

The following removes a file called "buttface" in /usr in the root directory::

sudo rm /usr/buttface

To remove a directory and all the files and subdirectories therein called "bubblebutt" in /usr, the command is as follows::

sudo rm -rf /usr/bubblebutt

Note that if you type rm -rf /usr /bubblebutt with a space between /bubblebutt and /usr, you will destroy your system by totally deleting the /use directory.

This is why a prompt is a good thing. Since most of you are using the bash shell on a Linux platform, you may add an "alias" to your ~/.bashrc file [/home/.bashrc].

add the following line::

alias rm rm -i

What that "-i" option does is to prompt the user before actually deleting anything. So if you typed "rm -rf /usr /bubblebutt" by mistake, you'll get a prompt asking if you really want to delete your /usr directory and destroy your system.

:::::::::::::::::::::::::::::::::::::::::::::::::::: Soon, I will explain how to edit modify, and fine tune a ~/.bashrc, a ~/.tcshrc, etc... ::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::Bash Shell configuration::::::::::::

In your .bashrc file you place any shell commands that you want executed every time you start up a new shell.

Here is the TCC standard .bashrc file with interspersed commentary.

## If we are not a login shell, source /etc/profile anyway if [ "$0" != "-bash" ] ; then . /etc/profile fi

The above lines cause the .profile file to be read even if the current shell ($0) is not bash. That file sets up your default search path.

## to add something to your path, do something like the following export PATH=${PATH}:${HOME}/bin

In the above line, the export command sets a variable in this script but also ``exports'' it so it affects things outside this script. The ${PATH} part is a special function that expands to your current search path. The ${HOME} function expands to your home directory's pathname, so effectively it adds your ~/bin directory to your search path. The colon (:) must be used to separate elements of the search path.

## set a happy editor for programs that want them export EDITOR='pico' export VISUAL='pico'

This sets up two environmental variables, EDITOR and VISUAL, that some programs expect to find to tell them what editor you like. Substitute emacs or vi for pico in the above lines if you prefer one of those editors.

set history=40

Tells bash to remember the last 40 commands you have typed. Refer to ``history substitution'' in the textbook to see how you can recall such previously entered commands and execute them again.

## some useful aliases, so new users don't hurt themselves alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias ls='ls -F'

The bash alias command sets up new commands as shorthand for longer commands. For example, the first command makes rm an alias for the rm command with the -i option so that the shell will ask the user before removing files.

## this is to fool the automounter cd ${HOME}

This command does a cd to your home directory so that pwd prints out your /u/username pathname and not the longer ``real'' (and confusing) path name.

:::THE OCTAL SYSTEM FOR SETTING PERMISSIONS:::

This is my usual method for setting permissions, It involves 1's and 0's. However, I do not recommend this method for the mathematically challenged. Although this may seem difficult at first, once you get used to it, it's as simple as tying your shoelaces while tumbling down a flight of stairs. That's why I like it so much.

The OCTAL system uses, as the name implies, sets of eight digits instead of the usual 10 digits of the decimal system. The following table shows the binary equivalent for each octal digit.

OCTAL...>...BINARY 0.............>...........000 1.............>...........001 2.............>...........010 3.............>...........011 4.............>...........100 5.............>...........101 6.............>...........110 7.............>...........111

Octal number... 1... represents: execute permissions. A user with this permission can execute the file, if executable. The su command, usually has executable permissions for the root user, because su allows the regular user to become root temporarily.

2... is permission to write. The user can modify a file via editing and save the results.

4... is permission to read. A user with read permission can do only that. With this permission only, the user can do nothing more.


3,5,6,7.... Permission combinations.


3... grants write and execute permissions [1+2]...

5... grants execute and read permissions... [1+4]...

6... grants read and write access...

7... grants rwx, or read/write/execute permissions [4+2+1]...

***************************************************************************** Here's how to use the Octal Permission Method:

Octal permission values are based on sets of four digits. When any one of the four digits of a permission value are omitted, it is considered to be a zero. In other words 300 is considered to be 0300.

octal value........digit 1--------digit 2--------digit 3--------digit 4 ......4............. set-UID............r..................r..................r..... ......2..............set-GID...........w.................w.................w..... ......1..............sticky-bit.........x..................x..................x..... ......................SPECIAL......USER........GROUP.......OTHERS

The first octal digit is used for setting special permissions, the second for setting file owner permissions, the third for group permissions, and the fourth for setting everyone else's permissions.

Special permissions require knowing whether or not the set-UID, set-GID, or sticky bit is necessary.

Set-UID - User ID:

When an executable is run with set-UID permissions, the prosess runs on behalf of the owner of the file. If butthead runs Open Office, in other words, butthead will be subject to the privileges set for him. But if the file is owned by root with read/write/execute permissions, butthead will essentially have root privileges while running Open Office.

NOTE:: If a set-UID root file is set accidently so that it can be alteren by anyone BUT root, you've got a major security problem. So be really careful when setting the set-UID.

Set-GID - Group ID:

When an executable with set-GID is run, it will carry all the privileges of that file's group.

The Sticky Bit:

This is not frequently used. Its purpose is to tell the operating system to keep an executable's program image in memory even after it exits. This is supposed to reduce the startup time of a large program. This may come in real handy for Open Office, but normally one avoids this part of the digital permission series.

That's it for what many consider to be the most difficult way to manipulate system permissions. Next, I will delve into using Access Strings to set permissions, which many believe is a simpler method.

:::::::Tell me More, Man:::::::

Don't forget to learn more about a command by reading the manual.

::::::::::More UNIX Commands::::::::::

* jobs --- lists your currently active jobs (those that you put in the background) and their job numbers. Useful to determine which one you want to foreground if you have lots of them. * bg --- background a job after suspending it. * fg %jobnumber --- foreground a job * !! --- repeat the previous command (but CTRL-p, is safer, because you have hit return in addition) * !pattern --- repeat the last command that starts with pattern * echo $VARIABLE --- shows the value of an environment variable * setenv --- lets you set environment variables. For example, if you typed a wrong value for the TERM variable when logging in, you don't have to log out and start over, but you can just do setenv TERM vt100 (or whatever). To see what all your environment variables are set to, type env. The one that you're most likely to have to set is the DISPLAY variable, when using an X-display. * unset VAR --- lets you un-set environment variables. Useful, for example, if you've usually set autologout but want to stay logged on for a while without typing for some reason, or if you set the DISPLAY variable automatically but want to avoid opening windows for some reason. * source filename --- you need to source your dotfiles after making changes for them to take effect (or log off and in again) * load --- will show you the load average graphically * ispell filename --- will check the spelling in your file. If you're running it on a LaTeX file use the -T option to tell it to ignore the LaTeX commands. You can create and use your own dictionary to avoid having it tell you that your own name, those of fellow linguists, and linguistics terminology are a typos in every paper you write. * weblint --- checks the syntax of html files * latex2html --- translates LaTeX files into HTML * wn word option --- lets you access the WordNet database and display, for example, synonyms, hypernyms, or hyponyms, depending on the option you select

Command editing in the tcsh These things are the same as in emacs: Backspace --- delete previous character CTRL-d --- delete next character CTRL-k --- delete rest of line CTRL-a --- go to start of line CTRL-e --- go to end of line CTRL-b --- go backwards without deleting CTRL-f --- go forward without deleting Other useful things

TAB --- complete filename or command up to the point of uniqueness CTRL-u --- cancel whole line CTRL-p --- show the last command typed, then the one before that, etc. (you can also use the cursor up key for this) CTRL-n --- go forwards in the history of commands (you can also use the cursor down key for this) CTRL-c --- cancel the processes after it has started CTRL-z --- suspend a running process (e.g. in order to do something else in between) you can then put the process in the background with bg CTRL-l --- redraws the screen

(piping) --- Lets you execute any number of commands in a sequence.

The second command will be executed once the first is done, and so forth, using the previous command's output as input. You can achieve the same effect by putting the output in a file and giving the filename as an argument to the second command, but that would be much more complicated, and you'd have to remember to remove all the junkfiles afterwards. Some examples that show the usefulness of this: ls | more --- will show you one screenful at a time, which is useful with any command that will produce a lot of output, e.g. also ps -aux man ls | grep time --- checks whether the man page for ls has something to say about listing files by time - very useful when you have a suspicion some command may be capable of doing what you want, but you aren't sure. ls -lR | grep dvi --- will show you all your dvi files - useful to solve disk space problems, since they're large and usually can be deleted.

::::::::::Basic UNIX commands::::::::::

If you've made a typo, the easiest thing to do is hit CTRL-u to cancel the whole line. But you can also edit the command line (see the guide to More UNIX). UNIX is case-sensitive. Files

* ls --- lists your files ls -l --- lists your files in 'long format', which contains lots of useful information, e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified. ls -a --- lists all files, including the ones whose filenames begin in a dot, which you do not always want to see. There are many more options, for example to list files by size, by date, recursively etc. * more filename --- shows the first part of a file, just as much as will fit on one screen. Just hit the space bar to see more or q to quit. You can use /pattern to search for a pattern. * emacs filename --- is an editor that lets you create and edit a file. See the emacs page. * mv filename1 filename2 --- moves a file (i.e. gives it a different name, or moves it into a different directory (see below) * cp filename1 filename2 --- copies a file * rm filename --- removes a file. It is wise to use the option rm -i, which will ask you for confirmation before actually deleting anything. You can make this your default by making an alias in your .cshrc file. * diff filename1 filename2 --- compares files, and shows where they differ * wc filename --- tells you how many lines, words, and characters there are in a file * chmod options filename --- lets you change the read, write, and execute permissions on your files. The default is that only you can look at them and change them, but you may sometimes want to change these permissions. For example, chmod o+r filename will make the file readable for everyone, and chmod o-r filename will make it unreadable for others again. Note that for someone to be able to actually look at the file the directories it is in need to be at least executable. See help protection for more details. * File Compression o gzip filename --- compresses files, so that they take up much less space. Usually text files compress to about half their original size, but it depends very much on the size of the file and the nature of the contents. There are other tools for this purpose, too (e.g. compress), but gzip usually gives the highest compression rate. Gzip produces files with the ending '.gz' appended to the original filename. o gunzip filename --- uncompresses files compressed by gzip. o gzcat filename --- lets you look at a gzipped file without actually having to gunzip it (same as gunzip -c). You can even print it directly, using gzcat filename | lpr * printing o lpr filename --- print. Use the -P option to specify the printer name if you want to use a printer other than your default printer. For example, if you want to print double-sided, use 'lpr -Pvalkyr-d', or if you're at CSLI, you may want to use 'lpr -Pcord115-d'. See 'help printers' for more information about printers and their locations. o lpq --- check out the printer queue, e.g. to get the number needed for removal, or to see how many other files will be printed before yours will come out o lprm jobnumber --- remove something from the printer queue. You can find the job number by using lpq. Theoretically you also have to specify a printer name, but this isn't necessary as long as you use your default printer in the department. o genscript --- converts plain text files into postscript for printing, and gives you some options for formatting. Consider making an alias like alias ecop 'genscript -2 -r \!* | lpr -h -Pvalkyr' to print two pages on one piece of paper. o dvips filename --- print .dvi files (i.e. files produced by LaTeX). You can use dviselect to print only selected pages. See the LaTeX page for more information about how to save paper when printing drafts.

Directories Directories, like folders on a Macintosh, are used to group files together in a hierarchical structure.

* mkdir dirname --- make a new directory * cd dirname --- change directory. You basically 'go' to another directory, and you will see the files in that directory when you do 'ls'. You always start out in your 'home directory', and you can get back there by typing 'cd' without arguments. 'cd ..' will get you one level up from your current position. You don't have to walk along step by step - you can make big leaps or avoid walking around by specifying pathnames. * pwd --- tells you where you currently are.

Finding things

* ff --- find files anywhere on the system. This can be extremely useful if you've forgotten in which directory you put a file, but do remember the name. In fact, if you use ff -p you don't even need the full name, just the beginning. This can also be useful for finding other things on the system, e.g. documentation. * grep string filename(s) --- looks for the string in the files. This can be useful a lot of purposes, e.g. finding the right file among many, figuring out which is the right version of something, and even doing serious corpus work. grep comes in several varieties (grep, egrep, and fgrep) and has a lot of very flexible options. Check out the man pages if this sounds good to you.

About other people

* w --- tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This allows you to see whether they're actually sitting there typing away at their keyboards right at the moment. * who --- tells you who's logged on, and where they're coming from. Useful if you're looking for someone who's actually physically in the same building as you, or in some other particular location. * finger username --- gives you lots of information about that user, e.g. when they last read their mail and whether they're logged in. Often people put other practical information, such as phone numbers and addresses, in a file called .plan. This information is also displayed by 'finger'. * last -1 username --- tells you when the user last logged on and off and from where. Without any options, last will give you a list of everyone's logins. * talk username --- lets you have a (typed) conversation with another user * write username --- lets you exchange one-line messages with another user * elm --- lets you send e-mail messages to people around the world (and, of course, read them). It's not the only mailer you can use, but the one we recommend. See the elm page, and find out about the departmental mailing lists (which you can also find in /user/linguistics/helpfile).

About your (electronic) self

* whoami --- returns your username. Sounds useless, but isn't. You may need to find out who it is who forgot to log out somewhere, and make sure *you* have logged out. * finger & .plan files of course you can finger yourself, too. That can be useful e.g. as a quick check whether you got new mail. Try to create a useful .plan file soon. Look at other people's .plan files for ideas. The file needs to be readable for everyone in order to be visible through 'finger'. Do 'chmod a+r .plan' if necessary. You should realize that this information is accessible from anywhere in the world, not just to other people on turing. * passwd --- lets you change your password, which you should do regularly (at least once a year). See the LRB guide and/or look at help password. * ps -u yourusername --- lists your processes. Contains lots of information about them, including the process ID, which you need if you have to kill a process. Normally, when you have been kicked out of a dialin session or have otherwise managed to get yourself disconnected abruptly, this list will contain the processes you need to kill. Those may include the shell (tcsh or whatever you're using), and anything you were running, for example emacs or elm. Be careful not to kill your current shell - the one with the number closer to the one of the ps command you're currently running. But if it happens, don't panic. Just try again :) If you're using an X-display you may have to kill some X processes before you can start them again. These will show only when you use ps -efl, because they're root processes. * kill PID --- kills (ends) the processes with the ID you gave. This works only for your own processes, of course. Get the ID by using ps. If the process doesn't 'die' properly, use the option -9. But attempt without that option first, because it doesn't give the process a chance to finish possibly important business before dying. You may need to kill processes for example if your modem connection was interrupted and you didn't get logged out properly, which sometimes happens. * quota -v --- show what your disk quota is (i.e. how much space you have to store files), how much you're actually using, and in case you've exceeded your quota (which you'll be given an automatic warning about by the system) how much time you have left to sort them out (by deleting or gzipping some, or moving them to your own computer). * du filename --- shows the disk usage of the files and directories in filename (without argument the current directory is used). du -s gives only a total. * last yourusername --- lists your last logins. Can be a useful memory aid for when you were where, how long you've been working for, and keeping track of your phonebill if you're making a non-local phonecall for dialling in.

Connecting to the outside world

* nn --- allows you to read news. It will first let you read the news local to turing, and then the remote news. If you want to read only the local or remote news, you can use nnl or nnr, respectively. To learn more about nn type nn, then \tty{:man}, then \tty{=.*}, then \tty{Z}, then hit the space bar to step through the manual. Or look at the man page. Or check out the hypertext nn FAQ - probably the easiest and most fun way to go. * rlogin hostname --- lets you connect to a remote host * telnet hostname --- also lets you connect to a remote host. Use rlogin whenever possible. * ftp hostname --- lets you download files from a remote host which is set up as an ftp-server. This is a common method for exchanging academic papers and drafts. If you need to make a paper of yours available in this way, you can (temporarily) put a copy in /user/ftp/pub/TMP. For more permanent solutions, ask Emma. The most important commands within ftp are get for getting files from the remote machine, and put for putting them there (mget and mput let you specify more than one file at once). Sounds straightforward, but be sure not to confuse the two, especially when your physical location doesn't correspond to the direction of the ftp connection you're making. ftp just overwrites files with the same filename. If you're transferring anything other than ASCII text, use binary mode. * lynx --- lets you browse the web from an ordinary terminal. Of course you can see only the text, not the pictures. You can type any URL as an argument to the G command.at any time to learn more about lynx, and Q to exit.

Miscellaneous tools

* webster word --- looks up the word in an electronic version of Webster's dictionary and returns the definition(s) * date --- shows the current date and time. * cal --- shows a calendar of the current month. Use e.g., 'cal 10 1995' to get that for October 95, or 'cal 1995' to get the whole year.

You can find out more about these commands by looking up their manpages: man commandname --- shows you the manual page for the command...

::::::::::Examples of Bourne shell scripts::::::::::

To read input to a command and process it in some way:

#!/bin/sh # usage: fsplit file1 file2 total=0; lost=0 while read next do total=`expr $total + 1` case "$next" in *[A-Za-z]*) echo "$next" >> $1 ;; *[0-9]*) echo "$next" >> $2 ;; *) lost=`expr $lost + 1` esac done echo "$total lines read, $lost thrown away"

The user types the command:

fsplit file1 file2

They then enter lines of text and issue an EOF instruction. The script then processes the lines as follows:

A line with at least one letter is appended to file1; any line with at least one digit and no letters is appended to file2. All other lines are thrown away.

To read commands from the terminal and process them:

#!/bin/sh # usage: process sub-directory dir=`pwd` for i in * do if test -d $dir/$i then cd $dir/$i while echo "$i:" read x do eval $x done cd .. fi done

The user types the command:

process sub-directory

To create a command:

#!/bin/sh flag= for i do case $i in -c) flag=N ;; *) if test -f $i then ln $i junk$$ rm junk$$ elif test $flag # true if not null then echo \'$i\' does not exist else >$i fi ;; esac done

This command takes filenames as its parameters. If a file exists it changes the modification date. If no file exists it creates a new one. This script is similar in action to the touch command.

The -c argument lets you specify that you only want to update a file that already exists and not to create one if it doesn't.

Shell scripts can act like standard UNIX commands and take arguments from the command line.

Arguments are passed from the command line into a shell program using the positional parameters $1 through to $9. Each parameter corresponds to the position of the argument on the command line.

The positional parameter $0 refers to the command name or name of the executable file containing the shell script.

Only nine command line arguments can be accessed, but you can access more than nine using the shift command.

All the positional parameters can be referred to using the special parameter $*. This is useful when passing filenames as arguments. For example:

cat printps # This script converts ASCII files to PostScript # and sends them to the PostScript printer ps1 # It uses a local utility "a2ps" a2ps $* | lpr -Pps1 printps elm.txt vi.ref msg

This processes the three files given as arguments to the command printps.

Examples of passing arguments to the shell

To pass several arguments from the command line to the shell:

cat first_5args # This script echoes the first five arguments # supplied to the script echo The first five command line echo arguments are $1 $2 $3 $4 $5 first_5args mines a pint john o.k. The first five command line arguments are mines a pint john o.k.

This passes the arguments represented by parameters $1 through $5 to the shell script.

To pass the value of each positional parameter to the shell script:

cat printps # This script converts ASCII files to PostScript # and sends them to the PostScript printer ps1 # It uses a local utility "a2ps" a2ps $* | lpr -Pps1 printps elm.txt vi.ref msg

This processes the three files given as arguments to the command printps.

Using the shift command

Usually only nine command line arguments can be accessed using positional parameters. The shift command gives access to command line arguments greater than nine by shifting each of the arguments.

The second argument ($2) becomes the first ($1), the third ($3) becomes the second ($2) and so on. This gives you access to the tenth command line argument by making it the ninth. The first argument is no longer available.

Successive shift commands make additional arguments available. Note that there is no "unshift" command to bring back arguments that are no longer available!

Example of using the shift command

To successively shift the argument that is represented by each positional parameter:

cat shift_demo #!/bin/sh echo "arg1=$1 arg2=$2 arg3=$3" shift echo "arg1=$1 arg2=$2 arg3=$3" shift echo "arg1=$1 arg2=$2 arg3=$3" shift echo "arg1=$1 arg2=$2 arg3=$3" shift_demo one two three four five six seven arg1=one arg2=two arg3=three arg1=two arg2=three arg3=four arg1=three arg2=four arg3=five arg1=four arg2=five arg3=six arg1=five arg2=six arg3=seven

Special shell variables

There are some variables which are set internally by the shell and which are available to the user:

Name Description

$1 - $9 these variables are the positional parameters.

$0 the name of the command currently being executed.

$# the number of positional arguments given to this invocation of the shell.

$? the exit status of the last command executed is given as a decimal string. When a command completes successfully, it returns the exit status of 0 (zero), otherwise it returns a non-zero exit status.

$$ the process number of this shell - useful for including in filenames, to make them unique.

$! the process id of the last command run in the background.

$- the current options supplied to this invocation of the shell.

$* a string containing all the arguments to the shell, starting at $1.

$@@ same as above, except when quoted.

Notes

$* and $@@ when unquoted are identical and expand into the arguments.

"$*" is a single word, comprising all the arguments to the shell, joined together with spaces. For example '1 2' 3 becomes "1 2 3".

"$@@" is identical to the arguments received by the shell, the resulting list of words completely match what was given to the shell. For example '1 2' 3 becomes "1 2" "3"

Evaluating shell variables

The following set of rules govern the evaluation of all shell variables.

Definition Description

$var signifies the value of var or nothing, if var is undefined.

${var} same as above except the braces enclose the name of the variable to be substituted.

${var-thing} value of var if var is defined; otherwise thing. $var is not set to thing.

${var=thing} value of var if var is defined; otherwise thing. If undefined $var is set to thing.

${var?message} If defined, $var; otherwise print message and exit the shell. If the message is empty, print a standard message.

${var+thing} thing if $var is defined, otherwise nothing.

Execute a command without creating a new process

The exec statement causes the command specified as its argument to be executed in place of the current shell without creating a new process. For example:

exec zmail -visual

This runs just the zmail program without a shell. When you quit the application the current shell also exits.

Controlling when to exit a shell script

The exit statement will exit the current shell script. It can be given a numeric argument which is the script's exit status. If omitted the exit status of the last run command is used. 0 (zero) signifies success, non-zero signifies failure. For example:

#!/bin/sh if [ $# -ne 2 ] # "$#" is number of parameters- here we test # whether it is not equal to two then echo "Usage $0 \<file1\> \<file2\>" # not two parameters # so print message exit 2 # and fail ($0 is # name of command). fi ...<rest of script>

This script is supposed to take two positional arguments. It will exit with status 2 (error) rather than 0 (success) if it is not called with two parameters.

Trapping operating system signals

Shell procedures may use the trap command to catch or ignore Unix operating system signals. The form of the trap command is:

trap 'command-list' signal-list

Several traps may be in effect at the same time. If multiple signals are received simultaneously, they are serviced in ascending order.

To check what traps are currently set use the trap command. For example:

trap

Signals to be caught

The following are the signals that are usually caught with the trap command.

0 shell exit (for any reason, including end of file EOF). 1 hangup. 2 interrupt (^C). 3 quit (^\\ ; causes program to produce a core dump). 9 kill (cannot be caught or ignored). 15 terminate; default signal generated by kill.

trap: Handling command lists

The command list is placed between single quotes, as the command line is scanned twice, once when the shell first encounters the trap command and again when it is being executed.

trap 'command-list' signal-list

The single quotes inhibit immediate command and variable substitution but are stripped off after the first scan, so that the commands are processed when the command is actually executed.

If command-list is not specified, then the action taken on receipt of any signal in the signal-list is reset to the default system action.

If command-list is an explicitly quoted null command (' ' or " "), then the signals in signal-list are ignored by the shell.

The command-list is treated like a subroutine call. The commands in the list are executed when the signal is trapped and control is then returned to the place at which it was interrupted.

Examples of interrupt handling

To use single quotes to inhibit command substitution:

#!/bin/sh trap 'echo `pwd` >>$HOME/errdir' 2 3 15 for i in /bin /usr/bin /usr/any/bin do cd $i some series of commands in the directory $i done

The file errdir will contain the name of the directory being worked on when the procedure is interrupted. What happens if the same procedure has double quotes around it?

trap "echo `pwd` >errdir" 2 3 15

The file errdir will just contain the name of the directory from which the procedure was invoked because the pwd command would be substituted on the first scan by the shell and not when it is invoked in the script.

To remove temporary files when a procedure is interrupted:

#!/bin/sh temp=/tmp/file.$$ trap 'rm $temp; exit' 0 1 2 3 15 ls > $temp .....

If any of the named signals are encountered, the command rm $temp; exit will be executed. The exit command is needed to terminate the execution of the whole procedure.

To continue processing commands after a trap command:

#!/bin/sh # read and process commands dir=`pwd` for i in * do if test -d $dir/$i then cd $dir/$i while echo ''$i:'' trap exit 2 # trap ^C read x do trap ' ' 2 # ignore interrupts eval $x done fi done

The shell continues to process commands after a trap command. The entire procedure is terminated if interrupted when waiting for input, but the interrupt is ignored while executing a command. The command list is an explicitly quoted null command and so the signal is ignored by the shell.

Back to Sitemap Index