UNIX Questions

How do I get started with UNIX?

The basic commands you'll need are:

Command

Function

ls

list files

cd

change directory

mkdir

make directory

rmdir

remove directory

cp

copy

mv

move

nano

edit files (probably the easiest text-based editor on our systems)

man

user manuals

These are the most important commands. If you need more details on how to use them, you can type man cmd where "cmd" is the name of the command you want more information about.

How do I use CVS?

Repository

CVS may use either a local repository or a remote repository. In general, CVS provides access to several kinds of remote repository, but the CIS systems only support the remote shell remote repository. Whenever running CVS you must tell the program where to find the repository. You can do this either by specifying the -d option to the cvs command or by setting the CVSROOT environment.

If the repository is stored in a CIS home directory, you may use a local repository, which is specified with just the directory name::

   1 /research/lbs/cvsroot

If the directory will be used on a laptop or other "remote" machine, then you must specify a remote shell repository::

   1 :ext:tamtoft@cislinux.cis.ksu.edu:/research/lbs/cvsroot

I prefer the latter in all cases because I can then copy the entire repository or zip it up and place it on another machine and use it as is. You may do whichever you prefer. If you do this, you will also need to make sure the CVS_RSH environment variable is set to ssh::

   1 export CVS_RSH="ssh"

As I stated above, these must be given to the CVSROOT environment or to the -d option::

   1 export CVSROOT=":ext:tamtoft@cislinux.cis.ksu.edu:/research/lbs/cvsroot"
   2 cvs ...
   3 
   4 # OR
   5 
   6 cvs -d/research/lbs/cvsroot ...

Commands

After the cvs command (and other basic options, such as -d), you specify the name of a command. The most common commands are import, checkout, update, add, remove, commit, and export.

Import

Import creates a new project in the CVS repository. You must first create a simple project directory containing at least one file (or it could be a complete, existing project). Change into that directory and run:

   1 cvs -d... import -kkv projectname tamtoft start

This will use the contents of the current directory (and all it's subdirectories) to create a new package in the CVS repository. It will name that project projectname assign the branch vendor tag as tamtoft (probably don't need to worry about what that means), and sets the version as start. The -kkv also says that all files imported should be treated as text for keyword replacements. If this is not the case, you should use -kb instead. I recommend running:

   1 cvs -d... import -h

for more details or see the man-page for CVS or go to http://www.cvshome.org/ for on-line documentation.

Checkout

After import, you need to check out a version controlled directory (the import directory is unmodified). You can do this by changing out of the current directory into your work directory and then running:

   1 cvs -d... checkout projectname

This will create a directory named projectname in the current directory. This will be your local work directory for the project. At the start of each work cycle, you will want to use the update command to synchronize your work to the current repository (in case others have made changes). When you are done making changes, you will use the commit command to push your changes into the main repository.

Update

At the start of each work cycle you may use this command to synchronize your local copy to all the work committed to the central repository by changing into your local work directory and running:

   1 cvs update

Notice that you don't need to specify the CVSROOT with this command as it is specified by your local repository inside of the CVS metadata directory.

This command is also useful when used to check the status of the repository by turning changes off:

   1 cvs -n update

This will show you the current status of your local work directory giving you information about which files you have changed, which files in the central repository are different from local copies, and where conflicts exist.

Add

This command is used to add files and directories to the repository by calling:

   1 cvs add files...

You can add multiple files and directories at a time. You cannot add files until you have added the directory they are in. After adding, you will need to commit your changes using the commit command.

Remove

This command is used to remove files or all files in a directory from the repository by running::

   1 cvs remove -f files...

The -f tells CVS to remove the file at the same time as marking it for removal from the repository. You will need to commit your changes using the commit command when done.

Commit

This command is used to upload all of your local changes to the master repository. In the case of conflicts, it will give you instructions on how to merge changes and then upload a new copy. Most of the time it will just try to do the right the thing:

   1 cvs commit

Export

When you want to package up the project without the CVS metadata directories, you run an export. From a top-level directory run:

   1 cvs export projectname

You will now have a clean copy of the repository, but this copy should not be used for editing.

Other Information

For more detailed information, I recommend using the -h option to cvs to get help or see the documentation available at CVS Help

How do I remap keys in X?

There are two ways to remap keys within X. The simplest method is to use the built in functionalities of your window manager if they exist. Gnome will allow a user to take care of tasks such as swapping control/caps through its Keyboard Preferences window. KDE has a Keyboard Layout section in its control center.

The other method is to use xmodmap. For this method you will need to create a ~/.xmodmap file to remap keys. Following is an example of one that would swap backspace/delete and control/caps. A ! character comments out the line.

   1 ! Swap delete and backspace
   2 keysym BackSpace = Delete
   3 keysym Delete = BackSpace
   4   
   5 ! Swap capslock and left control
   6 remove Lock = Caps_Lock
   7 remove Control = Control_L
   8 keysym Control_L = Caps_Lock
   9 keysym Caps_Lock = Control_L
  10 add Lock = Caps_Lock
  11 add Control = Control_L

You can this load this by running xmodmap ~/.xmodmap when you start your X session. There is not a good way to automate this every time Gnome starts since gnome-smproxy overwrites all keyboard settings. If anybody knows of a way, please let us know, and we can update this document to reflect that.

How do I install applications under UNIX

Assuming that the application uses the standard autoconf and automake style of deployment, you should be able to install most applications into your home directory (or into another directory you have write access to, such as a /projects directory). To do so, you basically need to run the following inside the source package directory of the application:

   1 ./configure --prefix=/path/to/your/home/directory/local
   2 make
   3 make install

Make sure to set the path to something besides the root of your home directory (*not* like /home/grads/sterling) or you will have gobs of extra files in your home directory. Instead use a directory like local (e.g. /home/grads/sterling/local). If you have a /projects directory or other directory we've given you write permission to on the CIS filesystems, you may place your files there too.

What are "UNIX file permissions"?

All student and faculty files in the CIS department are stored on a Unix file server. However, not everyone needs or should have access to every file. Unix file permissions are how the file server decides who can access which files and what kind of access is permitted.

Ownership

Every file in Unix is assigned an user owner and a group owner. These form the basis of file security.

Each group may contain zero or more users. In the CIS department, every user has a special group which contains only their user (e.g., if your username were foobar, your group would be foobar_users).

You may not change the user ownership of your files. If you find that some of your files are owned by the wrong user, you will need to contact the systems staff to get that problem correct.

You may, however, change the group ownership of your files (or directories). You are only able to change a file's group ownership to another group to which you belong. You may change group ownership with the chgrp program:

   1 chgrp foobar_users file.txt
   2 chgrp foobar_users dir

File Mode

The second component of Unix file ownership is called "file mode." The file mode determines what access the user owner, group owner, or other user has to a file.

There are three kinds of access: read, write, and execute. The access granted by each of these depends upon whether they are applied to a directory or to a file. For files, read access gives the user permission to see the contents of the file, write access gives the user permission to change the contents of the file, and execute access gives the user permission to run the file as a program. For directories, read access gives the user permission to see what files are stored in that directory, write access gives the user permission to create files in that directory, and execute access allows the user to enter that directory (note that directory execute is required for read or write to mean anything).

Viewing File Permissions

To view the permissions on a file or directory you can use the -l option to the file list command, ls::

   1 foobar@camaro projects$ ls -l
   2 total 4
   3 drwx------   3 foobar foobar_users 4096 Mar 16 19:51 bin/
   4 drwxrwxr-x   4 foobar foobar_users 4096 Mar 16 19:51 lib/
   5 -rw-r--r--   1 foobar foobar_users  667 Mar 16 19:51 foo.txt
   6 -rwxrwxr-x   1 foobar foobar_users  408 Mar 16 19:51 a.out

Here we see two directories and two files. The permissions are shown in the first column of the listing. The user owner is the third column and the group owner is the fourth column. The permissions are shown via the 10-character string. The first character (either d or - here) tells us what kind of thing is shown: d for directory and - for regular file (there are other kinds of "things" in a Unix file system, but those are beyond the scope of this discussion). The rest of the columns show the file mode.

The file mode is divided into three sections. The first applies to the user onwer, the second to the group owner, and the third to all other users. These fields are then divided into three letters, one for each permission granted: r for read, w for write, and x for execute.

The first row above shows a directory that is only accessible by user foobar. This user is allowed to change to the bin directory, see what files are in that directory, and allowed to put new files into that directory. The second row shows a publically accessible directory that is both user and group writable. Here anyone can change to and see the contents of the lib directory. However, only foobar and members of foobar_users are allowed to create files in that directory.

The third and forth rows show files. The first file is readable by everyone, but only writeable by foobar. The second file is readable and executable by everyone, but is only writable by foobar or members of foobar_users.

Changing File Mode

If you need to change the mode of a file or directory, you may do so with the chmod command. The chmod command takes two or more options. The first option is the permission changes you wish to make and the rest of the arguments are the files to change. (The actual command is a lot more flexible, but you may find out more about that by typing man chmod.)

The permission changes are specified in three parts: (1) whose permissions are being changed, (2) stating that permissions are being added or removed, and (3) what access is being granted or revoked.

The first, or "who", part of the options are specified with one or more letters: u for user, g for group, o for other, and a for all.

The second part is specified with either the plus (+) sign to grant permission or the minus (-) sign to revoke permission.

The third part is specified with the same letters as were used by ls when viewing permissions: r for read, w for write, and x for execute.

For example:

   1 chmod a+rx script.pl
   2 chmod og-w file.txt
   3 chmod ug+rw source.c

The first line above would grant read and execute permission to all users on the file named script.pl. The second line would revoke write permissions on file.txt for other users and the group owner. The third would grant read and write permissions to the user owner and group owner on source.c.

Notice that this doesn't say anything about the existing permissions. For example, in the second line above, the user may not be allowed to write to the file either if the user was never granted that permission.

Absolute File mode

Advanced users may want to specify the mode quickly and exactly. This can be done by specifying the numeric file mode directly. The file mode may be specified as an octal number where the last three digits represent each of the three levels of access, user, group, and other, respectively. Each digit then specifies all three read, write, and execute for each of the three fields. Read is specified by the digit 4, write by 2, and execute by 1. Adding these together will get the overall permission.

For example:

   1 chmod 755 script.pl
   2 chmod 644 file.txt
   3 chmod 660 source.c

After running these commands, we would see something like the following listing (note the first column especially):

   1 foobar@camaro src$ ls -l
   2 total 3
   3 -rwxr-xr-x   1 foobar foobar_users   432 Mar 10 12:40 script.pl
   4 -rw-r--r--   1 foobar foobar_users  2590 Mar  8 17:22 file.txt
   5 -rw-rw----   1 foobar foobar_users   596 Mar 12  7:04 source.c

Again see the man-page for chmod for details.

How do I change my default JDK?

Gentoo provides the java-config utility to setup the default JDK. To list the available JDK's run java-config -L. Then to select one, run java-config -s jdk-name-version. For example, java-config -s sun-jdk-1.5. Be aware that when the JDK gets updated you will need to rerun java-config to point to the new location since your are now overwriting the system's setup which gets updated with each new JDK.

What about the /tmp directory?

Whenever working on a Linux system in the department, please be aware of the /tmp directory since it allows you to store files for a short time without affecting your quota. If you need to download a large file or work with some large files that you don't need to work with for long and can't fit into your home directory, you can place these files in /tmp, which is stored on the local disk of the current machine.

However, there are some things you should be aware of when using the the /tmp folder. First, filling up all space in the /tmp folder is a bad idea. You can cause certain programs on the system to freeze up if there is no room left on the drive, which may make working on that computer difficult. Second, the temporary folder is temporary and the systems staff clean up these folders regularly. Any file in the /tmp directory will be deleted after 24 hours. Finally, anything stored in /tmp will not be backed up during our nightly backup process, so when the files are deleted from the /tmp folder, they are gone for good.

How can I change the default app used to open files?

Note: This is for GNOME & Xfce

Changing Default PDF Application

You can run the "pdfdefault.sh" script to prevent GIMP or another application from being the default for opening pdf files. This script sets evince as the default application.

$ /common/public/bin/pdfdefault.sh

Changing Other Default Applications

If you want to make changes to any other defaults you can edit the defaults.list file

$ vim ~/.local/share/applications/defaults.list

You can also right click a file on the desktop and select properties and then select a different application from the "Open With" drop-down box.