echo $SHELL
$ (dollar sign) - sh, ksh, bash % (percent sign) - csh, tcsh
Bourne C TC Korn BASH sh csh tcsh ksh bash ______________________________________________________ Programming language Yes Yes Yes Yes Yes Shell variables Yes Yes Yes Yes Yes Command alias No Yes Yes Yes Yes Command history No Yes Yes Yes Yes Filename completion No Yes* Yes Yes* Yes Command line editing No No Yes Yes* Yes Job control No Yes Yes Yes Yes ______________________________________________________ * not the default setting for this shell
To see your current shell's processes:
% ps PID TTY TIME CMD 26450 pts/9 0:00 ps 66801 pts/9 0:00 -cshTo see a detailed list of all of your processes on a machine (current shell and all other shells):
% ps uc USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND jsmith 26451 0.0 0.0 120 232 pts/9 R 21:01:14 0:00 ps jsmith 43520 0.0 1.0 300 660 pts/76 S 19:18:31 0:00 elm jsmith 66801 0.0 1.0 348 640 pts/9 S 20:49:20 0:00 csh jsmith 112453 0.0 0.0 340 432 pts/76 S Mar 03 0:00 cshTo see a detailed list of every process on a machine:
% ps ug USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND root 0 0.0 0.0 8 8 - S Feb 08 32:57 swapper root 1 0.1 0.0 252 188 - S Feb 08 39:16 /etc/init root 514 72.6 0.0 12 8 - R Feb 08 28984:05 kproc root 771 0.2 0.0 16 16 - S Feb 08 65:14 kproc root 1028 0.0 0.0 16 16 - S Feb 08 0:00 kproc { lines deleted } root 60010 0.0 0.0 1296 536 - S Mar 07 0:00 -ncd19:0 kdr 60647 0.0 0.0 288 392 pts/87 S Mar 06 0:00 -ksh manfield 60968 0.0 0.0 268 200 - S 10:12:52 0:00 mwm kelly 61334 0.0 0.0 424 640 - S 08:18:10 0:00 twm sjw 61925 0.0 0.0 552 376 - S Mar 06 0:00 rlogin kanaha mkm 62357 0.0 0.0 460 240 - S Feb 08 0:00 xterm ishley 62637 0.0 0.0 324 152 pts/106 S Mar 06 0:00 xedit march2 tusciora 62998 0.0 0.0 340 448 - S Mar 06 0:05 xterm -e dilfeath 63564 0.0 0.0 200 268 - S 07:32:45 0:00 xclock tusciora 63878 0.0 0.0 548 412 - S Mar 06 0:41 twm
kill [-signal] process_identifier(PID)Examples:
kill 63878 - kills process 63878 kill -9 1225 - kills (kills!) process 1225. Use if simple kill doesn't work. kill -STOP 2339 - stops process 2339 kill -CONT 2339 - continues stopped process 2339 kill -l - list the supported kill signalsYou can also use CTRL-C to kill the currently running process.
To start a job in the background, use an ampersand (&) when you invoke the command:
myprog &
To put an already running job in the background, first suspend it with CRTL-Z and then use the "bg" command:
myprog - execute a process CTRL-Z - suspend the process bg - put suspended process in background
jobs [1] + Running xcalc [2] Running find / -name core -print fg %2
jobs [1] + Running xcalc [2] Running find / -name core -print stop %2
jobs [1] + Running xcalc [2] Running find / -name core -print kill %2
> - redirect stdout (overwrite) >> - redirect stdout (append) < - redirect stdin 2> - redirect stderr (sh,ksh,bash) >& - redirect stdout and stderr (csh,tcsh)
mail tony < memo - uses the file memo as input to the mail program ls -l > my.directory - redirects output of ls -l command to a file called my.directory. If the file already exists, it is overwritten cat Mail/jsmith >> Oldmail - appends the contents of Mail/jsmith to the file Oldmail (does not overwrite) myprog >& output - redirects stdout and stderr from myprog's execution to a file called output (csh,tcsh) (myprog > out) >& err - redirects stdout from myprog's execution to a file called out and stderr to the file err (csh,tcsh) myprog 2> runtime.errors - redirects stderr from myprog's execution to a file called runtime.errors (sh,ksh,bash) myprog > output 2>& - redirects stderr and stdout from myprog's execution to a file called output (sh,ksh,bash) myprog > out 2> err - redirects stdout from myprog's execution to a file called out and stderr to the file err (sh,ksh,bash)
command1 [arguments] | command2 [arguments]
Operation 1 who > temp sort temp Operation 2 who | sort
ls -al | more who | more ps ug | grep myuserid who | grep kelly
who | sort | lp
set history = 100
history 35 12:34 sort < unsorted > sorted.list 36 12:34 cat sorted.list 37 12:35 ls * > unsorted 38 12:35 cat unsorted 39 12:35 ls 40 13:06 history 41 13:08 alias 42 13:11 ls 43 13:11 vi .cshrc
set savehistory = 50
!! - repeats last command !number - repeats numbered command from history list !string - repeats last command starting with string
^old^new - changes the string "old" to the string "new" in the last command issued !number:s/old/new/ - changes numbered command from history list; substitutes the string "old" with the string "new". Note that there is no space between number and :
alias entered_command executed_commandSome examples:
alias m more alias rm "rm -i" alias h "history -r | more" alias xpvm /source/pd/xpvm/src/RS6K/xpvmTo view all current aliases:
aliasTo remove a previously defined alias:
unalias alias_name
ls *.txt - list files with .txt suffix ls [abc]* - list files with names that start with a, b or c lpr prog?.c - print files named prog?.c where ? is any character cd ~jsmith - change to user jsmith's home directoryYou can "turn off" filename generation by setting the noglob variable. This will permit special characters to be interpreted literally. For example:
set noglob
To use filename completion, you need to set filec, either on the command line or in one of your initialization files.
set filecThen, when specifying a filename, type the part which is unique and hit the escape key (C shell) or tab key (TC Shell). For example, if you had a directory with a long name, such as "Introduction.UNIX.Filesystems", you could cd to that directory by using the cd command with only a portion of the file's name, provided that the portion you specify is unique (no other files have similar names)
cd Intro<ESC>Note: typing a portion of a filename and then hitting CTRL-D instead of ESCape or TAB will display a list of the filenames which match.
set - assigns non-numeric string variables locally unset - removes a previously "set" variable set - shows all "set" variables setenv - assigns non-numeric string variables globally unsetenv - removes a previously setenv variable setenv - shows all setenv variables @ - assigns numeric variables locally echo $variable - displays value of variable
set name=fred - Sets variable name to value of fred unset name - Unsets the variable name set path=($path . ~/bin) - Adds to current setting of string array variable path setenv DISPLAY makena:0 - Sets environment variable DISPLAY echo $HOME - Displays value of variable HOME set colors=(red green blue) - Assigns three values to the string array variable colors @ count = 1 - Sets numeric variable count to one @ count = ($count + 1) - Adds one to numeric variable count set counts = (1 22 4 9) - Assigns 4 values to numeric array variable counts @ counts[2] = 5 - Assigns values to second element of numeric array variable counts @ echo $counts[3] - Displays value of third element of numeric array variable counts
set cdpath=(/usr/jenny /usr/jenny/mail ../)
set prompt = "`hostname -s`% "
/etc/environment /etc/profile /etc/cshrc /etc/login
Executed during interactive login .login - csh, tcsh .profile - sh, ksh, bash .bash_profile - bash (alternative 1) .bash_login - bash (alternative 2) Executed for every new shell .cshrc - csh, tcsh .tcshrc - tcsh .kshrc - ksh .bashrc - bash
source .login source .cshrc
.logout> - csh, tcsh .bash_logout - bash
This concludes the tutorial. Return to the Table of Contents