Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic UNIX OLC Training.

Similar presentations


Presentation on theme: "Basic UNIX OLC Training."— Presentation transcript:

1 Basic UNIX OLC Training

2 Shells A shell is how you primarily act with the operating system at the command line Two main types of shells: Bourne shell & C shell Modern variants are Bourne Again Shell (bash) and trusted c shell (tcsh) Athena uses tcsh; most everything will be in tcsh syntax. If bash is different, it will be noted

3 Commands Most UNIX commands are of the form: command -option argument
Options (occasionally called 'flags') change the behavior of a command are usually preceded with one or two dashes Arguments are the “input” to the command Commands can take anywhere from 0 to n arguments and options.

4 Example Command with no options or arguments athena% renew
Command with 2 arguments and no options athena% attach consult cref Command with one option and no arguments: athena% znol -l

5 Shell & Environment Variables
Contain information about working environment Change behavior of various programs Change behavior of shell Environment variables apply to your login session Shell variables apply to one instance of your shell (ie: an xterm or gnome-terminal)

6 Environment Variables
Display all environment variables: printenv Display a single variable printenv USER echo $USER Set a variable Tcsh: setenv FOO bar Bash: export FOO=bar

7 Shell variables Display all variables: set Display a single variable:
echo $prompt Set a variable: Tcsh: set foo=bar Bash: foo=bar

8 I/O Redirection Command > filename
Redirect output of command to new file “filename” Command >> filename Append output of command to new file “filename” command < filename read input from file called “filename” command | command2 take the output of command and make it the input of command 2

9 Examples ls > /tmp/files.txt ls Public >>/tmp/files.txt
ls | more sort < /tmp/files.txt

10 Basic Commands Move file1 into the directory directoryname
mv file1 directoryname Copy file1 to the directory directoryname cp file1 directoryname Go back/up one level cd .. Create the directory directoryname mkdir directoryname Restore the previously deleted file file1 undelete file1 Mark file1 for deletion, will be deleted in 3 days delete file1 Move (rename) file1 to a new file called file2 mv file1 file2 Copy file1 to a new file called file2 cp file1 file2 Change current directory to directoryname cd directoryname Show name of current directory pwd List contents of current directory ls

11 Other Commands Display contents of a file cat filename.txt
Count lines in a file: wc -l filename.txt (-c for characters) Display only the beginning or end of a file head filename.txt tail filename.txt

12 grep grep is a “searching” utility
it matches patterns (“regular expressions”) Can do lots of complex things, but simple text search is the best grep dog animals.txt ls | grep thesis grep -i causes it to be case-insensitive

13 sort Sorts the input and displays it sort -n will sort numerically
otherwise it goes 1, 10, 2, 3, 34, 4, etc.

14 Pagers A pager allows you see one “page” of information at a time
Common pagers are “more” and “less” Basic pager commands: space = page down enter = line down b = page up y = line up / = search q = quit

15 Examples ls | more less mydocument.txt

16 Shell Wildcards * Match anywhere from 0 to n characters ?
match one character Examples: ls foo* will list “foo”, “foo2”, “foobar” ls foo? will only list “foo2”

17 Manual Pages man commandname whatis commandname
apropos <search term> Some commands don't have man pages (ie: fs) Try -help, --help, -?, -h Google

18 File Permissions ls -l shows file permissions -rw jdreed mit 684 Sep 12 09:51 /tmp/tkt_p16901 10 columns. First is – if it's a file, “d” if it's a directory Remaining 9 are 3 groups of 3. First group for user (u), 2nd group for group (g), 3rd group for “everyone else” (o)

19 File modes r = read (or list files, if directory)
w = write (or delete/create if directory) x = execute (or access if directory) s = run as though you were the owner t = sticky (on directory, regardless of permissions files can only be accessed by the owner or root)

20 chmod change the mode of a file: chmod go-rwx myfile
remove read write and execute for group and other chmod u+w myfile Give yourself (owner) ability to write to file On AFS, only the user (u) permissions are used, group and other are ignored, as they are governed by AFS permissions

21 Jobs and Processes ps show processes in current shell ps -u
show all your processes ps ax (or ps -ef) show all processes on the machine

22 Foreground and Background
All processes are run in the foreground by default ie: you start xcluster, you don't get your athena prompt back until it's done Add an & to the end of the command to run in the background To background an already running process Ctrl-Z to suspend it bg to background it

23 jobs The jobs command can give you a list of suspended and running jobs fg and bg take “%n” as an arugment, where n is the number of the job as shown by “jobs”

24 killing processes kill can take a job number (from 'jobs') or a process id (from ps) kill -9 can kill off more stubborn processes Don't use it unless kill doesn't work

25 Unix Utilities df Lists free space on filesystem du
shows disk usage – ideal for finding large files in your home directory file attempts to identify a file's contents


Download ppt "Basic UNIX OLC Training."

Similar presentations


Ads by Google