Introduction to the Linux Environment - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to the Linux Environment

Description:

With linux you can tie the output of one program into the input of another program with the pipe operator. This is incredibly handy and will be used a ... – PowerPoint PPT presentation

Number of Views:118
Avg rating:3.0/5.0
Slides: 44
Provided by: bria4329
Category:

less

Transcript and Presenter's Notes

Title: Introduction to the Linux Environment


1
Introduction to the Linux Environment
  • Brian E. Brzezicki

2
First things first
  • Log in to your linux machine using
  • Username student
  • Password student01

3
Terminal!
  • Next Linux is VERY text based environment, so
    lets get used to the Terminal!
  • Click on Applications-gtAccessories-gtTerminal
    until you get this! (next slide)

4
Terminal
5
Terminal
  • Go ahead and close it (click on the x in the
    windows top bar) and open it again you need to
    get comfortable with the terminal window!

6
Basics of the Linux File System structure
7
File System Layout
  • Linux is layed out in a heirarchical manner
    starting from the root ( / ) directory. This is
    similar to MS Windows except that
  • Linix uses the / as a directory seperator,
    Windows uses a \
  • Windows has multiple roots one for each drive
    (C, D etc). Linux has a single root, separate
    physical drives are grafted onto the tree
  • (see image)

8
Linux File System
9
Entering Commands
  • When Entering commands in Linux, most commands
    take a filename as an option. You can specify a
    filename as a
  • Full path Example
  • cat /etc/passwd
  • Relative to your current directory
  • cd /etc
  • cat passwd

10
Special Relative directories
  • There are special entries for directories in
    linux
  • . this directory
  • .. back one directory
  • If I was in the directory /etc/sysconfig, I could
    read the file /etc/passwd with the following
    command
  • cat /etc/passwd
  • Or
  • cat ../passwd

11
Lets look around
  • Open up your terminal windows now and lets look
    at some programs used to navigate the filesystem
    in unix

12
File System Commands
  • cd change directory
  • pwd print working directory
  • In your terminal type
  • cd /usr/local
  • Now type
  • pwd
  • What is the response?

13
File System Commands
  • Now type
  • cd . .
  • and
  • pwd
  • Now what is the response?
  • .. is a useful argument to cd that moves you
    back 1 directory level.

14
File System Commands
  • You can add multiple .. together
  • For example. Lets get back to /usr/local
  • Use the command
  • cd /usr/local
  • Type
  • pwd
  • To verify your in /usr/local
  • What do you think will happen if I type
  • cd ../..
  • And type pwd?

15
File System Commands
  • Right Ill be back at the root directory! (/)
  • Now before we used to get to /usr/local by
    directly typing the whole path. This is called an
    absolute path. Because we specified the exact
    location that we want to go on the system.
  • But we can also move around using relative paths.
  • For example, lets move back to the root
    directory (/)
  • Type
  • cd /
  • And verify with
  • pwd

16
File System Commands
  • So now that we are at / lets use relative
    addressing to get to /usr/local
  • We are going to specific paths relative to where
    we are
  • Type
  • cd usr
  • And
  • pwd
  • Where are we now?

17
File System Commands
  • Now lets move into local
  • Type
  • cd local
  • And
  • pwd
  • Where are we now?
  • Lets start again and do it in only one step

18
File System Commands
  • Type
  • cd /
  • And
  • pwd
  • We are back at root (/)
  • Type
  • cd usr/local
  • And
  • pwd
  • We are back at /usr/local

19
File System Commands
  • OK now that we can move around lets learn
    another important linux command
  • ls list directory contents
  • cd /usr/local
  • ls
  • What is the response?

20
File System Commands
  • How about
  • ls l
  • (next page for results explain the entries)

21
  • root_at_linux1 local ls -l
  • total 72
  • drwxr-xr-x 2 root root 4096 Mar 9 2009 bin
  • drwxr-xr-x 2 root root 4096 Mar 9 2009 etc
  • drwxr-xr-x 2 root root 4096 Mar 9 2009 games
  • drwxr-xr-x 2 root root 4096 Mar 9 2009 include
  • drwxr-xr-x 2 root root 4096 Mar 9 2009 lib
  • drwxr-xr-x 2 root root 4096 Mar 9 2009 libexec
  • drwxr-xr-x 2 root root 4096 Mar 9 2009 sbin
  • drwxr-xr-x 4 root root 4096 Apr 18 1403 share
  • drwxr-xr-x 2 root root 4096 Mar 9 2009 src

22
Useful ls options
  • ls l long listing
  • ls la long listing, how hidden files
    (file starting with .)
  • ls lh long listing with easy to read file
    sizes
  • ls lt long listing sorted by time and date,
    most recent first
  • ls ltr long listing, sorted by time
    (reverse)

23
Using ls
  • Do a quick exercise
  • cd /home
  • pwd
  • ls
  • cd student
  • pwd
  • ls -latr

24
File System Commands
  • To effectively run Linux you have to have a solid
    grasp on the filesystem structure and the
    commands to move around.
  • Get used to CD, PWD and LS

25
More useful Commands (set 2)
  • rm remove file
  • rm rf remove directory and everything
    in that directory recursively
  • rmdir remove empty directory
  • mkdir make directory
  • cp copy a file
  • mv move a file

26
More Useful Commands (set 3)
  • cat show the contents of a file
  • more show the contents of a file
  • tail show the last lines of a file
  • tail -10 shows the last 10 lines of a file
  • tail -f shows as lines are added to a file
  • echo displays whatever you type

27
More useful commands (set 4)
  • chmod change file permissions
  • chmod username filename
  • example
  • chmod student /tmp/file
  • chown change file owner
  • chown urwx,grwx,orwx filename
  • u-rwx,g-rwx,o-rwx

28
Example of chmod
  • cd /tmp
  • touch file
  • ls l file
  • -rw-r--r-- 1 root root 0 Apr 21 1541 file
  • chmod ux,gx,o-r file
  • ls l file
  • -rwxr-x--- 1 root root 0 Apr 21 1541 file
  • chmod urwx,grwx,orwx file
  • ls l file
  • -rwxrwxrwx 1 root root 0 Apr 21 1541 file

29
More useful commands (set 5)
  • grep search a file for a specific line of text
  • grep root /etc/passwd
  • root_at_linux1 grep root /etc/passwd
  • rootx00root/root/bin/bash
  • operatorx110operator/root/sbin/nologin
  • locate search the system for a specific filename
  • locate ssh_config
  • root_at_linux1 locate ssh_config
  • /etc/ssh/ssh_config
  • /usr/share/man/man5/ssh_config.5.gz

30
The PIPE operator ()
  • When working with unix, you notice one command
    usually gives you output.
  • With linux you can tie the output of one
    program into the input of another program with
    the pipe operator. This is incredibly handy and
    will be used a lot in your linux administration
    tasks.
  • cat /etc/passwd grep root
  • root_at_linux1 cat /etc/passwd grep root
  • rootx00root/root/bin/bash
  • operatorx110operator/root/sbin/nologin

31
Redirect operators
  • Like with PIPE in Linux you can redirect the
    output of one command to a file (gt), or redirect
    the contents of a file to be the input of a
    program (lt)
  • Example
  • grep root /etc/passwd gt /tmp/grep_results.txt
  • or
  • grep root lt /etc/passwd

32
Process operators
  • Often in Linux you will want to see what
    processes are running and possibly manipulate
    them you do this will the commands
  • ps
  • ps ef
  • kill
  • kill -9 pid
  • kill TERM pid

33
su
  • In unix you generally log in as a user account
    rather than the superuser account
  • su is a command that lets you switch to a
    different user and run commands as them
  • su root
  • su - student

34
vi
  • Linux adminstration is very much about text
    configuration files. When you have a GUI you can
    edit these files with a normal editor however if
    you want to run Linux you better get used to a
    text editor. Id suggest vi
  • So lets look at vi in the next couple slides

35
vi
  • First lets copy a file that we can edit
  • cp /usr/share/dict/words /tmp/words.txt
  • Now lets open this with vi
  • vi /tmp/words.txt

36
vi
  • Now that we are in vi you should understand vi
    has 2 modes.
  • Movement mode
  • Edit mode
  • When you start you are put into movement mode, an
    you can move the cursor around using the commands
    (next page)

37
Vi movement mode
  • j up a line
  • k down a line
  • h left 1 character
  • l right one character
  • Use these characters to move around!
  • Note you can specify a number before the command
    for example
  • 5j would move you down 5 lines

38
vi movement mode
  • You also can go to a certain line number with the
    command
  • XX
  • Where XX is a line number
  • Example
  • Typing
  • 50 would take me to line 50

39
vi edit mode
  • Once we are were we want to type or delete in the
    file we can use edit mode commands.
  • Some edit mode commands
  • x delete the current characterk
  • dd delete the entire current line
  • You can add a number before either of these
    commands to do that command multiple times

40
Typing in characters
  • So now that we know the basics of deleting
    characters how about adding characters?
  • To do so, we enter insert mode by typing
  • i enter insert mode
  • Typing I will let you start entering characters
    that will go to the left of the current
    character.
  • Once in insert mode type away when your done hit
    the Esc button

41
Saving the file
  • When you want to save the file make sure your in
    normal mode (usually hit esc) then hit
  • w save the file but remain open for editing
  • wq save the file and quit
  • There are tons more vi commands, but these are
    the basics and should provide you with all that
    you need to do your work. I myself only know a
    few more than this as these commands make up 95
    of anything youll want to do.

42
man pages
  • Linux is much different than windows is that the
    documentation (useful documentation) for each
    command is stored on the system and available
    with man pages.
  • To view the documentation for a command type
  • man command
  • Example
  • man ls
  • You can even do a man on the man pages
  • man man
  • You will learn to love the man pages!

43
Labs! Lets get some hands on practice now!
Write a Comment
User Comments (0)
About PowerShow.com