Before you go to your PSO, make sure that you know the login and
password for mentor. This is the same account and password that you use
for the PCs in the Purdue computer labs. If you don't know your ITaP login
and password go to MATH 231 to get it before your PSO.
Now logout typing
mentor.cc.purdue.edu% chsh
Changing login shell for <your-login> on *all* ACMAINT hosts.
Old shell: /bin/csh
New shell [/bin/csh]: /usr/local/bin/tcsh
mentor.cc.purdue.edu% exitLogin into mentor again. After you login, you should obtain a ">" prompt that is the tcsh prompt.
> lsThe command "ls" with no arguments lists the contents of the current directory. If you want to see the details of the files, type:
> ls -alThe command "pwd" prints the directory path of the current directory. This current directory is the directory where the shell is currently in. Type:
>pwdThe directory path printed is a list of the directories necessary to reach the current directory from the root directory.
/home/lookout/<some-letter>/<login>
To create a new directory (for example a directory called cs354), type:
> mkdir cs354To change the current directory to the cs354/ directory, type:
> ls
> cd cs354You will notice there are no files in there. Now type:
> ls
> ls -alYou will see two files: "." and ".." One dot means the current directory, and ".." means the parent directory.
To change the current directory to the parent directory type:
> cd ..The home directory is the directory where all your files are stored and is where the current directory points to when you login. To change the current directory to your home directory type "cd" with no arguments. Type:
> cdSometimes you would like to go back to the previous command. To do that in tcsh type the <up arrow> (the key that has the arrow pointing upwards). Type:
> pwd
> ls
> <up arrow>several times and you will get the last commands. To execute the current command displayed type <ENTER>. You may also type the <down-arrow> to go to the next command.
For example, type <up-arrow> until you find the "ls -al" command and then type <ENTER>.
If you have made an error while typing, you may use the <left-arrow>, <right-arrow>, or <backspace> to move the cursor and correct it.
You don't need to type all the characters for a file or command. You may use <tab> and <ctrl-d> to complete the name of a file.
For example, type:
> ls /usr/j<tab>
This will complete to "ls /usr/java"
If the prefix matches several files, you may see a list of files matched by typing:
> ls /usr/p<ctrl-d>
This will show all the files that start with "/usr/p"
Also you can reffer to a list of files by using the character "*". The "*" character in a file name represent one or more characters. For example:
> ls /usr/lib/*.a
Lists all the files that end in ".a" in the directory /usr/lib.
| ls | Lists the contents of the current directory |
| ls -al | Lists the contents of the current directory in detail |
| pwd | Prints the path of the current directory |
| mkdir new-directory | Create a new directory |
| cd directory-path | Change to a directory |
| cd | Change to home directory |
| cp old-file new-file | Copy a file from old-file to new-file |
| mv old-file new-file | Rename a file from old-file to new-file |
| rm file | Remove a file |
| echo "message" | Outputs the string "message" |
| <up-arrow> | Get previous command |
| <down-arrow> | Get next command |
| <left-arrow>, <right-arrow> | Move cursor to the left or rigth. |
| <tab> | Path-completion |
> /usr/openwin/bin/xterm -sb &The "-sb" option is for scroll-bar and the "&" is to run xterm in the background. Running a program in the background means that the shell will return a prompt immediately and will not wait until the program completes.
You may open as many xterm windows as you want using the command above.
>/opt/SUNWspro/bin/xemacs &This command will run xemacs in the background. You will see the xemacs window appear on your screen.
You can use xemacs using the pull-down menus like other editors with a graphical user interface. If for some reason you are stuck in the prompt at the bottom line type <ctrl-]> More information on xemacs can be found in xemacs-tutorial.txt.
> whoExecute this command and find your name in the list.
You may list the contents of this directory typing:
> ls /There are some important directories such as:
/dev
All the devices of the machine (terminals, printers etc.)
/etc
Administration
/usr/include
Header files used for "C" programs
/usr/bin
Commands
Try
> ls ~
> ls ~/cs354
> ls ~cs354 - Lists the cs354 home directory
For example, type:
> cd /bin - Go to /bin directoryNow try to lists all the files that start with m and that contain g.
> ls - Lists all the files in /bin
> ls m* - Lists the commands that start with m
> ls *ma* - Lists all the files that contain ma
> ls *ma* *ta - Lists all the files that contain "ma" or end with "ta"
Wildcards do not match files that start with a "." . If you want to see those files, you will have to either use "ls -al" or match those files explicitly.
Type:
>cd - Goes to home directory
>ls - Lists files in home directory (there are no files that start with "."
>ls -al - Lists all files, including the ones that start with "." and also prints timestamp
>ls .* - List all files that start with "."
>echo .* - Prints to the screen the names of the files that match .*
>pwd - Gives the current directoryIn your home directory, create the following directory structure:
>cd - Goes to the home directory
>cd .. - Goes to the parent directory
>cd <dir> - Goes to a specific directory <dir>
>mkdir <dir> - Creates a new directory
~/cs354/lab1/ --- that contains
subdir1/ subdir2/
subdir1/ contains
subdir11/ subdir12/
subdir2/ contains
subdir21/ subdir22/
To redirect the standard output of a command to a file you need to add "> filename" at the end of the command. For example, to write the list of files in your home directory to a file "ls-out" type:
cdYou can edit the file ls-out to see its contents. Alternatively, you can use the command "cat filename" to print the contents of the file to the screen. For example to print the contents of "ls-out" type:
ls > ls-out
cat ls-outAlso, it is possible to append the output of a command to an existing file by adding ">> filename" at the end of the command. For example, type:
ls >> ls-outAlternatively to cat you may use more. The difference between these two commands is that for large files cat does not stop and more will prompt after every page of text displayed. When using more type <space> to go to the next page.
ls >> ls-out
cat ls-out
Type:
more ls-out
For example, try listing a non-existing directory and send the output to "errout".
ls none-existing > erroutThis command will print an error to the screen instead of the "errout" file. To redirect both the output and the errors of the command to "errout" type:
ls none-existing >& errout
cat errout
ls >>& errout
cat errout
The input of the command "cat" with no arguments is the standard input. You can redirect the standard input of a command by adding "< filename" at the end of the command. For example the following two commands will display the contents of the file ls-out:
cat ls-out
cat < ls-out
cdTo print the lines that contain the word "Total" in the file EggBasket.java type:
cd cs354/lab2
grep System EggBasket.java
grep Total EggBasket.javaTo print the lines that contain the word "System" in all the files in the current directory type:
grep System *In this case "*" matches the file names EggBasket.java and Hello.java.
grep System EggBasket.java | grep basketsIn this command line the output of "grep System EggBasket.java" goes to the input of the command "grep baskets".
Also you may send the output of this command to a file:
grep System EggBasket.java | grep baskets > out
cat out
> alias ll ls -alNow typing "ll" will be equivalent to typing "ls -al".
> ll
The alias you have created will go away when you logout. If you want to make the alias permanent, you will have to add the alias command to your ~/.login file. If this file does not exist, you can create one.
To remove an alias use "unalias":
> unalias ll
> ll
> printenvor to print a single variable type "printenv varname". For example, to print the value of the variable PATH type:
> printenv PATHThe most important variables are the following:
PATH - It is a list of colon separated directories where the commands typed are found. The shell will search the command in each directory until found or the end of the list is reached. By default the PATH variable includes the directory /bin.
DISPLAY - It is the Internet address of the computer where the x-windows applications are displayed. By default it is the IP address computer where you login.
HOME - it is the home directory.
PWD - It is the current directory.
SHELL - It is the shell program you are currently using.
Type the following:
printenv DISPLAYAlso you can use the variables as part of a command or argument by typing $ before the variable. For example, to print the contents of your home directory you can type:
printenv HOME
ls $HOMEThat is equivalent to typing:
ls ~You can also change the value of variables using "setenv VAR VALUE". For example, to set the value ~/cs354/lab3to variable lab3 you can type:
setenv lab3 ~/cs354/lab3In this way, you may use $lab3 everywhere you need the lab3 path.
printenv lab3
cd $lab3
ls
You may also append a value to an existing environment variable by setting the variable and adding the variable to the value. For example, you may add the directory /opt/SUNWspro/bin to your PATH environment variable in the following way:
(Note: The command "which command" tells you in which directory a command was found.)
Type:
printenv PATHIf after executing "xemacs &" the shell tells you that xemacs was not found, then the variable was not correctly set, try again. Also, it may be possible that you have already set up an alias for xemacs. You may unset the alias by typing "unalias xemacs" and try the previous steps again.
which xemacs - It should print that xemacs was not found.
setenv PATH /opt/SUNWspro/bin:$PATH - Adds xemacs dir to PATH
printenv PATH
which xemacs - It should print that xemacs was found.
xemacs &
To change the value of the PATH variable permanently you need to modify your .login file.
setenv PATH /opt/SUNWspro/bin:/usr/openwin/bin:$PATHMake sure that this line is spelled correctly in your .login file. Save the file and exit. Logout from the xterm and the telnet session. Then login again into mentor by clicking on the mentor icon, login, and type:
> xterm -sb &You will not need to type the directory of these commands anymore.
> xemacs &
When running a command in the background the prompt is printed before the command completes. You may need to type <Enter> to see the shell prompt again.
You can run any process in the background. For example:
> ls /dev -Runs ls in the foreground (default)> ls /dev & - Runs ls in the background