61772211-2011-w1-linuxshell

Upload: saravanaraajaa

Post on 02-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 61772211-2011-W1-LinuxShell

    1/33

    LINUX SHELLCOMPSYS202 / MECHENG270

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    2/33

    Contents

    Where can I get Linux?

    Where can I get help with Linux?

    What is the Linux shell ?

    How do I use the Linux shell ?

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    3/33

    Where Linux?

    Linux is installed in most SE, CS, ECE, andEngineering Faculty labs. You generally need to rebootand choose Linux from a boot menu.

    Linux is Free/Open Source software, so you canlega!y

    copy it from friends and install it at home.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    4/33

    Where Linux?

    You can download Linux for free, or you can buy it.

    http://www.ubuntulinux.org/

    Dick Smith Electronics sells CDs.

    There are CD images available on the UofA network ifyouwant to burn a CD.

    Wednesday, 20 July 2011

    http://www.ubuntulinux.org/http://www.ubuntulinux.org/http://www.ubuntulinux.org/
  • 7/27/2019 61772211-2011-W1-LinuxShell

    5/33

    Linux Help?

    We will be covering Linux usage in some lectures.

    TAs are available to help in labs.

    Reference guides and documentation will be made

    available via. Cecil.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    6/33

    Linux Help?

    There is avast collection of information on the

    Internet.

    http://www.linux.org/

    http://www.ubuntulinux.org/

    http://www.wikipedia.com/

    Wednesday, 20 July 2011

    http://www.wikipedia.com/http://www.ubuntulinux.org/http://www.linux.org/http://www.wikipedia.com/http://www.wikipedia.com/http://www.ubuntulinux.org/http://www.ubuntulinux.org/http://www.linux.org/http://www.linux.org/
  • 7/27/2019 61772211-2011-W1-LinuxShell

    7/33

    Which Linux

    There are many flavours of Linux available. eg.

    Redhat, Ubuntu, Fedora, Gentoo.

    We will be using Ubuntu Linux

    When searching the Internet, make sure you find

    recent help. Articles from 1996 may not be relevantnow, for example.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    8/33

    Remember

    command options arguments

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    9/33

    File Tree

    ccog001

    Desktop example

    example.jpg example.c

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    10/33

    File Naming

    Linux is case sensitive.

    This means that:

    he!o.jpgis NOT the same file asHELLO.JPG

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    11/33

    File Naming

    Filenames can contain spaces, but this is awkward for

    the command line.

    For now, dont put spaces in filenames.

    You can use underscores if you want.

    eg. My_simple_program.cpp

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    12/33

    Working Directory

    Every program running is in a specific directory- the

    current directory

    This is the place it looks for files, or will save files to, bydefault.

    We can move a program to a different directory.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    13/33

    Starting Directory

    When we first log in, our desktop (file manager) will bein our Desktop directory.

    If we start a terminal from the menu, it will be in our

    HOME directory.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    14/33

    Navigation

    cd

    change directory

    Navigate to other locations in the filesystem

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    15/33

    pwd

    pwdprint working directory

    Shows the name of the folder that the terminal is

    currently in.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    16/33

    ls

    ls

    list - Show files in the current directory.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    17/33

    mv

    mv

    move files.

    This will move a file to a different location.

    It can also rename files.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    18/33

    cp

    cp

    copy files.

    Make a copy of files.

    eg. cp labex1.c labex1.c.backup

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    19/33

    echo

    echo

    echo some text back to us

    This will display some text to the output.

    eg. echo hello there

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    20/33

    cat

    cat

    catalog - Reads a file and sends it to output.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    21/33

    more

    moreshow us more of a file.

    This will read a file and display it to our terminal, but

    will pause once it fills the screen until we press space.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    22/33

    cut

    cutTakes the input text and, for each line, removes someof it.

    eg. ls -l | cut -c29-34

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    23/33

    Combining Commands

    in UNIX systems, most commands are considered tobe building blocks. You use them to construct moresophisticated operations.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    24/33

    Pipe

    |takes the output from one command and feeds it intothe next.

    ls | more

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    25/33

    Backticks

    `

    If we put a command inside backticks ``, the shell willrun that command first, thenreplacethe `` part withthe output of that command.

    echo My working dir is `pwd`

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    26/33

    More Backticks

    We can put multiple commands inside backticks:

    echo The largest file is `ls -l | sort -n -k 5 | tail -1 | cut -c54-`

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    27/33

    Sequencing

    Like many programming languages, we can specify asequence of commands, separated by the ; character.

    echo my files: ; ls

    The second command wont start until the first finishes

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    28/33

    Typing Shortcuts

    The shell contains features to help us with our typing.

    We can use the arrow keys to go back through previouscommands.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    29/33

    Auto Completion

    The shell can try and work out what we meant bywhat weve typed so far.

    If it can, it will complete as much as it can for you.

    Press to do this.

    Press twice and the shell will suggest what

    matches so far.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    30/33

    Build Your Own

    Except for a very few built-in commands, all shell

    commands are just programs.

    You can write your own.

    Most common ones included on the system are in the /

    usr/bin directory.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    31/33

    Explore

    Have a look around the system, find new commands,figure out what they do.

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    32/33

    Compiling

    Linux comes with a C/C++ compiler, called GCC.

    GCC is a free software compiler and is very crossplatform. see: http://www.gnu.org/

    We can call it from the UNIX shell using the g++command.

    g++ -o targetsource.cpp

    Wednesday, 20 July 2011

  • 7/27/2019 61772211-2011-W1-LinuxShell

    33/33

    Running programs

    To run a program we must type its name.

    The shell will search our path for a program with

    that name, and if it finds it, it will run it.echo $PATH

    our home directory is not by default in the path,

    so we have to specify where the program is../myprogram