RH033 Red Hat Linux Essential

18
-: RH033 Red Hat Linux Essential:- -: RH033 Red Hat Linux Essential:-   RedHat Linux Family RedHat Linux Family A) Redhat Enterprise Linux Advance Server :- Redhat Enterprise Linux Advance Server :-  The top-of-the-line Red Hat Enterprise Linux Solution, this product supports The top-of-the-line Red Hat Enterprise Linux Solution, this product supports the largest x86-compatible servers and is available with the highest levels of the largest x86-compatible servers and is available with the highest levels of support. support. B) B) Redhat Enterprise Linux Enterprise Server :- Redhat Enterprise Linux Enterprise Server :-  For entry-level or mid-range department servers. Red Hat For entry-level or mid-range department servers. Red Hat Enterprise Linux ES provides the same core capabilities as Advance Enterprise Linux ES provides the same core capabilities as Advance Server for systems with up to two physical CPU’s and up to 8 GB of Server for systems with up to two physical CPU’s and up to 8 GB of main memory. main memory. C)  Redhat Enterprise Linux Workstation :- Redhat Enterprise Linux Workstation :- -: Commands :- -: Commands :- 1) #mkdir  <folder name> 2) #mkdir  –p  <parent folder name>/<sub-folder name>    -p = create parent & sub folder even if it is not there 3) #cat  >  new filename (this is allow to create file & to save file press     Ctlr+d) 4) #cat filename (to view files content) 5) #cat filename > newfile (this will append content of previous file to new    file) 6) #cat >> filename (this will append to the file & to save file press ctlr+d) 7) #date (To display date and time) 8) #date –s 2004-12-09 (yyyy-mm-dd) (this will change the current date) 9) #date –s 18:00 (this is will change time) 10) #date  MMddhhmmyy (it chages date & time together)    MM :- Month 

Transcript of RH033 Red Hat Linux Essential

Page 1: RH033 Red Hat Linux Essential

­: RH033 Red Hat Linux Essential:­­: RH033 Red Hat Linux Essential:­

          RedHat Linux FamilyRedHat Linux Family

A) Redhat Enterprise Linux Advance Server :­ Redhat Enterprise Linux Advance Server :­  The top­of­the­line Red Hat Enterprise Linux Solution, this product supportsThe top­of­the­line Red Hat Enterprise Linux Solution, this product supports

the largest x86­compatible servers and is available with the highest levels ofthe largest x86­compatible servers and is available with the highest levels ofsupport.support.B)B) Redhat Enterprise Linux Enterprise Server :­ Redhat Enterprise Linux Enterprise Server :­ 

For entry­level or mid­range department servers. Red HatFor entry­level or mid­range department servers. Red HatEnterprise Linux ES provides the same core capabilities as AdvanceEnterprise Linux ES provides the same core capabilities as AdvanceServer for systems with up to two physical CPU’s and up to 8 GB ofServer for systems with up to two physical CPU’s and up to 8 GB ofmain memory. main memory. 

C)   Redhat Enterprise Linux Workstation :­  Redhat Enterprise Linux Workstation :­  

­: Commands :­­: Commands :­

1) #mkdir  <folder name> 2) #mkdir  –p  <parent folder name>/<sub­folder name>      ­p = create parent & sub folder even if it is not there

3) #cat  >  new filename (this is allow to create file & to save file press         Ctlr+d)4) #cat filename  (to view files content)5) #cat filename > newfile (this will append content of previous file to new       file)6) #cat >> filename  (this will append to the file & to save file pressctlr+d) 

7) #date  (To display date and time)8) #date –s 2004­12­09 (yyyy­mm­dd) (this will change the current date)9) #date –s 18:00  (this is will change time)10) #date  MMddhhmmyy (it chages date & time together)      MM :­ Month 

Page 2: RH033 Red Hat Linux Essential

      dd    :­ Date       hh    :­ Hours       mm  :­ Minutes       yy    :­  Year 11) #date +”Today is %A, %B , %d , %Y . %n The time now is %r , %z .”                  Today is Sunday, may 05, 2005.Today is Sunday, may 05, 2005.                  The time now is 02:54:45 PM, EDT. The time now is 02:54:45 PM, EDT. 

12) #cal 12 2005  (12 represents month, 2005 represents year)13) #cal  (It will show you current cal)14) #cal 2006                 13) #cp sam.txt /root  (This is will copy sam.txt file to root folder)14) #cp filename filename (This is will copy the content of one file to         another)15) #cp –r  ­i –p /onefolder /secondfolder      ­i = Interactive ask before overwriting      ­r = recursive  (The content of sub folders and files)      ­p = preserve permission

16) #pwd  (To see the status of present working dir)

17) #cd ..   (This is allow to come one step back)18) #cd      (If this command is executed by any user then he orshe                       will be switch automatically to home dir for e.g. /root for rootuser) 19) #cd /    (This is will take you root of this current partition)20 ) #cd ~  (If this command is executed by any user then he orshe                      will be switch automatically to home dir for e.g. /root for rootuser)21) #cd –   (It will switch u to previous working directory)22) #cd ../root/sameer/test (This will first take u back one step and then it                                               will switch u to particular folder.) Note :­    . represents to the current dir 

        .. represents to the parent dir     

Page 3: RH033 Red Hat Linux Essential

There are two types of path 1. is relative path which represents . and 2.isAbsolute path which is denoted with /root/desktop 

23) #ls  (This is list the content of a particular partition)24) #ls –aldR      ­a  (All hidden files which is starting from .file )      ­l   (Long listing)      ­d   (To show only you directories)    

         ­R  (To see the content of sub­folders)         #ls –ld /home/sameer (To see only directories)          #ls  sh[]*  (It will list all which is starting from the word sh and in which                               third position can be letter or no which we can put in square                              bracket [] after * defines anything)[] [] ­­­­ This is known as positional parameter.         # ls sh[123456789]*              # ls  sh [0­9]*         # ls  sh [02468]* ­­­ even no match          # ls  sh[!02468]*     !! ­­­­­­­­  not operator         # ls –al | grep ^d (It shows only dir)         # ls –al | grep ^­ (It shows only normal files)      Note     :­  ^ this symbol is known as caret.Note     :­  ^ this symbol is known as caret.                    * , ? is known as wild characters in windows but unix it is known as* , ? is known as wild characters in windows but unix it is known as                                          globbing characters or meta characters. globbing characters or meta characters. 

   25) #mv oldfoldername  newfoldername (To rename folder or filename)   26) #mv  /root/sameer/cms  /home/sameer (To move folder from one                                                                           location to another)

27) #rm filename  (To delete a file)28) #rmdir dirname  (To delete an empty folder)29) #rm –r foldername (To delete sub­dir of a particular folder with                                           interactive)30) #rm –rf      (To remove all forcefully all the content)

Page 4: RH033 Red Hat Linux Essential

31) #touch newfile  (It will allow you to create new empty file as well as                                           to even to update timestamp of a file)

32) #file filename  (To recognize a file type)

33) #less filename  (To view a file content only)34) #more filename  (To view a file content only) 

35) #slocate filename or foldername (To find or search something on a                                                                system) 36) #locate filename or foldername (To find or search something on a                                                               system)      Note: ­Note: ­ slocate is actual command which is symlink to /usr/bin/locate 

37) #man command  (Help command of linux)38) #info command  (Help command of linux)39) #command ­ ­help  (Help command of linux)      # whatis command   (Help command of linux)

40) #switchdesk gnome or kde (To switch between GNOMEGNOME and KDEKDE                                                        desktops)

41) #history  (To see current command history of a terminal which                                       get store in a file .bash_history under home directory)       Note :­ !!  (To repeat last command)       !c  (To repeat last command that starts with C)                  !n  (To repeat a command by it’s number in history

output)                  !­n  (To repeat a command entered n command back)41) <ctrl+r> command  (To search a repeated command)

42) #find / ­name “find data” –print & (To search files or folders in a                                                                   system)43) #find . ­name “find data” –print & (To search files or folders in a                                                                  system)      #find / ­name “find data” –print 2>> /dev/null (To search files or folders in

Page 5: RH033 Red Hat Linux Essential

 a system by normal users and to suppress a message of permissiondenied we use 2>> )

43)  # 44) #which <command> (It shows the full path of shell commands)      #which clear (e.g. of above description)       #whereis  <command>     (It shows the full path of a command along with                                                     it’s man pages location) 45) #tr ‘a­z’ ‘A­Z’ < /etc/passwd      (It translate the output from lowercase to                                                            uppercase)      # ls –C | tr ‘a­z’ ‘A­Z’

46) # tee   (It reads from standard input and write to standard output files)      # ls | tee logfile  (This command will take output of who                                                     command and it will redirect to logfile (file)       # ls | tee | sort –r > /root/logfile       # cat  /etc/passwd | sort –r | tee sam                Note     :­   sort –r  =  it shows the output in reverse orderNote     :­   sort –r  =  it shows the output in reverse order         Note : ­ Modes of vi is as follows :­ 

Command mode :­• cursor movement • change, delete, yank, put, search 

  Insert mode :­• Type in new text• Return to command mode with <Esc>  Ex mode: ­• Configuring , exiting saving• Search and replaceEntering into insert mode :­

• a append after the cursor• i insert before the cursor• o open a line below• A append to end of line • I insert at beginning of line 

Page 6: RH033 Red Hat Linux Essential

• O open a line above <esc>  takes you from insert mode back to command mode

Undoing changes • u   undo most recent change • U  undo all changes to the current line since the cursor landed on the line • <ctrl­r>  redo last “undone” change

   Searching for text  • /text    search downwards for “text” word• ? text   search upwards for “text” word• n continue search in the same direction • N continue search in the opposite direction

     Saving and exiting : ex mode

Save changes Abandon changesExit :wq , or shift zz :q or :q!Do no exit :w :e!

Forcing changes :

Save changesExit :wq!Do not exit :w!

   • 5dd  delete five lines • x delete a character• r replace a character (or press insert twice to replace)• R replace character­for­character until you press <esc>   

Extra Options of vi:­

:r  newfile (It is possible to read other files into current file):! command (This will append given command)

Page 7: RH033 Red Hat Linux Essential

:! date  (This is will append date into current file):e /etc/hosts (This is will open file into current location) :set number (This will append numbering to each line):se nu  (This will append numbering to each line)<esc><esc> gg (It will take you to start of the line in current file) :$ (It will take you to end of the line in current file)  :sh (This will temp shut down vi):w newfile  (This will save as this current file into different

name)

Change, Delete, and Yank :­ChangeChange DeleteDelete Yank(copy)Yank(copy)

Line  cccc dddd YyYyLetter  clcl dldl YlYlWord cwcw dwdw YwYw

49) #vi –m filename  (File is non­modifiable)50) #vi –R filename  (File is only modifiable by using the exclamation  

  point :w!)51) #vi –n filename  (Do not use a swap file for a backup [useful for                                           floppies] )52) #vi –r filename  (Recover data from a swap file after a crash)53) #vi –x filename  (Encrypt file when saving, decrypt file when editing)54) #vi + filename   (It will open file and it will go to last line of the file)

­: Backup Utilities:­­: Backup Utilities:­

55) #tar  (tape archive)    #tar –cvf  /root/backup.tar  /projects  /data  /sameer (To create a tar file                                                                                         Backup)    #tar –tvf   /root/backup.tar               (To view the content of a tar file)  # tar –xvf  /root/backup.tar                (To extract the tar file but before                                                               extraction of a file you should be into                                                            destination folder)  Note :­ Remember tar command never compress the data but it onlycombines multiple data into one single tar file.

Page 8: RH033 Red Hat Linux Essential

 56) # compress –v /root/backup.tar        (It compress tar file to ratio of approx.                                                                   50%­ 60%) 

      ­v   = verbose­v   = verbose    Note :­ After compressing a tar file it gives an extension to the file i.e.   Note :­ After compressing a tar file it gives an extension to the file i.e.                                 backup.tar.Z backup.tar.Z  # zcat  backup.tar.Zbackup.tar.Z                         (It reads a contain of an *tar.Z file)# uncompress backup.tar.Z # tar –Zcvf   /root/backup.tar.Z  /projects  /data  /sameer     (To create a tar file along with compress utility)# tar –Ztvf   /root/backup.tar.Z        (To view the content of a compress tar                                                             file) #tar –Zxvf   /root/backup.tar.Z         (To extract the compress tar file but before extraction of a file you should be  into destination folder)  

# gzip  ­v   /root/backup.tar                (It zips a tar file with an extension                                                                .tar.gz.tar.gz)# gzip –lv  /root/backup.tar.gz           (To view the contents of an .tar.gz.tar.gz file)   # gunzip –v  /root/backup.tar.gz         (To extract the .tar.gz.tar.gz file)  # tar –zcvf   /root/backup.tar.gz     /projects  /data  /sameer     (To create a tar file along with zip utility)# tar –ztvf   /root/backup.tar.gz        (To view the content of a zip tar                                                             file) # tar –zxvf   /root/backup.tar.gz           (To extract a zip tar file but before extraction of a file you should be        into destination folder)  

# bzip2  ­v  /root/backup.tar           (It zips a tar file with bzip2 utility an                                                           extension .tar.bz2.tar.bz2) # bunzip2 –v  /root/backup.tar.bz2  (To extract the .tar.bz2.tar.bz2 file)  # tar –jcvf   /root/backup.tar.bz2  /projects  /data  /sameer   (To create a tar file along with bzip2 utility)# tar –jtvf   /root/backup.tar.bz2       (To view the contents of an .tar.bz2.tar.bz2 file)# tar –jxvf   /root/backup.tar.bz2    (To extract a bzip2 tar file but before extraction of a file you should be   

Page 9: RH033 Red Hat Linux Essential

     into destination folder)  

# zip –v  /root/file1                   (To zip a file with having extension i.e .zip).zip) # unzip –l   /root/file1.zip         (To view a zip file content)

#file­roller                                 (It’s an graphical utility for all kind of tar or                                                      zip,compress)

ln  (Link command )

There two type of link can be made to a files or folder. Symbolic link : ­ is a file that points to another file. In between two

link file both the file separately represents different inodes no.# ln –s <filename> <filename>

Hard link : ­ One physical file on the filesystem each linkreferences the file’s inode. File is present in the file systems as long asat least one link remains. After linked between two files both filerepresent to one inode number.

# ln  <filename>  <filename>

57) # head  /etc/passwd (To show you first top 10 lines (default) in a file)      # head –n 40 /etc/passwd   (To Show you first top 40 lines) 

58) # tail  /etc/passwd  (To show you last 10 lines (default) in a file)      # tail –n 20  /etc/passwd  (To show you last 20 lines )      # tail –f /var /log/messages          (To show automatic updates made into this file)     # watch tail /var/log/messages          (To show automatic updates made into this file)

 59) # wc  /etc/passwd    ( “Word Count” in a file or into some output)       # wc –l  /etc/passwd ( To read how many lineslines are available in a file)

Page 10: RH033 Red Hat Linux Essential

       # wc  ­w /etc/passwd (To read how many wordswords are available in a file)       # wc  ­c  /etc/passwd (To read how many characters are available in afile)       # ls   –al  | wc –l   60) # sort /etc/passwd  (Sort lines of a text files) 

 # sort  ­r /etc/passwd (sort in a reverse order)      # sort  ­n /etc/passwd (sort in a numeric order)      # tail  /etc/passwd  | sort (It will display last ten line with alphabetical                                                    order)  61) # cut  –d:  ­f7 /etc/passwd | sort | uniq   

  (To cut the out put of a file –d: means delimeter or separator –f7 field no  7 of a file /etc/passwd)

62) # grep  bash  /etc/passwd (To search a bash word from a file)     # ls –R | grep  .conf  Note : ­ Global Regular Expression Print (grep)    # ls –R | grep .conf | wc –l    # ls –al | grep ^d   ( To search for only directory)    # dmesg | grep CD    # dmesg | grep –i cd (To ignore case while searching a word)    # cat /etc/init.d/functions | grep \(\) | sort | nl     63)  sed (stream editor which is use to replace a word with another word)      #sed  ‘s/bash /nologin/g’  /etc/passwd  | grep nologin 

64) 

Page 11: RH033 Red Hat Linux Essential

­:Linux File Systems:­­:Linux File Systems:­

          A filesystem is a data structure written to the media that allowsusers to store and access files. The default filesystem for Red Hat Linux isthe Third Extended Linux Filesystem or ext3. Red Hat Linux supportsover 20 different filesystem types.

Page 12: RH033 Red Hat Linux Essential

­: An Inode :­­: An Inode :­

An inode table contains a list of all files in an ext2 or ext3 filesystem. An inode (index nodes) is an entry in the table, containing information

about a file (the metadata), including:­• File type, permissions, link count, UID, GID• The file’s size and various time stamps• Pointers to the file’s data blocks on disk• Other data about the file• Ext2 and ext3 file systems keep a list of files in the file system in a

table called an inode table.• An individual entry in the inode table is called an inode.• The inode is referenced by it’s number, which is unique within a file

system.

An inode maintains the following thing :­

The file type  File permission  Link count : the number of file names associated with the node number  The user ID number of the file owner  The group ID number of the associated group  Time stamps, including last access time, last modification time, and inode

change time Location of the data on the hard disk Other metadata about the file

Note :­  Above points cam be check by executing ls –alls –al command whichshows same thing in a  sequence.e.g.  :­­ ls ­alitotal 28

80788   ­rw­rw­rw­ 1 root root 5120 sep 11        11:35 mydata80788   drw­rw­rw­ 1 root root 5120 sep 11        11:35 myfolder

Page 13: RH033 Red Hat Linux Essential

­i   :­ The inode number for the mydata file is 80788 

­: The seven Fundamental File types :­ ­: The seven Fundamental File types :­ 

• ­ regular file• d directory• l symbolic link• b block special file• c character special file• p named pipe• s socket

­: Filesystem Structure of Linux :­­: Filesystem Structure of Linux :­

Interesting directories and their contents 

Directory Description

/ The root directory where the file system begins. In most cases the rootdirectory only contains subdirectories. 

/boot This is where the Linux kernel is kept. It is a file called vmlinuz. 

/etc The /etc directory contains the configuration files for the system.Most of the files in /etc are text files. Points of interest: /etc/passwd 

The passwd file contains the essential information for eachuser. It is here that users are defined. 

/etc/rc.d This directory contains the scripts that get the system started. 

/etc/sysconfig Red Hat systems have this directory. It contains a lot of start­upscripts and configuration files for various services. 

/bin, /usr/bin These two directories contain most of the programs for the system. The/bin directory has the essential programs that the system requires tooperate, while /usr/bin contains applications for the system's users. 

Page 14: RH033 Red Hat Linux Essential

/sbin, /usr/sbin The sbin directories contain programs for system administration,mostly for use by the superuser. 

/usr The /usr directory contains a variety of things that support userapplications. Some highlights: /usr/X11 

The X Windows system /usr/dict 

Dictionaries for the spelling checker. Bet you didn't know thatLinux had a spelling checker. 

/usr/doc Various documentation files in a variety of formats. 

/usr/man The man pages are kept here. 

/usr/src Source code files. If you installed the kernel source codepackage, you will find the entire Linux kernel source code here.

/usr/local /usr/local and its subdirectories are used for the installation ofsoftware and other files for use on the local machine. What this reallymeans is that software that is not part of the official distribution (whichusually goes in /usr/bin) goes here.

When you find interesting programs to install on your system, theyshould be installed in one of the /usr/local directories. Most often,the directory of choice is /usr/local/bin. On Red Hat systems, the /usr/local directories are created but they are empty, ready for youruse. 

/var The /var directory contains files that change as the system is running.This includes: /var/log 

Directory that contains log files. These are updated as thesystem runs. You should view the files in this directory fromtime to time, to monitor the health of your system. 

/var/spool This directory is used to hold files that are queued for someprocess, such as mail messages and print jobs. When a user'smail first arrives on the local system (assuming you have localmail), the messages are first stored in /var/spool/mail 

/lib The shared libraries (similar to DLLs in that other operating system)are kept here. 

Page 15: RH033 Red Hat Linux Essential

/home /home is where users keep their personal work. In general, this is theonly place users are allowed to write files. This keeps things nice andclean :­) 

/root This is the superuser's home directory. 

/tmp /tmp is a directory in which programs can write their temporary files. 

/dev The /dev directory is a special directory, since it does not reallycontain files in the usual sense. Rather, it contains devices that areavailable to the system. In Linux (like Unix), devices are treated likefiles. You can read and write devices as though they were files. Forexample /dev/fd0 is the first floppy disk drive, /dev/hda is the firstIDE hard drive. All the devices that the kernel understands arerepresented here. 

/proc The /proc directory is also special. This directory does not containfiles. In fact, this directory does not really exist at all. It is entirelyvirtual. The /proc directory contains little peep holes into the kernelitself. There are a group of numbered entries in this directory thatcorrespond to all the processes running on the system. In addition,there are a number of named entries that permit access to the currentconfiguration of the system. Many of these entries can be viewed. Tryviewing /proc/cpuinfo. This entry will tell you what the kernelthinks of your CPU. 

/mnt Finally, we come to /mnt, a normal directory which is used in a specialway. The /mnt directory is used for mount points. As we learned in the,the different physical storage devices (like hard disk drives) areattached to the file system tree in various places. This process ofattaching a device to the tree is called mounting. For a device to beavailable, it must first be mounted.

When your system boots, it reads a list of mounting instructions in thefile /etc/fstab, which describes which device is mounted at whichmount point in the directory tree. This takes care of the hard drives, butyou may also have devices that are considered temporary, such as CD­ROMs and floppy disks. Since these are removable, they do not staymounted all the time. The /mnt directory provides a convenient placefor mounting these temporary devices. In a normal installation, youwill see the directories /mnt/floppy and /mnt/cdrom. To see whatdevices and mount points are used 

Page 16: RH033 Red Hat Linux Essential

55) # 56) df  –h –T  (Report disk space usage)­h  displays sizes in easier to read units­T displays which file system is used by particular filesystem­h  Human readable means in MB or KB or GB57) du –h /data  (Reports disk space usage used per directory)

­: Formatting a Floppy :­  ­: Formatting a Floppy :­  

Two types of format needed to prepare a floppy 

A low level format (rarely needed)• fdformat  /dev/fd0F1440

A filesystem, one of• mkfs  ­t  ext2  /dev/fd0• mke2fs  /dev/fd0

Page 17: RH033 Red Hat Linux Essential

• mkfs  ­t  vfat  /dev/fd0• mformat  a:   

74) #alias cls= ‘clear’   (this is will create alias temp but if you wantpermanent       then write in user’s home directory in .bashrc file to remain last even if           user logged out)

75) #su  ( if a user name is not supplied, the su command assumesthat                                 you wish to become root.) 76) #su ­ ( if a user name is not supplied, and if you type dash aftersu                              command then assumes that you wish to become root and                            you want open a new shell after login.) 77) #su   username ( to change identity or to switch identity)78) #su  ­  username   ( to change identity or to switch identity with available                                    with new shell after login)

79) #who   (to find out who is logged in)80) #users (      )81) #w ( 82) #groups  (to find out what groups you belong to)83) #id            (to find out group id , user id)84) #last ( who has logged in a system last ,or who hasrebooted                                        system last time)85) #whoami  (to find out who you are)86) #umask  ( to check default permission)

• umask value is set for normal users is 0002 • umask value is ser for root user is 0022

Without umask in effect the umaskumask value for files it is 666 666 andfor folders it is 777777

Umask value can be set per individual user by setting umask ineach users home directory’s there is a file called as .bashrc ,which will be read only once when users logged into system

Page 18: RH033 Red Hat Linux Essential

If you want change umask value globally to all users so you haveset this value in          

Umask value is calculated for root and normal users is 

­ 666  ­ 777  002              002   664   775

     87) #newgrp othergroup (Where othergroup is one of the user’s secondary                             groups)