Carleton University
Library Carleton A-Z CU Phonebook Campus Map
Prospective Students New & Current Students Alumni Faculty/Staff
School of Computer Science
News & Events
Calendar of Events
SCS News
SCS Seminars
Prospective Students
Undergraduate Programs
Graduate Programs
Contact Us
Current Students
Undergraduate
Graduate
Research
SCS Research
Technical Reports
People
Faculty & Staff
Directory Listing

The new Computer Science Video

Home > Net/Account Help > Linux Help Contact Us
Linux Help

The following will help you get started with Linux on the SCS Network. It will only describe the very basics. For an in-depth look at Linux, the internal workings, and how the operating system works see the O'Reilly set of books in particular 'Essential System Administration' by Aeleen Frisch.

Opening an XTerm

Linux like windows has a window manager, your front end, the windows that you work with (SCS uses Gnome as the default window manager). Although GUI's are useful, and many tasks can now be done using GUI's, most of the work in Linux is done on the command line (essentially all work can be done on the command line). The xterm window is used to type command line arguments. For the Gnome window manager you can right click on the desktop to pop up the system menu, then select xterm (it can also be found under 'Programs - Terminal - XTerm').

Basic Linux Commands

Once in the xterm the following commands are essential for navigating on the Linux command line:

Linux Command DOS command Description
ls dir list contents of directory
cd cd Change Directory - Some 'special' examples are: 'cd ..' moves up one directory 'cd ~' changes the directory to your linux homedirectory. Usage: cd directory
rm del Deletes file:
Usage: rm file1 file2
cat type Displays contents of a file
Usage: cat file1
clear cls Clears the screen
Usage: clear
mkdir mkdir Creates a directory
Usage: mkdir DirectoryName
rmdir rmdir Removes a directory
Usage: rmdir DirectoryName
cp copy Copies a file
Usage: cp Source Dest
mv ren, move Moves a file
Usage: mv Source Dest
find N/AFinds a file in a specified direct ory
Usage: find SourceDir -name "file"
Example: find ~ -name "*.c" would find all files of .c extension in your home directory or below.
tail NADisplay last n lines of a file
Usage: tail LINES FILE
Example: tail 20 aFile.c to display last 20 lines of aFile.c
For more information on Linux commands, see the man pages (type: 'man man' for help with man 'man ls' for manual pages for ls), and the on-line unix help

Linux Command Line Examples

Here are some useful examples that can get you started with using linux:

Linux Command Description
more readme.txt Scroll through readme.txt, page by page.
less readme.txt Scroll through readme.txt and you can scroll line by lane and backwards.
date > date.txt Get the current system date/time and pipe the output into a file called date.txt
find . -name emacs -print Search for the file 'emacs' in the current directory ('.'). You can replace '.' with your starting search path.
grep gcc readme.txt Search for a reference of string 'gcc' in the file readme.txt
uname -a Displays the current version of the operating system that is running on your machine.
tar -cvf file.tar mydir/ Recursively archive everything in the directory called mydir/. This means the entire directory structure is preserved and stored in a single file (file.tar). It is much like a zip file except that it does not compress the archive. It is often used in conjunction withthe gzip command.
gzip file.tar file.tar.gz This will compress the file called file.tar and store the result in a file called file.tar.gz
gunzip file.tar.gz Unzip the file called file.tar.gz
tar -xvf file.tar This will de-archive or untar the archive file.tar. It will re-create the directory structure of the original archive.
whoami Returns your login name otherwise known as your user ID (uid)
finger 'uid' finger 'uid', ie, 'finger root', shows you network information about root.
ssh epsilon15 Log into machine epsilon15 using the secure shell protocol (encrypted telnet).
emacs & Spawn a program called 'emacs' a standard linux text editor. Since you used the '&' (spawned the process) you can keep working in your xterm (try the same command without '&').

System Files,Paths, and Commands

System files can be tricky to work with and therefore we suggest that you modify them only if your familiar with linux. System files typically start with a '.'. You can view them using 'ls -la | more' command. The editors of choice for editing linux system files are 'emacs' and 'vi' (again both are tricky to use for the novice user - if your really lost try using 'pico -w' make sure to use the -w option!).

System Files, Paths, and Commands Description
/usr/local/bin System directory for most executable programs (Try 'ls -l /usr/local/bin/ | more').
.cshrc and .login .cshrc and .login are files that are launched when you first log into linux (similar to the autoexec.bat for windows 95/98). If you like to have the SCS default you can delete these files, otherwise they can be modified (ie add to the path)
set Displays your linux environment variables.
setenv DISPLAY epsilon15:0.0 Set the output of your display to be epsilon15. Used when you are remotely logged into another linux machine and you wish to have the display sent to your local machine (in this particular case epsilon15).
df -k Show local drive/disk information
du -s -k ~ Calculate your linux disk usage in kilobytes in your homedirectory. The ~ is a shortcut referring to your network homedirectory.
ps -aux | grep 'uid' Displays all the processees 'uid' is running on your linux workstation (linux only, use 'ps -ef' for SUN solaris). Note the use of the pipe '|' command.
kill -9 'pid' Stop/Kill the process with id 'pid' displayed in the 2nd column of the 'ps -aux' output. You can only kill processees that have your uid.

Disk Usage, archiving, and compressing files and dirs

The following will explain how to check for you disk usage, how to compress, and how to archive files and directories.

Checking your disk usage in your homedirectory:

du -s -k ~

To check your local filesystem for its disk usage:

df -k

To compress a file:

gzip filename

This will create a file called filename.gz. To de-compress the file:

gunzip filename.gz

If you like to backup and entire directory, its subdirectories, and you would like to preserve permissions you can use the tar command:

tar -cvf file.tar <directory>

This will create a sinlge file file.tar that contains an archive of your directory. To expand the archive:

tar -xvf file.tar

Since the tar files may be large in size you can then run the gzip command to compress the archive, this will generate the popular file.tar.gz compressed archive.

Adding to your PATH

When you run a program in your current directory the computer knows to search for it there and launch it. In Linux executables are found in several directories and it is possible to launch them even though your not in the current directory. The PATH variable is used to specify the search PATH for the computer. If you run 'echo $PATH' you can display your current PATH. To add to your path you can add the following entries to your .cshrc file (or create the .cshrc file if it does not exist):


if ($?PATH) then
setenv PATH "${PATH}:/home/70userX/my_uid/my_dir"
else
setenv PATH "/bin:/usr/bin:/usr/local/bin:/home/70userX/my_uid/my_dir"
endif

Note that you replace '/home/70userX/my_uid/my_dir' with your directory, you can add more paths seperating entries with ':'. When you first log in the .cshrc file is run and will execute the above code. If your PATH variable is defined it will add your entries in the IF section of the above code. If no PATH variable is defined then it will use the code you specified in the ELSE section of the above code. For more information about what the 'shell' can do for you type 'man tcsh' for detailed information about the tcsh-shell.

Linux Permissions (chmod)

Linux file and directory permissions can be seen using 'ls -l' command. Directories will start with a 'd' as in 'drwxr-xr-x' and files will start with '-' as in '-rw-r--r--'. That is, the first character refers to the file type (directory/file). The next 9 characters refer to the permissions rwx or read-write-execute. Characters 2-4, ie, drwxr-xr-x refer to the local user permissions, characters 5-7 drwxr-xr-x the group permissions, and characters 8-10 drwxr-xr-x the world permissions.

The chmod command can be used to set the permissions for files and directories. To set the permission for your homedirectory to be readable by the world (used to setup your own webpage) use 'chmod 711 ~' your directory will be set as follows: 'drwx--x--x'. An easy way to specify and remember the permissions is as follows. The numbers 7-1-1 refer to the set of permissions of local-group-world respectively. In binary '7' translates to '111' which implies that bits 'rwx' are set. A '1' in binary refers to '001' meaning '--x' respectively (rw are 0 and x is 1). Hence '711' translates to '111001001' which in turn is 'rwx--x--x'. Webpages files require to have permissions '755' which translates to '-rwxr-xr-x' (verify this for yourself). That is all files are executable and readable by the world (therefore they are visible to www). Note that the files have write access by the local user (yourself) only - never use the command 'chmod 777'!!

Linux Processees

Anything that you run, launch, or start in linux is a process. When you log into linux a number processees will start under your linux ID. To view your current linux processees open an xterm and run:

ps aux | grep <LOGIN_NAME>

ofcourse you must substitute your login-name with <LOGIN_NAME>.

The top command allows you to view the top computationally intensive programs on any given system. Try running top (type q to exit top) and check what is running on your system.

You can run interactive processees in the foreground meaning that the process is bound to the terminal shell. The shell will interact with the process until it terminates. The second way to run process is in the background, you launch your process and then add '&'. Say you like to launch firefox in the background simply type:

firefox &

You can then use your shell for other tasks. Background processees are particularly useful if you like to run programs remotely or in parallel. Once you launch processees in the background use the command jobs to see how many and what processees you have launched. WARNING: Once you have launched a program in the background you must stop the process before you logout! Simply logging out will not stop a program that is in the background. Graphical programs can be easily stopped but command line programs may not have an interface available. In this case you must use the 'ps aux' command in conjunction with the 'kill -9 <PID>' command (please check the man pages, man kill for more details about the kill options). The <PID> or process ID is the value of the output of the second column of 'ps aux'.

Since you are sharing a linux machines with many other users you should be aware of how many processees your running and how computationally intensive your processees are. If you will be running a job that is computationally intensive over an extended period of time then you should be using the nice command (man nice). The nice command will run your process at a lower scheduling priority than the default user process. If you have already started a process and you wish to 'nice' the process while it is running use the renice command, it is used in conjunction with the pid (process ID). To renice a running program 'bigjob' for user test:

[test@epsilon12]$ ps aux | grep bigjob
[test@epsilon12]$ test 28284 0.0 3.2 56980 32584 pts/2 S Mar04 2:20 bigjob
[test@epsilon12]$ renice +20 28284

Only the owner of the running process or root can change the scheduling priority of a process.

ssh without a password

Sometimes you may want to be able to ssh (secure-shell) between linux hosts without typing your password. Typically this is done when your doing some sort of parrallel programming, ie, using lam or mpi.

To ssh without a password between SCS epsilon hosts:
  1. ssh-keygen -t rsa
  2. now enter a filename, ie, identity and no passphrase
  3. mv ~/.ssh/identity.pub ~/.ssh/authorized_keys
  4. chmod 600 ~/.ssh/authorized_keys
You must now log into every SCS linux machine at least once to initialize the encryption key per host. After you logged in once you should be able to ssh to the host without typing your password.

Re-directing the display

Sometimes you may want to run a graphical application on a remote host. Say a linux machine has some extra software running that is not present locally on your machine. When you run the command you may receive this error message like: Can't open display. In this case you must re-direct the display to your local machine.

Say I am logged onto epsilon03 and I opened an x-term and ssh'd to epsilon10. I then try to run a graphical application but I receive the message Can't open display. To re-direct the display from epsilon10 to epsilon03 do the following:

  1. [epsilon03 ~]$ xhost + epsilon10
  2. [epsilon10 ~]$ setenv DISPLAY epsilon03:0.0
Now, you should be able to run graphical applications remotely from epsilon10.
© 2009 Carleton University, School of Computer Science, 1125 Colonel By Drive, Ottawa, Ontario, K1S 5B6, Canada, Tel.: 1-613-520-4333
| Contacts |