UNIXLINUX - PowerPoint PPT Presentation

1 / 52
About This Presentation
Title:

UNIXLINUX

Description:

Remote connection via cygwin may work, but otherwise you can use telnet (in that ... in a Cygwin command window to get a GUI connection to a UNIX machine. ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 53
Provided by: peopleSab
Category:

less

Transcript and Presenter's Notes

Title: UNIXLINUX


1
UNIX/LINUX
  • A Short Introduction

2
Overview
  • Remote connection to UNIX machines
  • Remote connection via cygwin may work, but
    otherwise you can use telnet (in that case you
    would have to implement first in Windows, then
    ftp your files, so as to leave less job to do
    over telnet)
  • IT tells you what you can use from outside
  • Simple UNIX commands
  • You are only responsible to know some/enough of
    them
  • Code development and potential problems
  • How to compile and build using g
  • Library not found if your system variables are
    not set properly
  • Makefiles
  • Debugging in UNIX

3
Connection to a UNIX machine
4
How to Connect to a UNIX machine?
  • Cygwin (suggested)
  • xwin
  • Telnet (for short connections)
  • SSH (Secure Shell, similar to a telnet window)
  • XWin32
  • ...

You can get them from \\software
5
How to Connect suggested
  • -Unless you have been using something else and
    you are happy with it, you should install Cygwin,
    which is a UNIX emulator for Windows
  • http//www2.sabanciuniv.edu/bt/servisler/akademik_
    destek/yazilim_lisansli/Cygwin/cygwin.html
  • -Bring up a command window by clicking the
    cygwin.bat icon under under C/cygwin

6
Cygwin Window
7
How to Connect suggested
  • - You can then type XWin -query blum -fp
    tcp/blum7100
  • in a Cygwin command window to get a GUI
    connection to a UNIX machine.
  • - Login with your email id and password (you
    should all have accounts, automatically)
  • Instead of typing the command
  • XWin -query blum -fp tcp/blum7100
  • you can use Su-Xwin which brings up a GUI to
    type in the xwin parameters. See
    howtouse-SU-Xwin... under lectures/week7/

8
UNIX commands
9
Text Editors
  • vi //commonly used - but needs to get used to
  • vim
  • pico //simpler
  • emacs //commonly used by non-vi people- but is
    harder
  • //to get used to

10
File/Dir. Manipulation
  • pwd (shows present working directory)
  • ls (lists the files)
  • more (shows the contents of a file)
  • more main.cpp
  • mkdir (makes-creates directories)
  • mkdir hw2
  • cd (changes directory)
  • cd hw2
  • cd C //puts you to your C directory on your
    laptop
  • rmdir (removes-deletes directories)
  • rmdir hw2

11
File/Dir. Manipulation
  • mv (moves-renames files and directories)
  • mv main.cpp hw2
  • mv main.cpp 5315-hw2.cpp
  • rm (removes-deletes files)
  • rm main.cpp
  • ln s (create symbolic link similar to
    shortcut in Windows)
  • ln -s /home2/berrin/texshell tsh
  • //make a symbolic link called tsh to dir
    /home2/berrin/texshell

12
File/Dir. Manipulation cont.
  • find (search for files/directories)
  • find . -name file.doc -print
  • //find a file named file.dc somewhere in this
    directory, searching recursively
  • chmod (change file/dir permissions)
  • clear (clear console)
  • regular expressions /?
  • more .cpp //print all files ending with cpp
  • more hw?.cpp //hw1.cpp, hw2.cpp single character
    wildcard

13
File Content Manipulation
  • All take a filename as parameter
  • cat (concatenate file(s) )
  • cat file1 file2 file2
  • sort (sort file)
  • sort file1
  • head (get N first lines of file)
  • head file1
  • tail (get N last lines of file )
  • tail file1
  • grep (search for pattern in a file )
  • grep include .cpp
  • wc (get word line count of a file)
  • wc file1

14
Pipeline
Redirection Pipelining
  • You can also pipeline multiple commands using
    (pipeline)
  • ps aef grep root more
  • sort data.txt uniq c grep cs204
  • You can redirect the output of commands that
    normally print to the console to a file, using
    gt, lt
  • cat file1 file2 file2 gt result
  • more gt filelist.txt
  • but not more gt grep
  • sort file.txt gt sortedfile.txt
  • etc.

15
archiving
Archiving
  • tar (create archive)
  • tar cvf hw2tar ./ //tar all the files into the
    archive file hw2tar
  • tar xvf hw2tar //extracts file into current
    directory
  • gzip (compress file(s))
  • gzip hw2tar //creates hw2tar.gz
  • gunzip (decompress file(s))
  • gunzip hw2tar.gz //creates hw2tar
  • For all these commands, type
  • man commandname to get to the manual pages

16
Process Manipulation
  • Once you run a program (e.g. vi, myprog,...),
    that program will suspend the terminal you called
    it in (the terminal will not be receiving input
    from you).
  • You can start the program in the background to
    avoid this
  • myprog
  • You can suspend a program that is running and
    send it to background, if you already started it
  • Ctrl-z (to suspend)
  • bg (sends the suspended program to the
    background)
  • ps (show running processes)
  • top (monitor running processes)
  • kill (kill processes)
  • (send process to background)
  • bg (send process to background)
  • fg (get process from background)
  • Ctrlc (terminate process)
  • Ctrlz (suspend process)

17
System Related
  • date (displays system date)
  • time (displays system time)
  • du (displays disk usage)
  • quota (displays users disk quota)

18
Networking
  • who (displays who is in the system)
  • finger (find user info)
  • telnet, ftp
  • pine, mail (email clients)
  • ping (ping the network or computer)
  • hostname (displays computer hostname)
  • talk (talk to someone)
  • su (login as a super user with admin
    privileges)
  • rlogin/login (remote login)


19
Development in UNIX
20
Compiling Programs Under UNIX
  • g -c hw2.cpp -o hw2.o //compile hw2.cpp
    and generate hw2.o
  • g -c image.cpp -o image.o //compile your 2nd
    file
  • g hw2.o image.o -o hw2 //linking stage
    produces the executable
  • Without a -o exec-name, this command will
    produce standard executable named a.out now
    hw2.exe will be created
  • ./hw2 //runs your program hw2.exe
  • If it runs without a problem (see next slides),
    you will see an output as shown in the next slide

21
(No Transcript)
22
Setting the Library Paths
  • ./hw2 //run your program
  • When you run the program, you may have problems
    if the include and library directories are not
    found
  • You need to set some variables just as in setting
    the directory paths in Visual C environment.
  • Shown in the next slide

23
Libraries Not Found
24
Setting the Library Paths
  • To set the variables needed
  • Create a file called .profile in your home
    directory, containing only
  • PATHPATH/usr/local
  • LD_LIBRARY_PATH/usr/local/lib
  • export PATH
  • export LD_LIBRARY_PATH
  • //Your PATH is the PATH to the executables
  • //LD_LIBRARY_PATH is the path to libraries

25
Setting the Library Paths cont.
  • Then, while still in your home directory
  • mkdir hw2
  • cd hw2
  • //create your files
  • bash //Bourne Again SHell.
  • source /.profile // reads the .profile file from
    your home directory
  • // / refers to your home directory
  • //run the executable again
  • The next slide shows my window before and after I
    read the path variables

26
Bash shell
  • Bash is a shell which interprets the user
    commands.
  • When you type bash, you switch to using the bash
    shell, rather than the default.
  • this is indicated with a change in the prompt

27
(No Transcript)
28
Notice how the PATH variable changed
29
System variables
  • In general, you can list an environment variable
    to see what it contains using echo VARNAME
  • HOME (system variable home directory)
  • bash-2.05 echo HOME
  • bash-2.05 home2/berrin
  • PATH (system variable your path to executables)
  • bash-2.05 echo PATH
  • bash-2.05 /usr/bin/usr/local/bin...
  • env (dumps all systems environment variables)

30
Makefiles
31
Makefiles
  • In order not to type in the compilation commands
    each time, UNIX has a utility called Makefile.
  • Advantages
  • Automatically detects what needs to be done
    (compilation etc.), because it knows the
    dependencies in your project
  • every dependency of files to each other stated in
    a makefile
  • e.g. image.cpp depends on image.h
  • e.g. main.cpp depends on image.h and ....h etc.
  • Necessary steps to create a target (object or
    executable) are specified
  • You do not need to enter g -c image.cpp o
    ... one by one

32
Makefile Syntax
  • MACRO DEFINITIONS
  • target dependent dependent dependent
  • command
  • command

33
Make files
34
Make files
35
Make files dependencies shown
36
Make files
If io.c has changed,only io.o will be generated
and linking will be re-done. The rest wont be
touched.
37
Make files
38
Sample make file
39
Make Rules/Conventions
Compilation/Makefile
  • If you type make, it will try to make the first
    target (hw1 in the prev. slide)
  • it will first check the dependencies of hw1
  • make those targets first, then execute the
    command to make hw1
  • If you type make clean
  • it will check its targets (nothing)
  • execute the command to make clean (rm hw1 .o
    core)
  • If you type make clean
  • it will check its targets (nothing)
  • execute the command to install the program in
    your home/bin directory (cp hw1 HOME/bin)
  • - Others (predefined or customary)
  • make all makes all targets
  • make install see prev. slide used for
    installation


40
Special Macros
Compilation/Makefile
  • _at_ is the name of the file to be made.
  • ? is the names of the changed dependents.
  • lt the name of the related file that caused the
    action.
  • So, for example, we could use a rule
  • printenv printenv.c
  • (CC) (CFLAGS) ? (LDFLAGS) -o _at_
  • printenv printenv.c
  • (CC) (CFLAGS) _at_.c (LDFLAGS) -o _at_


41
Compilation/Makefile
More information at http//vertigo.hsrl.rutgers.e
du/ug/make_help.html Slightly edited/highlighted
form is in How-to-Write-Makefile.doc under
lectures.
42
debugging
43
Debugging in Unix
  • You can use one of the following debuggers
  • gdb (command window version)
  • xxgdb (GUI version) or
  • ddd (GUI, and probably easier to use than xxgdb)
  • You should be able to
  • set breakpoints
  • single step or go to next break
  • display variables
  • ...

44
Debugging in Unix gdb
45
  • Ex
  • gtxxgdb hw1
  • Brings up hw1.cpp in the main window
  • -Put a break point by clicking on a line
  • hitting the Break button
  • - Run the program by typing
  • (xxgdb) run
  • For hw3, xxgdb window after these
  • commands are shown in the slide

46
(No Transcript)
47
scripting
  • You may skip the rest

48
Shell Scripting
The shell is a command interpreter. More than
just the insulating layer between the operating
system kernel and the user, it's also a fairly
powerful programming language.
49
Shell Scripting
You are able to define almost any kind of
complicated statements you get used in
programming with other languages.
50
Shell Scriptingfor bash
  • for, if, while, parameter passing, interaction
    with user,
  • interrupt handling, etc

for planet in Mercury Venus Earth Mars Jupiter
Saturn Uranus Neptune Pluto   do echo
planet done for files in do echo
files done
You may use awk or sed or perl or some other
scripting language for shell programming each
of these languages is somewhat more suitable for
certain jobs (sed for quick replacement of text
strings, while awk and perl are capable of
counting lines and doing replacements accordingly.
51
Shell Scripting
52
Shell Scripting
  • Very good reference
  • http//www.tldp.org/LDP/abs/html/
Write a Comment
User Comments (0)
About PowerShow.com