Learning Linux v2.1

26
Learning Linux – Part 2 CentOS 6.2

Transcript of Learning Linux v2.1

Page 1: Learning Linux v2.1

Learning Linux – Part 2

CentOS 6.2

Page 2: Learning Linux v2.1

Topics• Command-Line Basics

• Permissions

• Using the man Command

• Hard and Soft Links

• Network settings

• Creating RPMs

• Repositories and working with YUM

• Kernel Modes

• Resizing Partitions

Page 3: Learning Linux v2.1

Command-line Interfaces

Ctrl + Alt + <F2 - F6> (multiple logins simultaneously)

Page 4: Learning Linux v2.1

Navigating Files and Directories

man <command> manuals lists information about the commandls list lists all non-hidden contents of a directorycd <directory> change directory moves into a directory located within

current directorycat <file> concatenate files print file contents to screencp <file1> <file2> copy creates a new file2 with file1 contents

rm <file name> remove removes the filemv <file1> <new filename> move renames file1mv <file1> <location> move moves file1 to a new locationcd .. change directory moves up a foldermkdir <new directory name> make directory makes a new directorypwd print working directory lists pathname of the current directorycd ~<username> change directory move into the home directory of user

cd <directory path> change directory moves into the directoryrm -r <directory name> remove recursively removes a directory and its contents

Page 5: Learning Linux v2.1

Tar Archiving and Gzip Compression

Archiving - grouping multiple files together in a single file to save space and make it easier to transfer the files around Compressing - replacing a single file with a smaller/compressed version to save space

Tar - a type of archiver most common to Linux Gzip - a type compressor most common to Linux

To extract .tar.gz files:    tar -xvzf <filename>        tar -xvzf example.tar.gzTo create a new .tar.gz file:        tar -cpzf <filename> <foldername>              tar -cpzf newArchive.tar.gz images

Page 6: Learning Linux v2.1

Users and Groups

Command Definition Purpose

su substitute user

Similar to logging into your computer as administrator

useradd  <username> user add adds a new user

passwd <username> password changes or creates new password

groupadd <groupname> group add creates new group

usermod  <options> <username>

user modify modifies the user

Ex. adding user to group

userdel  <username> user delete deletes a user

groupdel  <groupname> group delete deletes a group

Page 7: Learning Linux v2.1

Permissions Format

• A permission has a total of 10 characters.• There are no empty spaces

ugoPermission Formatu - user/ownerg - users of the owning groupo - any other user

Page 8: Learning Linux v2.1

Permissions Characters

Identifier categories• -     file identifier• d directory identifier

 rwx categories• r     read (able to open/view files as well as view contents of folders)

• w write (able to edit/rename/save files and folders)

• x execute (able to run a program)

• -     place holder (does not have the privilege)

Page 9: Learning Linux v2.1

Permissions Commands• Changing permissions can be done with the command chmod in the terminal

 

 • chmod can be used with multiple modifiers

Command Definition Purpose

ls -lh list lists a long humanly readable list of all files

chmod <u,g,o> <+,-,=> <r,w,x> change mode changes permissions of files

Modifier Purpose

+ adds to current permissions

- takes away from current permissions

= erases previous permissions and sets new ones

Page 10: Learning Linux v2.1

Permissions

• You can set who can access specific files by changing user and group owner

• The superuser (root) has full access and can change any

permission, even for files that don't belong to the root account.

 Command Definition Purpose

chown <username> <filename> change owner changes the owner of a file

chgrp <groupname> <filename> change group changes the group owner of a file

Page 11: Learning Linux v2.1

The man command

• The Linux man pages are the most helpful tool to the for the test.

• The above is a manual page for the ls command

Page 12: Learning Linux v2.1

Strategies and Use• The manual pages are organized in the order:

– Name, Synopsis, Description, and Options

• The options are organized into subcategories:

– User Commands, System Calls, C Library Functions, Devices and Special Files, File Formats and Conventions, Games, Miscellanea, System Administration.

• If you know what you are looking for and where to look it saves a lot of time

• Syntax for the command is as follows:

man <command> <options>

man –k <something> | less    

Page 13: Learning Linux v2.1

Strategies and Use

• Once you are in a man page, there are other ways to help narrow down what you are looking for.

• By typing /<search parameter> and hitting Enter, you can search for key words within the manual. Sequentially typing / and hitting Enter bring up the next occurrences of your search.

Page 14: Learning Linux v2.1

Strategies and Use

• When searching, pressing the space bar will take you down one page and help ensure you don’t miss anything

• To close a manual page, type q or hit ctrl-c which is the stop current command hot key

• One other method for finding the correct command is through /sbin where all the executable commands are stored. Scrolling through the list with | less can help jog a person’s memory

Page 15: Learning Linux v2.1

Hard and Soft Links

• Every file has two parts, a data structure and file name structure.

• The data structure is associated with an inode.• The file structure is the name and the associated

inode number that references where the data is stored.

• A hard link refers to more than one file with the same inode number.

• A soft link is a reference to another file or directory with a different inode number than the original file.

Page 16: Learning Linux v2.1

Hard and Soft Links

• ls –lia Shows inode numbers of files

Create hard links• ln <source-filename> <link-filename>

Create soft Links• ln –s <source-filename> <link-filename>

Page 17: Learning Linux v2.1

Network Settings

To display the current network settings, use the command: ifconfig

This will list all the different interfaces. Choose the one you want and use the command:

ifconfig <interface> <ip address> netmask <netmask> up

To set the default connection, use the commandroute add default gw <default gateway>

To set the DNS, modify the /etc/resolv.conf with the vi or grep text editor.

It should resemble nameserver <DNS Address>

To configure network with DHCP, run the command dhclient –r which will release the current client. After run dhclient to obtain a new IP.

Page 18: Learning Linux v2.1

Creating RPMs

RPM is the package management system used by Red Hat Enterprise Linux and many other Linux distributions.

Basic Usage:$ rpm -ivh demofile-1.0.0-i386.rpmi for install, v for verbose, h for process hash

$ rpm -ql demofileq for query, l for list files

$ rpm -e demofilee for erase

Setup:$ mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}$ mkdir -p ~/rpmbuild/RPMS/{noarch,i386,i686}

Page 19: Learning Linux v2.1

YUM Repositories

Yellowdog Updater ModifiedPackage manager for .rpm files that allows the installation of new packages, removal of old packages, and automatic system updates

yum install <application>    yum install nanoyum update <application>    yum update flash-pluginyum update (no other parameters)yum remove <application>    yum remove vimyum list

Page 20: Learning Linux v2.1

Kernel Modes

• Within every Linux operating system there are the six basic runlevels.

• The runlevel is the state of the machine after boot.• A typical computer boots into runlevel 5. This

usually contains a GUI and networking.

Page 21: Learning Linux v2.1

Kernel Modes

• These runlevels can be accessed in three main ways – With the init command – Modifying the /etc/inittab file that controls what

the computer boots into– Changing command sent by the GRUB

Bootloader

**Note when running init command or modifying innitab file, you need root privileges.**

Page 22: Learning Linux v2.1

Kernel Modes

• When you start up a computer, press any key to load the grub menu when the loading screen appears

• It will then take you to the GRUB menu

• Once in the menu, you can scroll up and down to chose which version of Linux you would like to load.

Page 23: Learning Linux v2.1

Kernel Modes

• You also have the option to open the grub command line when you press c.

• To modify boot command, press e.

• To change the runlevel the computer boots into, add a space at the end of the command and type the runlevel code (1-6) and hit Enter

• Once loaded into one of the runlevels you can modify the root password with passwd

• To change runlevels after loading into a runlevel, use init <runlevel id #> (Root only).

Page 24: Learning Linux v2.1

Kernel Modes

• How is this secure?• You can establish a GRUB menu password with

the command grub-md5-crypt, but this has its drawbacks.– If you forget GRUB password, you may need to

backup your computer and reinstall the operating system through the BIOS and wipe the hard drive.

Page 25: Learning Linux v2.1

Summary• Command-Line Basics

• Permissions

• Using the man Command

• Hard and Soft Links

• Network settings

• Creating RPMs

• Repositories and working with YUM

• Kernel Modes

• Resizing Partitions

Page 26: Learning Linux v2.1

Questions?