||A Unix/Linux terminal is a application that allows you to communicate with a system. Typically when you start up a terminal it has a shell attached to it that allows commands to be sent and received from the Unix/Linux system. An xterm shell is like a command windows in windows. Two of the most common Unix/Linux shells are korn (ksh) and bash.
||Runs command as a separate process (thread) Type: xterm &
Results: A new command shell should appear and you will be able to use both command shells. If you had type xterm without the & you would not be able to use the first command shell until you exited the first.
Type cd ~
Result ~ is your home directory.
||gets a list of all files and directories in current directory (-l options gives a detailed view and –a to see configurations files.) In Unix configurations files have a “.” prefix. Type: ls –l
Results: something like this on a CYGWIN installation: -rwx—— 1 tharris mkgroup-l-d 2402 Apr 12 09:41 myproject.r
drwx——+ 13 tharris ???????? 0 Jan 28 06:45 Application Data
drwx——+ 6 tharris ???????? 0 May 25 06:12 Desktop
-rwx——+ 1 tharris ???????? 1905 Apr 12 09:29 DesktopGarpLog.txt
drwx——+ 3 tharris ???????? 0 Apr 12 09:34 Favorites The first column with the cryptic sequence of letters if indicates the rights and permissions.
-rwx: a file with read, write and execute permissions
drwx: a directory with read, write and execute permissions
The second column is the user who created the file (owner).
The third is the Unix group from which the file was created. File created while in Window do not have Unix groups so appear as ????????.
The forth is the file size followed by creation data and file name
||| Pipe or redirect output to another command. This allows you to chain multiple commands together without having to create files at each immediate step. > Pipe or redirect output to a physical file. Type: ls –l > test.out
Results: Now you have created a text file is the deletes of the file located
||Make a directory. Type: mkdir test
Results: type ls and see your directory listed.
||Moves file. This is useful to rename output files when debugging a process.
Type: mv test.out list.out
Results: now the file test.out has been renamed to list.out.
||Copy a file or directory (with -r option).
Type cp list.out test.out
Results Now you have two file list.out and test.out
||Remove a file or directory.
Type rm list.out
Results the list.out file has been deleted.
||Allows read-only access to a file. To quit out of MORE type :q.
Type: more test.out
Result: The output should look the same as if you ran the ls –l command.
||Also allows read-only access to a test file. The name is a misnomer; LESS has greater capabilities than MORE. Like more to quit type :q. Both MORE and LESS have far more capability than I will discus here.
|vi and emacs
||Two powerful text editors for Unix. VI is a command line text editor and does require a little sit down time with the manual. Once you have mastered a few simple commands VI is a quick tool for editing text. If, however, you want a tool more familiar to Windows text editors try Emacs.
||To make text appear in the command window use the echo command. This can be useful to alert users to how a script or program is running.
|Creating a script
|| To create a script type emacs myscript.sh & in the command prompt. Now lets put all that we have learn into use. Type the follow code: #!/usr/bin/sh
echo I am starting
ls -l > ./mytest/test2.out
cp test2.out test3.out
mv test3.out test4.out
echo I am done. Now save the file by clicking on the familiar save icon. Everything should look familiar except #!/usr/bin/sh. That line tells Unix which shell to use to execute the script.
||The change the permissions or mode of a file use chmod. A good setting is 775. Type chmod 775 myscript.sh
Results now we can execute the script myscript.sh.
|Executing a Script
|| Type ./myscript.sh
I am starting
I am done Note: If nothing appears between the two statements in the command terminal the script ran successful. To check the results change to the directory my testand check the results.
||If you want a script to pause between command use the sleep command. This can be useful to enable the user to kill a process that spawns lots of other processes at way points in the script. Type sleep 360
Results the command terminal should pause for 10 minutes
||Allows you to execute a script and log out without termination the script. This is useful with scripts that take a long time to run.
Type nohup ./myscript.sh
Result: nohup: appending output to `nohup.out
You will not see anything in the command window. The output will be redirected to a text file. The text  272 tells you the process id and will be different for you.
|Reading output from Nohup
||Type less nohup.out
||Allows you to see the status of processes (with the -p option you can specify a process to examine). This can be useful when running long jobs. It is similar to task manager. Example, add the following code to your script: sleep 360. Now when you run the script it will pause for 10 minutes. This will give us time to use the PS command. Type nohup ./myscript.sh
Result: nohup: appending output to `nohup.out
 5056 Type ps –p 5056
PID PPID PGID WINPID TTY UID STIME COMMAND
5056 1896 5056 2168 0 156949 08:23:37 /usr/bin/sh Another example is to show all the processes you have spawned.
Type ps –u
Results: a STIME COMMAND
2528 1 2528 2528 con 156949 08:03:43 /usr/X11R6/bin/Xwin
2336 1 2336 2876 con 156949 08:03:43 /usr/bin/xterm
1220 1 1220 2984 con 156949 08:03:43 /usr/X11R6/bin/wmaker
3912 1220 1220 1260 con 156949 08:03:45 /usr/X11R6/bin/wmaker
4368 2336 4368 4528 1 156949 08:03:49 /usr/bin/bash
5056 1896 5056 2168 0 156949 08:23:37 /usr/bin/sh
6088 5056 5056 5848 0 156949 08:23:40 /usr/bin/sleep
4612 1896 4612 3736 0 156949 08:25:24 /usr/bin/ps
||List the top 10 processes on the machine. Important to tell whether you are playing nice with others.
||Allows a user to stop a process
Type: kill 6088
Process 6088 will be terminated regardless of state
||If you are not playing nice with others (ie you are hogging resources) you can change the priority of your process to allow others to get done with what ever they need to do. Nice enables this. The values range from 1(highest) to 19 (lowest). 10 is the default. Type ; nice -17 nohup ./myscript.sh
Result: the process will be towards the end of priority. When allocating resources Unix will prioritize other user processes over yours.