UNIX and Linux

Unix resources and basic instructions


elflord@pegasus.rutgers.edu

Tutorials

Useful information mostly written by me, the conspicuous exception being the bash manpage ...

Intro to Unix
UNIX command summary
grep tutorial powerful search tool
sed tutorial scripts to edit text files
Autofs in Linux automatically mounting removable media
procmail tutorial well known email filter
bash manpage the man page for the bash shell. Warning: this is long (~210k)

Contents:



Online Unix Guides

Back to top

Unix help for users

is a very good unix guide, more readable than manual pages full of clear examples. Recommended for idiots like me who can't make a head or tail of the manual page's jargon. Includes info on changing permissions on files. For the benefit of Australian users, they have a

mirror site

in Australia to help you get a speedy connection.

Another site, which is good if you're ready for something a little more advanced is

the 85321 guide.

which is written for up and coming system administrators but starts with the basics. A good one to check out!!! (especially if you want Bob Gerdes' job!)


PC UNIX

Back to top

If you're interested in installing Unix on your PC, check out the

Linux homepage, or the

freeBSD page.

Both of these are inexpensive PC versions of the Unix operating system, in fact they're sometimes used on University Network systems as well.


Basic Unix commands

Fundamental stuff

Back to top

mail

read mail using the primitive and clumsy basic mail program.

elm

read mail using a slightly more sophisticated program

pine

read mail using pine. Pine is the email program I recommend for beginners, it's user friendly and reasonably powerful. For more advanced users, I recommend mh. (try "man mh" for details... actually, if you couldnt figure that out for yourself, just use pine...)

who

tells you who else is on the system

pico file_name

or
pico

Starts up the pico editor, if file_name i specified, it opens up file_name with the pico editor. pico is the editor that is ued by the pine program. It is not a very powerful text editor, but very user friendly, probably the best to use if you're a beginner with no unix knowledge (unless you have XWindows on your system, if so, see emacs.....)

&

When you finish a command with &, the shell does not wait for the process to finish before giving you your command prompt back. This command is useful when you're in X-Windows. For example, if you type netscape& then netscape starts, but you can still type more commands in the window. This is useful when you're running programs like Netscape, Ghostview and Xdvi.

emacs

Emacs is another text editor. It is more powerful than pico. If you have X-windows, emacs comes with a nice user interface. So if you have xWindows on your ystem, emacs is probably better to use than pico.

man command_name

prints out the "online documentation " for command_name. a better way of using this (though it might not work on all machines) is man command_name|less. The reason for this is that most machines have the annoying habit of using the more command to display a man page. The more command only allows you to scroll forward, while less allows you to scroll forward or back.

talk user_name@domain.name.edu
(or org or com... or whatever...)

talk to the specified user. If you don't know how this command works, try it and see what happens. It only works if the person you're trying to talk to is logged on.

finger user@domain.name

Great for all you nosey people. Tells you how long since user read their mail, when they last logged in... sometimes, you need to use finger -l to get it to give you enough info. Note that this doesn't allways work, some servers don't like being "fingered" (: One useful application of this command is to check if some-one's "home" before you try to "talk" with them.

whoami

tells you who you are ( in case you forget (: )


Unix commands: file management

Back to top
pwd

Tells you which directory you are in

cd

moves you to a directory, ie cd public_html moves you to the public_html directory. You can use a number of conventions for describing path names. For example, cd / puts you in the top directory, and cd ~ puts you in your home directory.

ls

Lists contents of your directory.You can attach some options to ls, for example, ls -a lists all files (ls does NOT list files beginning with a . like .netscape, etc). ls -l gives you "long" output, ie lists file details, including permissions. ls -al
lists all files in long format, in general you can combine options in this manner. ls -s lists the file size (in kilobytes) and ls -R lists all sub- directories and files contained within sub-directories.

mkdir

makes a directory with a given name, ie mkdir blah makes a directory (a subdirectory of the current directory) called blah.

rmdir

removes an empty directory. Not really a very useful command. To remove a nonempty directory, you use rm -r directory_name (this deletes all files inside the directory and it's subdirectories).

cp

copies the contents of a file to another file, eg cp file_1 file_2 copies the file named file_1 to a new file named file_2 If you want to copy a directory to another directory, you use cp -R dir_1 dir_2

mv

mv file_1 file_2 moves file_1 to file_2, ie renames it. you can also use mv dir_1 dir_2 to rename dir_1

rm

removes a file, ie rm blah removes the file called blah. This can also be used to delete a directory and its contents. rm -r deletes a directory and all of the files in it and its subdirectories. One thing a little annoying about this command is that it prompts you for each file- at least it's annoying if you're deleting a directory containing 100 or more files, like a Netscape cache. So you can also use rm -Rf which does not prompt you to confirm every single delete. Well it usually will not. If this doesn't work (it depends on which type of UNIX you're using), try yes|rm -r. The yes command just answers all the questions for you. If you do this yes thing, you get a "broken pipe" message. Don't worry- it just happens because the yes command keeps talking after the rm -r has stopped listening.

du

disk usage- tells you how much space in kilobytes is in both the directory and all of its subdirectories. Some options are du -s which just tells you the total space used by the current directory and du -a which includes files in the summary.



Permissions

Back to top

Permissons as you've probably guessed are those things that determine who is allowed to do what to your files. Whether you are aware or not, the default setting is (usually) that your files are readable by anyone (except your email files- the email programs are smart enough to 'know' that you probably don't want your email to be 'world readable'). So here's the answer to a frequently asked question:
How do I change the default permission settings The answer: put the following line in your profile file:
umask 077
Also, typically, all files default to being strictly non-executable. This makes it difficult for viruses to corrupt your system. Each file has a permissions field which is 10 letters long. The permissions field looks something like this: drwxrwxrwx or -rw-rw----, you get the idea. The first space contains either d if it's a directory, or a dash if it's a file. What do those letters mean? Letters two, three and four represent the permissions that the user (ie you) have. r means the file is read permitted, w is write permitted, and x is executable. Letters five six and seven represent the permissions that the group ( type ls -l file_name the name in the second column is the group name.) If the group name is your user name, then the permissions for your user name over-ride the group setting. Letters eight to ten represent the permissions that some one accessing from any location has.

I would recommend that you use the following permissions:
For files that you want to keep private, use 600 as your permission field.
For executables, use 700 (or 744 if you don't mind others reading it.
For files that you are willing to share with the world, use 644
To protect the contents of an entire directory, use 744, 711 or 700
I'll say more about what these numbers mean...


examples

-rw-------

This file may be read or written to by the user only (ie an email file)

-rw-r--r--

This file may be read by ANYONE but only written to by you. This tends to be a default setting on some systems. So be careful. As a note, this is the recommended setting for a webpage file in a unix account (if you don't set all of the read permissions, some people will not be able to access your page).

-r-xr-xr-x

This is say, some precious application, and you don't care who uses it, but you want to make sure no-one (including you...) deletes it! Note that security-wise, it's probably best not to allow anyone else to execute your files. In other words, I do not endorse that permission setting, it's just an example.

drwx--x--x

This is a directory with execute permissions, ie it's "searchable" but not readable. What does that mean? A searchable directory is a directory that permits you to view the contents , but not 'read' it, ie you can't run ls on it. So anyone can view files in the directory, PROVIDED THEY KNOW THE NAME OF THE FILE THEY WANT TO SEE. They have no way of listing the file. This is a convenient way of protecting access to a file that you're working on with a friend, you can allow read permissions on the file but put it in a read protected directory, so that no-one else can find the file. Another advantage of this is that if you maintain a web page, this setting will not interfere with access to your page, because the browser is free to look for a file called public_html/index.html, and (and you have the permissions on the file set correctly) the browser may read the file.

drwxr--r--

This directory i read permitted, but not searchable. That is, while anyone can run ls on it and get a list of the files it contains, no-one (except the user) can read, execute, or otherwise access the files inside.



Changing Permissions

Back to top

Permissions are changed with the chmod command. The basic formats are chmod _+_, chmod _-_ where the first blank space contains u, g, o, or a, and the second blank space contains any subset of the letters w,r and x. The first letter refers to either the user (u), the group (g), other, or everyone else (o) or every one (a). Note that a includes g,u and o. The second letter refers to the permission being modified. Lets have some more examples:

 
Command          	permissions before 	permissions after 
chmod g+x file1    	-rwxr--r--         	-rwxr-xr--         
chmod g-x file1  	-rwxr-xr--         	-rwxr--r--
chmod a+rx file1 	-rw-r--r-- 		-rwxr-xr-x

An alternative is to use octal numbers. The format then becomes chmod abc filename or chmod abc dir_name where a,b and c are numbers between 0 and 7. The numbers stand for user, group and other respectively. They are attained as follows: r-- correponds with 4, -w- corresponds with 2 and --x corresponds with 1. r-x corresponds with 4+1=5, rw- corresponds with 4+2=6, etc. So some examples are
Command 			before 		after 
chmod 777 filename (RU nuts?) 	Anything 	-rwxrwxrwx
chmod 755 dirname 		Anything 	drwxr-xr-x

Configuration Files

Configuration files are files that are executed every time you login (the .login file), use a shell (.shellname_profile, .profile or .shell_namerc) or every time you log out (.logout), or even every time you run a program (there are configuration files for Xwindows, procmail, pine, mh , elm, etc) As a general rule, files that begin with a dot are likely to be configuration files. Files that begin with a dot and end with 'rc' or 'profile' are almost certainly configuration files.
Try running the command ls -a in your home directory. You should discover that you have some file in your home directory with one of the following names:
.profile
.shell_name_profile 	where shell_name is usually either bash, 
			sh, csh, tcsh or zsh (I think that's about it...)
.shell_name_rc   	where shellname  as described above 
.login
If you don't have any such files, you can always make your own. Best to call it .login, this should work regardless of which shell your system uses. You can do some nice things with these files to customize your operating environment, for example, you can use the alias command which works as follows:

alias command_1 = 'command_2'
where command_1 is a shortcut or alias for command_2.

Examples:

alias ll='ls -l'

this tells the system to execute ls -l when you type ll at the command line.

alias dir='ls'

For dos-users who miss dos so badly that they have to re-write unix to work like dos.

alias man='man $*|less'

This is a useful alias which modifies the man command so that you can scroll backwards as well as forwards when viewing man pages. The $* is replaced by the command line argument, o for example, if you type man procmail the shell executes man procmail|less

alias logout="echo 'goodbye';sleep 1;logout"

This makes the system say goodbye to you when you log out. The semi-colons are a way of putting multiple commands on one line. The sleep 1command tells the system to pause for 1 second.

Of course, your aliases need to be defined every time you log in. That is, unless you automate the process by placing them in one of your shell profile, shell rc or .login files. Typically, most users don't do a great deal with their configuration files except for adding a lot of aliases.