LPI 101 Ch05 Linux Usage

  • View
    224

  • Download
    0

Embed Size (px)

Text of LPI 101 Ch05 Linux Usage

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    1/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Chapter 5

    Linux Usage

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    2/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Objectives

    Define command line basic procedures

    List common commands

    Describe and use the commands su and

    sudo

    Describe and perform basic file system

    tasks

    Describe the Linux file system, its

    structure, and directory hierarchy

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    3/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Objectives

    Locate commands and files

    Identify Linux text editors ( e.g vi )

    Describe and use the Linux shell (e.g

    bash) environments

    Describe and use text processing tools

    and filters

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    4/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Command Line Basic Syntax

    Usually, there are three components in

    command line syntax :

    : whatthe system will do : or , how the command

    will do

    : where the command will apply to

    Sometimes you won't need option or

    argument, depending on the command

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    5/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Command Line Examples

    For example:

    $ date (Command)

    $ date +%d%m%y (Command and argument)

    $ cal 12 2000 (Command and two

    arguments)

    $ uname -a (Command and option)

    $ uname -rpns (Command and

    multiple options)

    $ uname -r -p -n -s (Command andmultiple

    options

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    6/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    COMMON COMMANDS

    Command line utilities are an extremely

    powerful way to complete day-to-day

    activities, you should be familiar with it

    Remember : Linux (Unix) is case-sensitive,ls , LS are different commands

    More information about a command can be

    found using manual pages.

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    7/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    COMMON COMMANDS

    pwd

    cd

    ls

    cp

    mv

    rm

    find

    more

    grep

    file

    Displays the current working directory

    Change working directory

    List contents of directories

    Copy files and directories

    Move or rename files

    Remove (delete) files or directories

    Search for files in a directory hierarchy

    Displays a file one page at a time

    Print lines matching a pattern

    Determine file type

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    8/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    su And sudo

    Working as rootcan be risky business, it is

    usually better to work as the root user on a

    temporary basis

    su c command :This will perform thecommand with root permission and then

    return to the normal user shell. You will be

    prompted for the root password before the

    command is executed sudo: This command allows user (as

    specified in the /etc/sudoers file) to

    execute some root commands

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    9/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    FILE SYSTEM BASICS

    File systems are used to store files in an

    organized structure

    A file system keeps track ofwhere things are

    and how large the files within it are, who ownsthem and whatpermissions are assigned to

    them

    It is important to have an understanding of

    how to navigate it and how to create, move,copyand remove files as a user

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    10/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    The Linux File System

    During installation, a file system will be

    created on the Linux partitions. The preferred

    Linux file system is called ext3, it has all the

    functionality ofext2, but with the addition of

    journaling

    Linux supports more than thirty types of file

    systems : ext2, ext3, vfat, msdos, NTFS,

    iso9660, NFS, ReiserFS, XFS,

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    11/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    File System Structure

    Linux file systems have the following structuralparts: thesuperblock, data blocks, and the inodes

    The superblock contains information about the

    whole file system

    The data block are a segment of disk space inwhich the file contents is stored

    An inode number is assigned to each file that is

    created. This is the number that the file system

    uses to refer to the file. An inode itself contains allinformation about a file except its name. The

    names of files are kept in directories , which are

    just special files containing a table with file names

    and their inodes

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    12/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Directory Hierarchy

    The Linux file system hierarchy has a tree of

    directories. The tree starts with the "root"

    directory, "/"; from here the tree branches out

    into sub-directories and sub-sub-directories;

    files are located inside some directories (like a

    leaf at the end of a branch)

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    13/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Directory Hierarchy

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    14/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    File System OrganizationExample

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    15/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Path Names

    Uniquely identify a particular file ordirectory by specifying its location in thedirectory tree.

    The slashes (/) within a path name aredelimiters between object names.

    The first slash in a path name always

    represents the root (/) directory.

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    16/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Path Names

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    17/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Absolute Path Name

    An absolute path name specifies a file ordirectory in relation to the entire directorytree

    Absolute path names always:

    - Start at the root (/) directory, and then listeach

    directory along the path to the finaldestination

    - Use a slash (/) to separate multiple directoryor file names

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    18/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Relative Path Name

    A relative path name describes the locationof a directory or file as it relates to thecurrent directory

    Relative path names:- Never begin with a slash (/) character

    - Use slashes (/) within the path name asdelimiters between object names

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    19/67

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    20/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Pathname Abbreviations

    . Current (working) directory

    .. Parent directory; the directory

    directly above the current directory

    ~ Users home directory

    ~- The full path to the previous

    working directory

    ~logname The home directory of the user

    specified by logname.

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    21/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Changing Directories

    When you initially log in to the system, thecurrent directory is set to your homedirectory. Change your current workingdirectory at any time by using the cd

    command.

    Command format:

    cd directory_name

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    22/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Displaying the Current Directory

    Use the pwd command to identify in which

    directory you are currently working.

    The pwd command displays the absolute path

    name of the current working directory.

    Command format: pwd

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    23/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Displaying the Contents of a Directory

    Use the ls command to list the files and

    directories within the specified directory.

    Using the ls command with no argument

    displays the contents of the current directory.

    Command format:

    ls [- options]pathname...

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    24/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Some ls Command Options

    -a: List all entries, including those beginningwith a dot (hidden files, except ., ..)

    -A: Same as -a excluding . and ..

    -d: If argument is a directory, then do not

    list the contents of that directory-l: List in a long format

    -F : Display file type ( /, *, @ )

    -R: Recursively list the contents of all subdirs.

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    25/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Creating Directories

    Use themkdir command to createdirectories

    Command format:

    mkdir directory_name...

    mkdir [-p] directory_name...

  • 8/9/2019 LPI 101 Ch05 Linux Usage

    26/67

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102