Sei sulla pagina 1di 43

Welcome!

RH033
Red Hat Linux Essentials

Objectives

Day 2

File Editing using vi editor Advanced usage of vi editor Users and Groups Management Understanding Permissions Linux File system Inodes Links Mounting Media Archives Compression Using GUI shells ( GNOME & KDE)
2

Using Linux File editing tool

Basic File editing vi editor


vi - the basic text editor three modes

Command mode <= default startup Insert mode ex mode

vi networknuts

<= a typical example

Enter insert mode <i> and <CR> Enter <ESC> return to command mode Navigate the cursor h move cursor left j moves cursor down k moves cursor up l moves cursor right

Advanced Uses of the editor


Position the cursor across a file or within a screen Insert into the file the output of a linux command Search for text and replace it Learn advanced reading and saving commands Configure vi and vim

Commands
G = go to last line in file 1G = go to first line in file H = go to first line on screen M = go to middle line on screen L = go to last line on screen z<Enter> = make current line first line on screen z= make current line last line on screen !!date = Inserts the current date and time in to file !}sort = Sorts the data of your file !}fmt -66 = formats the data of your file in to 66 column width Ex mode : Search and Replace command :%s/big/small :%s/big/small/g

Advanced Reading and Saving


:r newfile = writes data from other file to current file :r !date = writes date to your file :1,5w xnewfile = writes line 1 to 5 to new file xnewfile :.,$w ynewfile = writes from current line to end in to new file ynewfile :1,5w >> xfile = append xfile with line 1 to 5 :n = changes to next file :n! = abandoning changes :n# = jump to the previous file :set showmatch = shows the match :set textwidth=65 = sets the text width to 65 character :set number = sets the line numbers ( Note : You can use no with set command to unset changes you made ) Ex. :set nonumber = will remove line numbers

Users and Groups Management

What is User Account ?


When a computer is used by many people it is usually necessary to differentiate between the users, for example, so that their private files can be kept private. This is important even if the computer can only be used by a single person at a time, as with most computers. Thus, each user is given a unique username, and that name is used to log in.

What is Group ?
Is a collection of users which make easy for administrators to perform the task of administration level when they need to apply permissions and restrictions with same level to many of the users, then such permission and restrictions can be applied to related group.

10

The root user


The root user: a special administrative account Same like Administrator we called in Win* Sometimes called the superuser root has complete control over the system An unlimited capacity to damage the system!

11

Creating Users
useradd options user - Creates a new user. -c Assigns full name to user. -d Uses to define home folders location. -s Uses to define user's shell. (Use /sbin/nologin for users you wish to restrict from having shell access). -g Add user to group ( Primary Group ) -G Add user to group ( Secondary Group ) usermod options user - Modifies user account Same options as useradd. userdel options user - Deletes user account. -r : Remove user's home directory. passwd user - Changes the password of the specified user. If no user is specified, will change the password of the current user.

12

Creating Groups
groupadd group - Creates a group. groupmod options group - Modifies a group.

-n : Rename group

groupdel group - Deletes the specified group.

13

Configuration Files
/etc/passwd /etc/shadow /etc/group /etc/gshadow = = = = file contains user database file contains user password database file contains group database file contains group password database

14

User Information Commands


Find out who you are whoami Find out what groups you belong to groups, id Find out who is logged in users, who, w Login/reboot history last

15

User and Group ID Numbers


User names map to user ID numbers Group names map to group ID number Data stored on the hard disk is stored numerically

16

Understanding Permissions

17

What is Permission ?
Specifies what rights are you granting to users to access the resources are available in the computer, so that important resources such as files are protected from unauthorized users.

18

Methods of Implementing Permissions


Symbolic Method Numeric Method

19

Permissions- Symbolic Method


Four symbols are used when displaying and applying permissions

r w x -

Permission to read a file or list a directorys contents Permission to write to a file or create and remove files from a directory Permission to execute a program or change into a directory and do a long listing of the directory no permission ( in place of the r, w, or x )

20

Applying Permission with Symbolic Method


chmod command is used to change access modes Symbolic Method

chmod u+w,go-w somefile file name ( Grants write access to owner but denies it to group and other. ) chmod u=rw somefile file name ( Sets read and write permission to owner, with execute turned off, regardless of the current permission ) chmod +r somefile file name ( Make the file world-readable )

[ Note : +, - and = are operators to add, remove or overwrite the permission ]

21

Permissions- Numeric Method


Four numbers are used when displaying or applying permissions

4 2 1 0

Permission to read a file or list a directorys contents Permission to write to a file or create and remove files from a directory Permission to execute a program or change into a directory and do a long listing of the directory no permission ( in place of the 4, 2, or 1 )

22

Applying Permission with Numeric Method


chmod command is used to change access modes Numeric Method

chmod 664 somefile file name ( Grants Read and Write access to owner and group but read only it to and other. )
chmod 600 somefile file name ( Sets read and write permission to owner, with execute turned off, with others and group have no permissions ) chmod 444 somefile file name ( Make the file world-readable )

23

24

Permissions
r w x r Owner has read Owner has write Owner has execute Group has read Group does not have write

x
r x

Group has execute


Others have read Others do not have write Others have execute

25

Understanding File System

26

Partition and File System


Disk drives are divided into partitions Partition are formatted with file system, allows users to store data Default file system: ext3, the Third Extended Linux File System Other common file systems: ext2 and vfat iso9660 ( typically used for CDs)

27

Inodes
An inode table contains a list of all files in an ext2 or ext3 file system Directories have inode numbers associated with files. inodes contain information about the file or directory, including:

Owner, group, permissions, size, location on disk, file type (file or directory)

One inode is associated with each file. The system uses inodes as the definition of a file. The ls -il command displays the inode number:

80977 drwxr-x--- 1 user user

4096 Mar 19 11:23

28

Links
A link is a file that points to another file. ln creates a link from the original file to a new file in your directory. Most programs will access the link as if it was the file. This is similar to a shortcut in Windows. This allows for aliasing (when two or more names can exist for the same object) Easy way to point to a really long absolute pathname or filename

29

Using Links
Two types of links can be created Symbolic ( Soft ) Hard

ln -s main soft ( This will create an soft link of file main )


ln main hard ( This will create an hard link of file main )

30

Mounting the media


Mounting means making a partition to access from an access point typically a folder to store and access data from it. Commands to mount media mount /media/floppy mount /media/cdrom mount /media/Device ID = = = Mounts floppy drive to your computer Mounts cdrom drive to your computer Mounts usb disk to your computer

Commands to unmount media umount /media/floppy = umount /media/cdrom = umount /media/Device ID = Unmounts floppy drive to your computer Unmounts cdrom drive to your computer Unmounts usb disk to your computer

31

Archive Files
Archiving places many files into one target file Easier to back up, store, and transfer tar Standard Linux archiving command

32

Using Archive files tar command


tar cvf archive_name files.. ( To create archive file ) tar tvf archive_name files.. ( To display files under archive file ) tar xvf archive_name files.. ( To extract files from archive file ) tar rvf archive_name files.. ( To append archive file )

33

File Compression
Results in smaller file size Text files can be compressed over 75% tar archives are often compressed

34

Compression Utilities
gzip, gunzip

Standard Linux compression utility Up to 75% compression for text files

bzip2, bunzip2

Newer Linux compression utility Generally achieves better compression than gzip

35

Using Compression
gzip somefile ( To create compressed file ) gunzip somefile ( To uncompress a compressed file ) bzip2 somefile ( To create compressed file ) bunzip2 somefile ( To uncompress a compressed file ) Note: - We can use z for gzip and j for bzip2 type of compression with tar

36

Using GUI shells ( GNOME & KDE)

37

Simple view of GNOME Desktop

38

Simple view of KDE Desktop

39

?
Questions

What have we learnt ?


File Editing using vi editor Advanced usage of vi editor Users and Groups Management Understanding Permissions Linux File system
Inodes Links Mounting Media

Archives
Compression

Using GUI shells ( GNOME & KDE)

Day 2 Complete !!!

?
Questions

Thank You !!!

Potrebbero piacerti anche