A Short Unix Tutorial - PowerPoint PPT Presentation

1 / 43
About This Presentation
Title:

A Short Unix Tutorial

Description:

An operating system used on everything from servers to embedded systems. ... apropos keyword. tells you all man pages that contain keyword. Files and Directories: ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 44
Provided by: edogdu
Category:
Tags: apropos | short | tutorial | unix

less

Transcript and Presenter's Notes

Title: A Short Unix Tutorial


1
A Short Unix Tutorial
  • Erdogan Dogdu
  • TOBB Ekonomi ve Teknoloji Üniversitesi
  • Some material is used from http//csua.berkeley.
    edu

2
Outline
  • I. getting help
  • II. the file system
  • III. the shell
  • IV. editors
  • V. input and output redirection
  • VI. process management

3
What is it and where do you get it?
  • An operating system used on everything from
    servers to embedded systems.
  • To you, probably a prompt
  • gt type stuff here

4
If you know only one thing, know how to read a
manual
  • gtman command
  • gives you help on that command.
  • gtapropos keyword
  • tells you all man pages that contain keyword.

5
Files and DirectoriesNaming something gives you
power over it.
6
Absolute Addressing
7
Addressing relative to your home dir.
8
Addressing relative to your current dir.
9
File system commands
  • pwd - report your current directory
  • cd ltto wheregt - change your current directory
  • ls ltdirectorygt -list contents of directory
  • cp ltold filegt ltnew filegt - copy
  • mv ltold filegt ltnew filegt - move (or rename)
  • rm ltfilegt -delete a file
  • mkdir ltnew directory namegt -make a directory
  • rmdir ltdirectorygt -remove an empty directory

10
getting recursive
  • remove a directory and its contents
  • rm -r ltdirectorygt
  • copy a directory and its contents
  • cp -r ltdirectorygt

11
File permissions.
  • There are 3 kinds of people in the world you
    (user), your friends (group) and everyone else
    (other).
  • Each sort of person may or may not be able to
    read, write, or execute a file.
  • gtls -l .forward
  • -rw-r--r-- 1 darin csua 23 Jan 23 2002
    .forward
  • gtls -l .cshrc.local
  • -rwxr-xr-- 1 darin csua 2988 May 19 0048
    .cshrc.local

12
executing
  • executing a file means running it as a program.
  • executing a directory means setting your
    current directory to it using cd.

13
Changing File Permissions
  • make a file readable to your friends
  • chmod gr ltfilenamegt
  • change who owns a file
  • chown ltusergt ltfilenamegt
  • change to which group the file belongs
  • chgrp ltgroupgt ltfilenamegt

14
touch
  • look at the full listing again
  • gtls -l .forward
  • -rw-r--r-- 1 darin csua 23 Jan 23 2002
    .forward
  • Each file has a date stamp of when it was
    modified.
  • Use touch to set the timestamp to the current
    clock.
  • touch ltfilenamegt
  • Touch creates the file if it didnt exist
    beforehand.
  • You can only touch a file to which you can write.

15
Symbolic Links
  • use ln -s ltold filegt ltsecond namegt to create a
    symbolic link to a file.
  • gtls -l .forward
  • -rw-r--r-- 1 darin csua .forward
  • lrwxr-xr-x 1 darin csua .forward.link_at_ -gt
    .forward
  • The first l tells you that its a symbolic
    link.
  • Symbolic links can be used as if it were its
    target.

16
whats a shell?
  • The shell is the program that
  • runs when you log in. It prints
  • the prompt and reads what you
  • type, invokes programs, etc.
  • your window to the Unix world.
  • use chsh ltnew shellgt to change your shell

17
File Globbing
  • some commands can work on many files at once
  • gt rm file1 file2 file27
  • Use to match any number of unknown characters
  • gt rm file
  • Use ? to match one unknown character.
  • gt rm file?

18
(un)aliasing
  • create shortcuts for yourself
  • gtalias ll ls -la
  • Use alias with no arguments to discover current
    aliases
  • gtalias
  • rm rm -i
  • ll ls -la
  • Type unalias rm to remove alias.

19
shell variables, echo
  • (tcsh) gtsetenv BOB joe
  • (tcsh) gtprintenv BOB
  • joe
  • (tcsh) gtecho BOB
  • joe

20
PATH a very important shell variable
  • gtecho PATH
  • /home/d/da/darin/bin/opt/local/bin/opt/local/bin
    /pbmutils/usr/bin/usr/sbin/opt/SUNWspro/bin/us
    r/ccs/bin/opt/local/X11/bin/usr/dt/bin/usr/open
    win/bin/opt/local/gnu/bin/opt/local/games/bin/u
    sr/ucb./
  • If a program (like ls) is in one directory found
    in your path, then typing it (gtls ltentergt) will
    execute it.
  • Otherwise you can type the full absolute address
    to execute a program (gt/usr/bin/ls ltentergt)

21
finding things in your PATH.
  • Type which ltcommandgt to find the location of
    the program which would be run when you type
    ltcommandgt.
  • If you dont remember if it was chgrp or chgroup,
    type chltcontrol-dgt to get a list of commands
    that starts with ch.
  • when all else fails, use find to find a file.
  • gtfind ltstart dirgt -name .doc

22
Other useful pre-defined shell variables
  • HOST what computer youre logged into
  • PAGER program used display man pages
  • PWD current directory
  • GROUP what group youre in
  • USER your login

23
Shell scripts.
  • If you have a bunch of commands youd like to
    automate, you can put them on separate lines of a
    file. Then type source ltfilegt to run the
    script.
  • If the first line of your script looks like
  • !ltprogram namegt
  • then you can make the script executable. When it
    executes, it uses ltprogram namegt to interpret the
    contents of the script.

24
Login scripts
  • Most people have a script that executes when they
    log in. It is commonly used to set up ones PATH
    and aliases.
  • For Bash it is .bashrc file in your home
    directory

25
vi
  • is an editor available on all decent Unix
    systems. Developed at Berkeley.
  • Has two modes command and insert. In insert
    mode you can type normally.
  • Press escape to get into command mode. In
    command mode each letter is a command.
  • hjkl ? ????

26
vi commands
  • h, moves cursor left
  • j, moves cursor down
  • k, moves cursor up
  • l, moves cursor right
  • x, delete character
  • dw, delete word
  • dd, delete line
  • p, put last deletion after cursor
  • u, undo last change

27
vi commands (cont.)
  • i, turn on insert mode (hit the esc key twice to
    stop)
  • wq, write file and quit
  • q!, quit without saving file
  • ctrl f, move forward one page
  • ctrl b, move backward one page
  • /text, will search for next occurance of 'text'
    (hitting n will find next occurence)
  • G, go to end of file
  • 1G, go to first line of file

28
STD
  • All terminal programs have
  • standard output, which is usually your screen
  • standard input, which is usually your keyboard
  • standard error, which is also the screen

29
redirect output to a file with gt
  • If you type who at the prompt, you will get a
    list of who is logged into the system.
  • If you type who gtf, a file named f will be
    created and the standard output of who will be
    placed in that file instead of to your screen.

30
gt vs. gtgt
  • By default, who gtf will overwrite the file f.
  • Use who gtgtf to append to f rather than
    overwriting it.

31
redirecting input from a file with lt
  • The program sort will sort its standard input and
    then print it on standard out.
  • To sort the lines of file1 and display
  • sort lt file1
  • To sort the lines of file1 and save in file2
  • sort lt file1 gt file2

32
The output of one program can be the input to
another.
  • who sort
  • The output of who is sorted and shown on your
    terminal screen.

33
grep
  • grep shows only those lines containing its search
    pattern.
  • To see all lines in a file containing bob
  • grep bob lt file1

34
The cat command
  • the arguments to cat are concatenated together
    and displayed on stdout. To view a file
  • cat file1
  • if no arguments, cat puts on stdout whatever you
    type on stdin, so this does the same thing
  • cat lt file1

35
To start a process in the background, use .
  • example
  • big_program gt output
  • big_program will not have input!

36
Managing Jobs
  • To suspend the currently active program, use
    ltcontrol-zgt.
  • To return to the program you just suspended, type
    fg
  • To put the program you just suspended in the
    background, type bg

37
To see a list of your programs running, type ps.
  • gtps
  • PID TTY TIME CMD
  • 866 pts/1 000000 tcsh
  • 872 pts/1 000000 ps

38
use kill to end a process
  • gtps
  • PID TTY TIME CMD
  • 866 pts/1 000000 tcsh
  • 874 pts/1 000000 cat
  • 875 pts/1 000000 ps
  • gtkill 874
  • 1 Terminated cat

39
kill -9
  • If kill ltPIDgt doesnt end your process, use
    kill -9 ltPIDgt

40
Other Unix Utilities
  • Finding files
  • find path name expression
  • Ex. find -name ch
  • Search home directory to find files that start
    with ch
  • Displaying file contents
  • cat filename
  • more filename

41
Other Unix Utilities
  • Finding text file size
  • wc filename
  • Sorting (file contents) line by line
  • sort filename
  • sort lt filename
  • Piping
  • command command
  • Ex. cat readme.txt sort

42
Other Unix Utilities
  • Translate or delete characters
  • tr d 0-9 lt myfile.txt
  • remove numbers from myfile.txt
  • tr A-Z a-z lt myfile.txt
  • convert upper case to lower case
  • tr \n lt myfile.txt
  • show contents word by word

43
The End
Write a Comment
User Comments (0)
About PowerShow.com