Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
143 views

Kernel Techn (Linux)

Uploaded by

Rick V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
143 views

Kernel Techn (Linux)

Uploaded by

Rick V
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 268
Nout Sy a Contents INTRODUCTION TO LINUX.. “RHEL 6 BASIC GRAPHICAL INSTALLATION... BASIC COMMANDS. / MANAGING FILE SYSTEMS AND PARTITIONS. “LOGICAL VOLUME MANAGEMENT (LVM) \AGSER AND GROUP ADMINISTRATION. -wnnewewennsnone ‘$IETWORK CONFIGURATION ANO TROUBLESHOGTINS MANAGING SELINUX (BASICS OF SEUNUN iy BOOTING PROCEDURE AND KERNEL, nua 4 JOB AUTOMATION... ADMINISTRATING REMOTE 5) 3 ma ENHANCED USER SECURITY SOFTWARE MANAGER BACKUP AND. nro ‘AR AND GZIP... MANAGE INSTAL S. DNS {DOMAIN NAME SYSTEM) SERVER.. ‘WEB SERVER |APACHE).. — __-ICKSTART AND NETWORKINSTALLATIONS cr UNIX Basics www kermeltech.com 195-197 198-200 201-210 2us-223 224-234 232-239 240-250 251-260 Page? of 278 cos Page 8 of 274 _.. Mnw.kermeltech.com UNIX Basics INTRODUCTION TO LINUX What is Operating System ? Operating system is an Interface between user and the re ufér hardware. The hardware of the ‘camputer cannot understand the human readable laf jorks on binaries i.e. O's and 1's. Also it : is very tough for humans to understand the binary lgngtagen such case we need an interface which ¢an translate human language to hardware and vic-verge for effective communication, ow ‘Types of Operating System: @ ( + Single User - Single Tasking OMggating System : Single User - Multitasking Opers@g System ¢ = Multi User ~ vad Operate ‘System Single User - Single Tasking Pperating System G in this type of opera ff only one user can log into system and can perform only one task at @ time. ? C Ms-00S , Ay . si Loa Side tasking operating System c THis Y)E°SFOFs supports only one der to log into the system but a user cn perform mull tasks at time, browsing internet while playing songs et. t Eg Windows -98,Xp,vsta,Seven ete, o Multi User - Multi Tasking Operating System é sneeitienceiaatiehe er G tasks at a time, In a broader term multiple users can logged into system and share the resources of the o system at the same time UNI, LINUX ete. oO Page 9 of 274 6 UNIX Bases winw.Kermeltech:com HISTORY OF UNIX In the beginning, there was AT&! Bell Labs’ Ken Thompson developed UNIX in 1969 so he could play games on a scavenged DEC PDP-7. With the help of Dennis Ritchie, the inventor of the “programing language, Ken rewrote UNIX entirely C" so that It could be used on different computers. in 1974, the OS was licensed to universities for educational purposes. Over the years, hundreds of people added and improved upon the systdnsand it spread into the commercial world. Dozens of different UNIX “flavors” appeared, e¢ tb unique qualities, yet still having enough similarities to the original AT&T version. All of the ‘ah were based on either AT&’s System V or Berkeley System Distribution (BSD) UNIX, or a hybrid of sie er ‘Apple Computer's A/UX + ATAsSystem V Release 3 + Digital Equipment Corporation's Ulrxand OSF/1 (renamed to DEE YNIK) Hewett Pacard’s HP-UX 8 IBM's AK Lyme’s Rea Time UNDX © NeXI’s NexTstep x © Santa Cruz Operation’s SCO UNIX silicon Graphics’ RIX SUN Microsystems’ SUN OS and ona ‘and dozens more. ‘The Open Standards Foundation ida ney ‘organization designed to keep the various UNIX gave UNKX a distinct advan ‘mainframe competition. M2 Then came the GUis/ ‘Macintosh operating system atid Microsoft's Windows operating environment simpli egos Yuting tasks, and made computers more appealing to a larger number of users. UNIX wizar@§, enj@éd the power of the command line interface, but acknowledged the difficult x earning ‘orl Users. The Athena Project at MIT developed the X Windows Graphical User for -dmputers. Also known as the X11 environment, corporations developed their own © of the BNI GUls based on X12. Eventually, a GUI standard called Motif was generally accepted ions and academia, : During the fate 1990's Microsoft's Windows NT operating system started encroaching into traditional UNIX businesses such as banking and high-end graphics. Although not as reliable as UNIX, NT became popular because of the lower learning curve and its similarities to Windows 95 and 98. Many traditional G —unidc compantes; suet as DEC ant Sitcom” Graphics, abandoned thelr OS for NT- Others;-suchras SUN; ————] focused their efforts on niche markets, such as the Internet. 3 7 Page 10 of 274 UNIX Basics www.kermeltech.com Linus Torvalds had a dream. He wanted to create the coolest operating system in the world that was free for anyone to use and modify, Based on an obscure UNIX flavor called MINIX, Linus took the source cade and created his own flavor, called Linux. Using the power of the Internet, he distributed copies of his OS all over the world, and fellow programmers improved upon his work. In 1999, with a dozen versions of the OS and many GUIs to choose from, Linux is causing a UNIX revival. Knowing that people are used to the Windows tools, Linux developers are making applications that combine the best of Windows with the best of UNIX. Cony UNIX Principles ?) ~ + Everything is a file UNIX system have many powerful utilities mia Seate and manipulate files. The UNIX security model is based around th of files. By treating everything as a file, you can secure access to hacer ngs way as you secure atcess 10 @ document A ‘+ Configuration data stored in text: - Storing configuration: ows an administrator to move a configuration from one machine to anoth ppbrovide the ability to roll back a system configuration to a particular date mate ‘* Small, Single-Purpose Programs: - UNIX provides fay filities. ‘+ Avoid captive user interfaces: % ¢ Ability to chain programs together to implex tasks:- A core design feature of UNIX is that output of one program c: input for another. This gives the user the flexiblity to combine many small progcamg together to perform a larger, more complex task, GNU Project/ FSF © GNU project started i I: Cres ‘UNIX clone 0, Nearly all required user space application created. 1mpWBgcc, emacs, etc. fare Foundation i lon-Profit organization that manages the GNU project. GPL - GNU (General Public Licens primary license for open ere = © encourages free software All enhancements and changes to GPL software must also be GPL Often called ‘copy left’ (All rights reversed) Page 11 of 274 www.kerrneltech.com ux Origins *. LINUS TORVALDS a) Finnish college student in 1991 b) Created Linux Kernel cae 2 + When Linux Kernel combined with GNU applications, complete free 05 was developed. Why Linux? Ay. ©} «Fresh implementation of UNIX APIs e * Open source development model + Supports wide variety of hardware * ¢ Supports many networking ree ney a ae Fully supported 2) Unuxis a UNIX like OS: Linuxis a oy the various UNIX versions are to each other. 2) Multi-User and Mult & a multi-user and multi-tasking operating system. That wveane that more dan @Ngperson can be logged an ta the same Unux computer at the same time. Ne useF could even be logged into their account from two or more terminals at thiggme time; Linus is also Multi-Tasking. A user can have more than ‘one program aN same time. 3). Wide hardwgye SgpBrt: Red Hat Linux support most pieces modern x86 compatible PC hardware 4) Fully Red Hat Linux is a fully supported distribution Red Hat Inc. provides mmagyygpMgort programs for the smallest to the largest companies. Page 12 of 274 www.kerrneltech.com oa oO Oo ARCHITECTURE OF UNIX ‘The architecture of UNIX can be divided into three levels of functionality, as shown in Figure -Thélowest level is the kernel , which schedules tasks , manages resources, and controls security. The, en is the shel, which acts as the user interface, interpreting user commands and startgg a The highest lvls iis, which provides uty faneos, nother wodsitis the USER gh thr isthe fone who operates those utiles. Ce Page 13 of 274 www.kerrneltech.com Linux us Jroot /home /boot Jetc Just (h eS” /bin FILESYSTEM HIERARCHY SYSTEM jle rooted, inverted tree like file This is top level directory itis parent directory for all other directories Itis called as ROOT directory itis represented by forward slash (/) Gey C.\ of windows ¥ itishome directory for rot user (superuser) 4 i provides working envronment fr root wer C:\Documents and Settings\Administrator mf) it is home directory for other users ae It provide working environment for othetajerfother than root) \Documents and Settings\username Read Ls Like vmlinuz (kernel). initrd (INITial Ram GRUB (GRand Uni or pater. boot ini, ntidr ion files it contains, like / : User info Jetc/res ay nf... Preferred DNS fete/dhcpd.conf...._ DHCP server \system32\dirvers\ ult soft wares are installed in /usr directory IX Sharable Resources) :\program files {tis optional directory for /usr It contains third party softwares c:\program files it contains commands used by all users (Binary files) it contains commands used by only Super User (root) (Super user's binary files) Page 14 of 274 www. kerrneltech.com oc [dev I proc var /ront {redia Hib it contains device files ike /dev/hda__... for hard disk Hdev/ed rom... for ed rom Similar to device manager of windows it contain process files 1ts contents are not permanent, they keep changing Itis also called as Virtual Directory {ts file contain useful information used by OS Sosy like /proc/meminfo information of RAWYSWYAP 5“ Iproc/cpuinfo ...__ information of CPU it is containing variable data like mails, log files itis default mount point for any partition’ ) skis empty by default bee it contains all of removable media ike -n8M, pen drive 2 it eontains trary fes whch gg B08 esate dh feot Library files in Linux are $® (shigred object) files LEO LOG Page 15 of 274 we Me RHEL 6 BASIC GRAPHICAL INSTALLATION Minimum and Recommended Requirements to install RHEL 6 are: Recommended Minimum Recommended ‘Minimum Hardware | Requirement for | Requirement for | Requirement for | Requirement for RHEL6-32BIT_| RHELG-32BIT | RHEL6-64BT_| RHEL6-64BIT PROCESSOR: AMD/INTEL /AMD/INTEL P IV AMD/INTEL “AMD/INTEL DUAL CORE ‘CORE 2 DUO oun MOTHER BOARD | __ NORMAL NORMAL VT ENABLED. VFENA! RAM. 168 384-512 MB 268 YosAca HARD DISK 20GB 15GB 40 GB “Y,20 6B Minimum Partition creation and sizes for basic installation’ Partition Name ‘Size For 32 Bit “Size For 64 Bit Trost) B to 1068 “Y_15to 20GB Toot 200 MB 200 MB SWAP. Twice of RAMA? Sy, ‘Twice of RAM ae Installing RHEL6 with above specification, ‘© Enter into BIOS setting and make coro first boot device ‘© Make sure that VT (Virtual Technolog for RHELG-64 bit systems ‘© Insert the RHEL 6 CD/DVD into, Drag ‘and boot the system + _if booted from CD/DVD Rorpfi ig screen will be displ al ENTERPRISE LINUX’ 6 Page 16 of 274 * Move the cursor to install or upgrade an ensting system and press Enter + Totest the media seleet OK, to skip the testing movlé curSot to Skip and press enter C Ay ae 3 ates ENTERPRISE LINUX 6 Page 17 of 274 www.kermelte Click on Next button to move forward ‘Ti]catatan (catata) | chineselsimplitecd esc (RHE) 1 Page 18 of 274 Select the keyboard type as required usually U.S English, click Next to continue Page 29 of 274 ‘+ Assign a hostname to the system, if wish to give ip address click on Configure Network, else Click Next to continue ‘Select the nearest city in yogr TRgzone and Click on Next to continue Page 20 of 274 a kerrneltech.com © a Select the type of partitioning you want, ta create your own partitions with custom sizes, select Create Custom Layout and click on Next to continue www.kermeltech:com Page 21 of 274 Page 22 of 274 ‘© Check the box beside Standard Partition, Click on Create to continue. Select / from Mount Point Box, Select the Free space again aj www kermeltech.com Page 23 of 274 + Select /boot from Mount Point Box, give the size 200 MB for it and click on OK to create it. F808 rn ‘san sd oe) 4 aes saree est TyBerE ve ‘© sda voevses) ‘esa ‘daz 03 Free i 486 www.kerrneltech.com Page 24 of 274 Te sda yaezss) san ‘sda sde3 ree, Q 6 Page 25 of 274 ‘To change the name of boot loader select sign new name to it. ‘To assign password to boot loader check: © le Use boot loader password and assign a password to it. To keep all as default, just click ge ‘to continue. Page 26 cf 274 G e o oO o 3 a cS “The default Installation of Red Hat Enterpise Unum ie a asic server stall. ou can are [0 Basie server | Database Server 10 Web server £10 viral Host {igh avoiaiiny 1D Lond galancer 12 Re Hot Enterprise Linux (ch Att ation store eportores ||. Soleaiysepostay. J ‘ou car arth eustarbze the soe selstion nor, Garter iaatall vid the sofviste” © ‘panagement appicaton, ‘@ Kumomize tet Customize fom, rl Select Desktop to have a graphical environmen Check Customize later to install additionalgoftvare later. Click on Next to continue ey « a = G ( Ee Pirro Tore ( sanmtcenzese ue 2 ee ( : 0 CG oO Page 27 of 274 ‘© When above prompt is displayed, remove the/cb/DVD from the drive and click on: Reboot to reboot the system. Page 28 of 274 + www, tech.ci Cee Biers ened Click on Forward to move to next step. ( his end userticanse agreement ("EULA") governs the use of any of the Versions of fea rat Emaeeese Linux, cero oer Red Hat software @ Yes, Vagree tothe License agreamant © Nas fe ret barge CG © Accept the license agreement and click on Forward to continue o Page 29 of 274 www.kerrneltech.com Poe Check No, lpr Stay ncalais waynecor manage siecipoe fo eyitens ae Seek ok prea con Untitled window www. kerrneltech.com Page 30 of 274 * Click on No thanks, to move to next step Sou may access the softwere undate took Sofrwat eo Hesate inche syvtern > a mindatrgeion ‘paler VIO), please dick ne Aavanced bution... iiyouniced more control whieh creating the user (specitying norne directory, www.kermeltech.com Page 31 of 274 * Give aname to create a user and assign it a password, Click on Forward to continue. Page 32 of 274 ~www.kerrneltes ma. CHeMOCOMOO'OD woo www.kermeltech.com Page 33 of 274 BASIC COMMANDS Creatin, Co} Moving files & Directories tng a file in Linux Using cat command: GS +cat (Concatenate) command is used to create fle and to display and modify sonedats of afile. + Tocreatea file ay # cat > filename (say ktfile) Hello World O Ctrltd (To save the file) &, Bas’ [root@ktlinux ~]# cat > ktfile ae Hello world a sO To display the content of the fil # cat filename (say ktfile) Trootektlinux ~]# cat ktfile Hello World [root@ktlinux ~]# § To appeni in the alr ing fi #eat>> Heat s>itfile Ctrltd (to save the chapges| {rootéktlinux ~]# cat >> ktfile Welcome to Kernel Technologies [root@ktlinux ~]# § v in same time usin command cl 1e> atotthifilgy file2 files Note: tércheck the files use #15 command {root@ktlinux ~]# touch filel file? fi1e3 [root@ktlinux ~]# 1s anaconda-ks.cfg Documents [ file | files Desktop Downloads | £11e2 | Install. log [root@ktlinux ~1# f Page 34 of 274 wyww.kerrneltech.com Gg & O.Oi.O.e AcDcace: oO Creating a Directory: mkdir mkdir kedir Treot@ktlinux ~]# mkdir ktair [root@ktlinux ~]# 1s anaconda-ks.cfg Downloads Desktop fileL Documents £i1e2 froot@ktlinux ~1# 2 Making multiple directories inside a di Let us make some directories according to the following architeéyre' KemetTech Linux fates install.log Anstall.log.syslog Music re mand. y cy s ce advlinux Tinuxcistr —hacmp ‘nat ad san netapp aimkdit ~p KemnetTech/{Linux/{gaiJinux, Check it by using tree commantfor f [rootakt linux ~]3 akdir -p RernettechjLimux/ advLinwsx, tinuxelste} ,Aix/{hacap, lpart, Storage/{san,nét app} {root@ethinos 1é teee KarnetTech/ KernelTech/ Aix hacep par timc E adyLinux Uinuxelstr Storage E netanp | san 9 directories, 0 files froptekthinex ~]8 istr},Aix/{hacmp,|par},Storage/{san,netapp}} ‘command Page 35 of 274 www.kerrneltech.com Copying files into directory 4icp Hep filet ktair [root@ktlinux ~]# cp filel ktdir {root@ktlinux ~]# cd ktdir [root@ktlinux ktdir]# 1s 5 filet [root¢ktlinux ktdirl# fj Copying directories from one lor # cp=rvfp Hep —rvip ktdlir2 kedir [root@ktlinux ~]# cp -xvfp ktdir2 ktdir ‘ktdir2’ -> “ktdix/ktaix2! ‘ktdix2/file2' -> “ktdir/ktdir2/file2' Tktdixe/file3' -> ~ktdir/ktdir2/file3' cktdix2/filea' -> ~Ktdix/ktdir2/file4' “ktdir2/file1' -> “Ktdir/ktdir2/file1' cktdix2/file5' -> “ktdix/ktdir2/files' [root@ktlinux ~]# cd ktdix [zoot@ktlinux ktdix]# 1s filel file2 xktdir2 [rootextlinux ktdirl# 9 Moving files from-one location to other (cut and Paste] Himy timy file2 ktdir {rcot@ktlinux ~]# mv file2 ktdir [root@ktlipux ~}# 1s anaconda-ks.cfg Documents filel install.log Desktop Downloads file3 install. [root@ktzinux ~1#.cd ktdir Iroot@ktlinux ktdir]# 1s file1 file2 [root@ktlinux ktdir]# /{ log. syslog www.kerrneltech.com Page 36 of 274 he o wee wee ‘Moving a Directory from one jocation to other #imy Pry Kedir Kedir2 [ trootextlinux -1¥ Is 7 anaconda-ks.cfg Documents filel install.log esktop Downloads file3 install.log.sysiog [voot@ktlinux ~1# mv ktdir Ktaix2 lroot@xtlinux ~]# 1s Leet tey pice neat peas Domiontr files iartaiiiefaysiog SEATS [root@ktlinux ~]# ed ktdir2 {xoot@ktlinux ktdir2]# 1s filel file2 file3 filed £415 Troot@xtlinux kedir214 ff Renaming a File simy sirnv kifile kernelfile {woot@kttioux ~1# Ts lanaconda-ks.cfg Documents install.log HeFLe] Pictures Templates Dountoads install.log.systog Music Public Videos nun =) arfile leome to Kernel Tech ile kemnetfile instal og Picturés Tomptates Doumtoads instal Lop. systog MIE Public. videos @ktlinu..~|# cat _kernelfite [root@kttinux -]# Is anaconda-ks.cfg Documents instatl.log ernel file Besktop Downtoads install.log.syslog {root@ktlinux ~]# mv ktdir kerneldir [root@ktlinux -]# 1s |anaconda-ks.cfg Documents install.log install.log.syslog kernelfite Desktop Down toads {rootektlinux -14 §f ae) Page 37 of 274 Www.kerrneltech.com Removing a File rm filename or #m-f filename (without prompting) [rootektLinux -]# 1s anaconda-ks.cfg Documents install.log kerneldir Desktop Downloads install.tog.syslog [kernel Tite] [rootektlinux ~]# rm kernelfile rm: remove regular file “kernelfite'? yl Without prompting: {root@kt linux ~]# rm -f kernetfile [root@ktlinux ~]# 1s anaconda-ks.cfg Documents install.log kerneldir Desktop Downloads install.log.syslog Music Troote@ktlinux ~1# If [root@ktlinux ~]# ls anaconda-ks.cfg Documents install.log kernetdir Desktop Downloads _install.log.syslog [ktdir | [rootektlinux ~]#[rmdir_ktdir [rootektlinux ~]# 1s anaconda-ks.cfg Documents install. log kernetdir Desktop Downloads install.log.syslog Music [root@ktlinux ~]# ff ‘directory with contents. e contents inside the directory and then run rmdir command tf dirname (where F stands for recursive and f stands for forcefully. [rootektlinux ~]# ls anaconda-ks.cfg Bocusents install.log kernetdiq] Desktep Downloads install.log.syslog Music [root@ktlinux ~]# rmdir kerneldir/ rmdir: failed to remove ‘kerneldir/’: [Directory not empty [root@ktlinux ~]# [fm -rt kerneldir: {root@ktlinux ~]# 1s anaconda-ks.cfg Documents install.1og Music Desktop Downtoads install.log.syslog Pictures Page 38 of 274 www.kerrneltech.com | | MIM_EDITOR V1__ Visual display editor VIM Visual display editor improved a This is command mode editor for files. Other editors in Linux are emacs, gedit Say Vi editor fs most popular ee ° @ oo a 2 insert made (edit mode) 7 cs "es 3 a Ithas 3 modes: extended command mode Note: When you open the vim editor, it will be in the command m iy detour ‘Wn the command mode the cursor’s can be used as fa i h//kjj_ to move cursor let/right/up/down “sy, ‘ ‘To begin insert mode at the cursonpositjor To inserta_ a the cursor position ole |>]»|—|- r ©) ngs ; aa | Togo tothe beginning ofthe page ; [6 re goto end ofthe page oO w To move the cursor forward, word by word b To move the cursor backward, word by word CS nw To move the cursor forward to n words {5W) nb To move the cursor backward to n words (SB) Oo u To undo last change (word) oO Page 28 0f 274 ie iww.kerrmeltech.com u To undo the previous changes [entire line) GrHR | To redo the changes wy __|Tecopyaine yy __ | To copy nines (Syy or 4vy) P___| To paste line below the cursor position P___| To paste line above the cursor position : ‘dw____| To delete the word letter by letter (like Backspace) x____| Todelete the world letter by letter (like DEL Key) iz dd__| To delete entire line 7 Cy ndd | To deleten no. of lines from cursor position|Sdd) fea T__[Tosearch a word in the file vk Extended Mode: ( Colon & Extended Mode is used for save and quit or save without quit usin “og Map Py ih “2 Beni To Save the changes aS Eset ‘To quit (Without saving) Escv:wa To saveand quit cs ao =e : Escrwa! | To save and quit forcefully Ae Factax [To save and aut % EsctX To give password to the file and reifliye pOssword Esck:20(n) | Togo tolline no20 orn ow Escr: senu | To set the line numbers tothe fle [[Esetsse nonu | To Remove the set line numbers dl ‘To open multiple files in vim edto dWim—o filet file2 To switch between files uSegtrl +w us ing fil Ne file names a 4 Chea file ls filename see the permissions of a particular file fos al shows the files in ascending order of modification. All the files start with p. Files with any first character and has ampie foie Directory listing only fHls-Id dicectoryname —_to see the permissions of a particular directory His [ael* First character of the filename must be a of e. fs [lae]* | symbol complements the condition that follows. The characters must nothe aor e. is [a-ml{c-2][4-9] list all the les in specific range Page 40 of 274 @ Gu G [symbol Tiweoffiie CC—“—~S™SCSCSCSCSY - Normal file d Directory t Link fite (shortcut) b Block file (Harddisk, Floppy disk) Character file (Keyboard, Mouse) Symbolic Link — * ©) ‘There are two types of Links: Bey, ee Soft Link Hardin 1 Size of link file is equal to no. of oF bothiaaye "same characters in the name of original file rt 2 Can be created across the Partition | Can't cross the partition, 3 Inode no. of source and link file is Ing of both file is same ia different é 4 if original file is deleted, link is broken ‘Weoriginal file is deleted then also link and data is lost *, “will contain data Est ___ SHORTCUT FILE A, BACKUP FILE _| ? #In=s ap “nw Ae I [root@ktLinux ~]# ln -s hing KtTile. slink rootektlinux ~]# ls -li ktfile ktfile.slink a3 efwxrwxtwx.-2 root root @ Sep 17 09:21 ktfile Wrwxrwxrwx. Lroot root 6 Sep 19 07:21[ktfile.stink -> kefite) {root@ktlinux ~]# santa Hin geDBgination> [root@ktLinux ~]# In ktfile ktfile.hlink [root@kttinux ~]# ls -li ktfile ktfile.alink -Twxrwxrwx. 2 root root @ Sep 17 09:21 Ktfite -rwxrwxrwx. 2 root root @ Sep 17 09:21 * eof [roote@ktlinux -1# ff Page 41 of 274 www.kermeltech.com Regular Expressions, Pipelines & I/O Re Grep: Grep stands for Global Regular Expression Print. It is used to pick out the required expression from the file and print the output. If grep is combined with another command it can be used to pick out the selected word, phrase from the output of first command and print it Examples of Grep: A Let us pick the information about root from the file fetc/passwd (/etc/passwd containg” information about all the users present in the system) ‘grep root _/ete/passwd [root@ktlinux -]# grep root etc/passwd [root]: x:0:0: root: {Foot}: /bin/bash isperator:x:11:0: operator: {root}/sbin/noLogin [rootektiinux ~]# ff To avoid case sensitivity of the word (i.e. the word may be g of lowercase) use -i grep -1 kernel ktfile (lets grep the word kernel ately lower case in the file ktfile) _ [root@ktlinux ~1# grep -i kernel ktfile Welcome to [Kernel] Tech Welcome to [Kernel Tech Welcome to[KERNEL ]TECH [rootektlinux ~}# To display a word and 2 lines ge prep -nA2 wheel /ete/group [roote@ktlinux ~]# grep -nA2 wheel /etc/group 11{wheelj: x: 18: root 12-mail:x:12:mail, postfix 13-wucp: x: 14: uucp [root@ktlinux ~]# ff To aiomgnaibs 2 lines after the word: rep el /etc/group os [root@ktlinux ~]# grep -nB2 wheel /etc/group 9-mem:x:8 10-kmem: x79: 11 fwheed: x: 10: root Page 42 of 274 ww errneltech.com ccoe@geee ce G To display the things except the given word: rep—v kernel Ktfile 5 [root@kt linux ~]# cat Ktfile Welcome to Kernel Tech Linux is Freedom [rootektlinux ~]# grep -v Kernel ktfile Linux is Freedom | Lrootekttinux ~1# ll To display the searched word in color - ‘figrep —color root /etc/passwd rn a — in other commands # cat ktfile | grep~1 kernel (pipe | is used to combine to conn ils | grep —| ktfile 4 # ifconfig |grep—1 etho 4 LUke this we can combine grep with many ome we will see in later chapters e Filter Command: © Filter commands are ved to filter the output so that the required things can easily be picked up, The comm, ich are used to filter the output are pee? #less fy #more ny thead Z i) Page 43 of 274 www. kerrneltech.com © less: The less command is used to see the output line wise or page wise. Ex: less /ete/passwd ‘oot :/root: /bin/bash in: /bin: /sbin/nologin daemon: /sbin:/sbin/nologin adm: /var/adm:/sbin/nologin /Var/ spool /Lpd:/sbin/nologin yne:/sbin: /bin/sync ‘sbin/shutdown ‘sbin/nologin uucp:x:10:14:uucp: /var/spool/uucp:/sbin/nologin operator:x:11:0: operator: /root:/sbin/nologin (00:games:/usr/games:/sbin/nologin | 30: gopher: /var/gopher:/sbin/nologin & 114:50:FTP User:/var/ftp:/sbin/nologin press Enter Key to scroll down line by line (or) %&, oa Use d to go to next page Use to gto prev page aid Use / to search for award in the file Use v to go vi mode where you can edit Baie you save it you will back to less command more is exactly samelike less a, x: more /ete/passwd ao Note: -press Enter key to scroll Gowljne by line (or) Use d to go to nexypage Use to go to pred page Use / to search f in the file Use v to go vi meee you can edit the file and once you save it you will back to : more com my - ~ G 18Y the top 20 lines of the file. = passwa 5 Troot@ktlinux -1# head /ete/pasewa ©: roct:/root:/bin/bash ‘ 1:bin:/bin:/sbin/nologin aemon:/sbin:/sbin/nologin :4:adm:/var/adm:/sbin/nologin 3 Lp: /var/spool/lpd:/sbin/nologin syne: x:5:0: sync: /sbin: /bin/syne G shutdown: x:610: Shutdown: /sbin: /sbin/shutdown halt :x:7:O:halt:/sbin:/sbin/halt eo mail ail: /var/spool/mait: /sbin/nologin uucp var/spoot/uucp:/sbin/nologin 5 Page a4 of 274 2 + 3 2 @ To display the custom lines ‘#thead -n /etc/passwd (where n can be any number) [root@ktlinux ~]# head -5 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon adm:x: ip 2:daemon: /sbin:/sbin/nologin 4:adm:/var/adm: /sbin/nologin i Up:/var/spool/1pd:/sbin/nologin 4 It is used to display the last 10 lines of the file Hail /ete/passwd Lroot@kttinux ~}# tail /etc/passwd ‘apache: 4:48: 48: Apache: /var/wws: /sbin/nologin LDAP Client User:/:/sbin/nologin Avahi mDNS/DNS-SD Stack: /var/run/avahi -daemon: /sbin/nologin /ete/ntp: /sbin/nologin var/Lib/ada:/sbin/nologin :Privilege-separated SSH: /var/enpty/sshd: /sbin/notogin /sbin/nologin isitor: /home/visitor:/bin/bash home tus bin/bash Todisplay the custom lin t tail -n /etc/passwd (wheren ep be any number) Troot@ktlinux ~}# tail -5 /etc/passwd re ktuser:x:580; 580:ktuser: shome/ktuser: /bin/bash ‘home /amit: /bin/bash ¢ /hone/vivek: /bin/bash 33:583: : /home/misab: /bin/bash ‘ 504: :/home/rahul: /bin/bash {rootakttinux “ell ( 7 = - — ‘ ce 6 Go Page 45 of 274 2 www.kerrneltech.com Sort: Itis used to sort the output in numeric or alphabetic order Hsort filename : | Troot@ktlinux ~]# cat ktfite Welcome to Kernel Tech Welcome to Kernel Tech Welcome to Kernel Tech Linux is Freedom Linux is Freedom Linux is Freedom [roote@ktlinux ~]# |sort ktfile! Linux is Freedom Linux is Freedom Linux is Freedom Welcome to Kernel Tech Welcome to Kernel Tech Welcome to Kernel Tech [roote@ktlinux ~]# Tosortthe file according to numbers =» Hsort—d ktfile of Hsort—h ktfile [rootektlinux ~]# cat ktfile 4.Welcome to Kernel Tech 2.Welcome to Kernel Tech 3.Welcome to Kernel Tech 1.Linux is Freedom 6..inux is Freedom 5.Linux is Freedom [rootektlinux ~]# fort -h ktfite 1,Linux is Freedom 2.Welcome to Kernel Tech 3.Welcome to Kernel Tech 4.Welcome to Kernel Tech 5.Linux is Freedom |6.Linux is Freedom www.kerrneltech.com Page 46 of 274 & & & te Q CG c oO To remove the duplicate entries from the output sort—u ktfile - Troot@ktiinux ~J# cat Kifite \ Welcome to Kernel Tech Welcome to Kernel Tech Welcome to Kernel Tech os Linux is Freedom Linux is Freedom * 3 Linux is Freedom he, [root@ktlinux ~]# [Sort -a KtTite Oa Linux is Freedom cag Welcome to Kernel Tech Ps o [roote@ktlinux ~]# 9 gut command: pate ‘The cut command is used to pick the given expression‘{in columns) and display the output. #cut -d -f filename (where d stands for delingiteré%,.: , #“ etc and f stands for field) [root@ktlinux ~]# cut -d: -fl /etc/passwd root bin daemon adm lp sync ‘shutdown halt mail uucp ‘To delimit spaces, int the field cut -d ““ -f; To dating ’ and print the field sf fhane Say [root@kt linux ~j# cat helio hello, how, are, you [rootektlinux ~]# cut -d, -f1 helto | helto Page 47 of 274 sed command: sed stands for stream editor, which is used to search a word in the file and replace it with the word required to be in the output Note: it will only modify the output, but there will be no change in the original file. tised_‘s/searchfor/replacewith/g’ filename [root@ktlinux ~]# cat ktfile Welcome to Kernel Tech D [root@ktlinux ~]# sed 's/Tech/Technologies/g' ktfile Cy Welcome to Kernel Technologies . [root@ktlinux ~]# cat ktfile be Welcome to Kernel Tech 4 i OY 1/0 Redirection: Say See’ Redirection is a process where we can copy the output of any, (s), file(s} into a new file. There are two ways of redirecting the output into a file. Using > or >> filename after the command, and a tee command Note: if the given name of the fil evoke ‘a new file will be created automatically. If the fil slready exists then it wp SygrwrtEontents of that le. [root@ktlinux ~1# cat ktfile Welcome to Kernel Tech [root@ktlinux ~]# sed 's/Tech/Technologies/g' ktfile > ktfl [root@ktlinux ~]# cat ktfl Welcome to Kernel Technologies = Appendiny jutput in same the same file [root@ktlinux ~]# cat ktfile2 Ameerpet - Hyderabad [root@kt Linux ~]# cat ktfile2 >> ktfl Lroot@ktlinux ~]# cat ktfl Welcome to’Kernel Technologies Ameerpet - Hyderabad Likewise there are many options where we can use redirections Ex: Copying contents of two files in a new file Heat filel file2 > file3 Page 48 of 274 eeg & c G ie Using tee commans The above options of redirections will not display any output, but directly save the output in a file. Using tee command will not only redirect the output to new file but it will also UispilRy the output. ° ha Ay Sw Sym: cat ditename> | tee ty Note: if the given name of the file {newfile) is not available a new fil automatically. If the file already exists then it will overwrite cohtents of the Heat ktfile [tee ktft baat [root@ktlinux ~]# cat ktfile [tee KtfT (© |Welcome to Kernel Tech & ted [root@ktlinux ~]# cat ktfl Welcome to Kernel Tech ‘Appending data in the same file using tee apa) ‘Synzcat filename {tee -a filename2 4 Heat ktfiled | tee -a ktf a0 ‘et Troot@ktlinux ~]# cat Serre [tee KttT Welcome to Kernel Tech [root@ktlinux ~]# cat ktfile2 |tee -a ktfl Ameerpet - Hyderabad [root@ktlinux ~]# cat ktf2 jelcome to Kernel Tech Ameerpet - Hyderabad Page 49 of 27a www.kerrnel com Find comms find command is used to find the files or directory’s path, itis exactly like the find option in windows where you can search for a file. Syntax: find / (under root) option filename Options that can be used with find command: n oD j 2 Option. Usage ews “ig” -name_ For searching afile with itsname a &. il ium For searching a file with particular inodlguftiber “type For searching a particular type of fil ~user or files whose owner is a particularuser ~group For files belonging to pase Bee Finding a rile with name AS #find / -name Kernel Tech [root@ktlinux ~]# find 7 -name KernetTech fin —/var/named*, Proot/Kernet Tech! File system loop detected; */var/named/. Finding a file with its inode dy #find / -inum 5934 Troot@ktlinux ~]# find 7 -inum 5934 /sys/devices/virtual/block/loop3/dev find: File system loop detected; ‘/var/ as ‘/var/named'. find: */proc/9206/task/9206/fd/5': No s find: */proc/9206/task/9206/fdinfo/5': find: */proc/9206/Td/5': No such file o find: */proc/9206/fdinfo/5': No such fi 7root/ktTile.hlink /rootskttile Troot@ktlinux ~1% Bl er errneltech.com Page 50 of 274 eecc oe eS Finding the files, whose owner Is a user called “ktuser” #find /-user ktuser _ _ _ Troot@ktlinux -]# find / -user ktuser | find: File system loop detected; */var & as ‘/var/named'. /var/spool/mail/ktuser /home/ktuser /home/ktuser/.mozilla /home/ktuser/.mozilla/plugins fhome/ktuser/.mozilla/extensions /home/ktuser/kernel2 /home/ktuser/.bashre i /home/ktuser/.gnome2 /home/ktuser/kernell ; Finding the files whose group is “ktgroup” #find / -group ktgroup ALR a [Trootektlinux ~]# find 7 -group ktgroup find: File system loop detected; */var/named/chroot © as ‘/var/named'. ‘ /home/ktuser/kernel2 ( /home/ktuser/kernelL ~ /nome/ktuser/kernel4 7hone/ktuser/kernel5 /home/ktuser/kernel3 GQ % ae °C Page 51 of 274 www.kerrmeltech.com File Permissions; Permissions are applied on three levels:- Owner or User level * Group level + Others level Access mades are of three types:- * 1 readonly * w_ write/edit/delete/append © x execute/run a command Access modes are different on file and directory: Permissions | Files abi r ‘Open the file "is the conter w Write, edit, append, delete file | Add/Del/Renamelcontents of dir x____| Toruna command/shell script | To enter thto dir using ‘cd” [root@ktlinux ~]# 1s -1 ktfile =rw-r--r--, 1 root root @ Sep 17 09:21 ktfile [root@ktLinux ~]# 1s -ld ktdir/ dewxr-xr-x. 2 root root 4996 Sep 17 09:21 ktdir/ a Filetypetpermission, links, owner file name 1 Symbolic method (ugo) 2 Absolute methods (numb! . al form of symbolic mode is: nlaghagne of owner, size in bytes, date of modification, metho. Assignifg different permissions to the file (user=rwx, group=nw and others=r fichmod u=nw%g=rw,o=r_ktfile (where ktfile is the name of the file) {root@ktlinux ~]# chmod u=rwx,g=rw,o=r ktfile [rootektlinux ~]# 1s -1 ktfile sTwxrw-f--. 1 root root © Sep 17 69:21 ¥: [rootektlinux ~]# ff Page 52 of 274 wyww.kerrneltech.com a & ber he fichmod ugo=rwx {rootektlinux ~]# Ls -L ktfile -Twxrw-r--, 1 root root © Sep 17 09:21 ktfile {root@ktlinux ~]# chmod ugo=rwx ktfile {root@ktlinux ~]# ls -l ktfile -rwxrwxrwx. 1 root_root @ Sep 17 09:21 ktfile nae ne . Ss Likewise you can add or rem. issions from any file for anyone (user grollp of other) chmod utx ktfile (Adding execute permission to user only). 7), #ichmod go-wx ktfile (Removing write and execute permissians: font ‘group’and other) #chmod gotwx ktfile [Adding write and execute permissions fyort¥'group and other) #ichmod go=r ktfile (Giving only read permission to —~ titer) 2 Absolute Method (numbers In Absolute method we use numbers instead of usi iagoltie © Read=a RS © Write=2 © Executes Assigning different permissions #tchmod 764 ktfile (where 7 men: Le, A241, rw=6 i.e. 442 and 2 indicates x) [rootektlinux ~]# ls -1 ktfite -rwxrwxrwx. 1 root root @ Sep 17 09:21 ktfile {root@ktlinux ~]# chmod 764 ktfile [root@ktlinux ~]# ls -l ktfile | = PwC P root raot @ Sep 17 09:21 ktfile [root@ktlinux ~]# 1s -1 ktfile | -rwxrw-T--, 1 root root @ Sep 17 09:21 « [root@ktlinux ~]# chmod 777 ktfile [root@ktlinux ~]# ls -1 ktfile -Fwxrwxrwx, 1 root_root @ Sep 17 09:21 ktTit= Likewise you can give different permissions according to your need Page 53 of 274 www.kerrneltech.com Removing all permissions from others fichmod 770 Ktfile (where 0 indicates no permissions) ‘Note: All the above permissions and procedure is same for files and directories. Umask: 7 When we create any file using touch, cat or vi commands they get created with default file permissions as stored in umask (User file creation mask).umask is a 4 digit octal nurmbe&wihich tells Unix which of the three permissions are to be denied rather than granted. ill decide that what should be the default permissions for a file and directory wken_ ee d. ‘The defautt umask value is 0022 stumask 2 [rootextli 7 umask oy 0 inux -1F u . 0922 1 i (roote@ktlinux ~1# oO the execute permission, so the raxirnum full tion can be 666 (i.e. 777-111 = 666), whereas a directory Note: For a file by default it permission for a file at the tim: can have full permissions ye. 777 . Theft permison je 666 © Minus the ur “022 + The default p&ttyissi6n for file is 644 (rwest~ r=) ektLinux ~]# umask Toot@ktlinux ~]# touch ktfite2 [root@ktlinux ~]# ls -l kttite2 trw-¥--r--| 1 root root 6 Sep 19 04:19 ktfile2 [root@ktlinux -]# Page 54 of 274 errneltech.co1 oc ¢ eeeoco ce ‘ ‘©The full permission for the directory 7 * Minus the umask value » The default permission for file is is f (rwx, rx Fx) k Toot@ktlinux ~]# umask : 1022 [root@ktlinux ~]# mkdir ktdir2 [root@ktlinux ~]# ls -ld ktdir2 . ¢ 2 root root 4096 Sep 19 04:24 ktdir2 ° [root@ktlinux ~]# lf ~_ ‘Modifying the umask value: av umask 002 4 The Modified default Permission for a file will be scoot nw.sw.t, and for the directory it will be 777-0022775 i.e. rwx,tWA-X. & root@ktlinux ~]# umask 1022) {root@ktlinux ~]# wnask 602 [root@ktlinux ~]# umask 002] TrootektLinux ~]# lf Note: Create a Don and rheck for the default permissions. oP ,* ‘These were the few things amongst the basics; keep working to furnish your basics. After All, “if the foundation is good then only the building can stand still” Page 55 of 274 www.kerrneltech.com MANAGING PARTITIONS & FILE SYSTEMS. What is a partition? Partitioning is a means to divide a single hard drive into many logical drives. A partition is a Bier sctfbloks ona rivets ae rented aan independent dk, Aparna an nest es sections of the hard drive to partitions . Why have multiple partitions? ie oy *Encapeulate your dat. Since fle system comuption i loca tg pail vob hare tose only eeearan nem will lead to disaster. By segregating space, ybu ensure that things other than the operating system die when allocated disk spac ted. Dikeationns itd Grit M EXTENDED ale Q) R u [frre { ter MBR = MASTER BOOT RECORD P= PRIMARY PARTITION EXTENDED= EXTENDED PARTITION L= LOGICAL PARTITION FREE= FREE SPACE Page 56 of 274 w.kerrnelt u we o ‘The Structure of Disk Partition ‘+ On the disk where 0/5 is installed, will have the first partition as MBR. ‘+ MBBR is a Master Boot Record, which contains two important utilities, IPL (Initial Program Loader) and PTI (Partition Table information) + IPLis responsible for booting the operating the system, because it contains the boot loader. a + In earlier versions of Linux i.e. up to RHEL 4, the default boot loader. was, fon Loader). But, since RHELS onwards it has been changed to GRub (Ggand{Urifie’ Boot loader), which is far more superior to LILO. a *+ The PM (Partition Table information) isthe information about the pufpbal-of partitions cn the disk, sizes of the partition and types of partitions. a Q ‘THE CRITERIA OF DISK PARTITIONING: XY ‘+ Every disk can have only 3 Primary Partitions. + Primary Partition is a partition which usually bi A goberatng system. Only one amongst the 3 primary partitions can be activity will be booted by MBR to load : the operating system. - + Extended Partition is a special type ie which can be subdivided into multiple logical partitions. As ther y 3 primary partitions per dik, and it the user is required to make f ohne then all the space remaining on the disk should be allocated ty Partition, which can be used to create the logical partitions later. There gabe onlyutihe extended partition per disk. + Logical partitions aréXthe Rartitions which are created under extended partition, all the space“in thgcextended Partition can be used fo create any number of logical ae Disk Identification: —‘¢” Different type of di having different initials in Linux {Be shown as (dev/hda ill be shown as /dev/sda rive will be shown as /dev/vda FILE SYSTEI ‘+ It is method of storing the data in an organized fashion on the disk. Every partition on ‘the disk except MBR and Extended partition should be assigned with some file system in order to make them store the data. File system is applied on the partition by formatting it with a particular type of file system. Page 57 of 274 wrw.kerrneltech.com file systems used in RHEL The file systems supported in Linux are ext2, ext3 and in RHEL 6 ext, vfat, etc. Ext file system is the widely used file system in Linux, whereas vfat is the file system to maintain a common storage between Linux and windows ( in case of multiple o/s‘ ene exr2 EXTS ExTs 1. [Stands for Second | Stands for Third Extended | Stands for Fouth Exte Extended File System | File System File System Yo 2,__ | fewas introduced in 1998 | ttwas introduced im 2001 | twas introduced/in 2098. 3. | Does not have journaling | Supports Journaling “Supports Journals,” fear Feature femurs. C4 @. | Maximum File size canbe | Maximum File Size can be from 16 GB to 273 from 16 GBto 278 3. [Maximum ext2 file] Maximum ext3 file system system size can be from 2| size can be from 2 TB to 32 Tato 32 7B 1B PB (Petabyte), 1 PB = 1024 TB byte). 6. _ | Cannot convert ext file | Vou can convert an ext@ifile PAIl previous ext file systems system to ext2. system to ext@pi can easily be converted into directly exté file systein. You can also backup/rest mount an existing ext3 #/s as ext ffs {without having to ) upgrade it). MOUNTING:- &® © Attaching a dire e file systern in order to access the partition and its file system is know ing. + The mount p@ipt Wthe directory (usually an empty one) in the currently accessible file system to tthjch¥ additional file system is mounted. * The / ry exists by default on all Unix-like systems. It, or usually its en ss {such as /mnt/floppy and /mnt/usb}, are intended specifically for use as ' for removable media such as CDROM, USB key drives and floppy disks. Files vi ch is related to mounting in Lin Jetc/mtab is a file which stores the information of all the currently mounted file systems; it is dynamic and keeps changing. Jete/fstab is the file which is keeps information about the permanent mount point. if you want to make your mount point permanent, so that it will be mounted even after reboot, then you need to make an appropriate entry in this file. Page 58 of 274 ww.kerrneltech.com 7S & G To view the existing partitions fifdisk-1 or parted -1 ; Trootantcls Desktop]# fdisk -T Disk /dev/sda: 32.2 6B, 32212254729 bytes 64 heads, 32 sectors/track, 30729 cylinders pits = cylinders of 2048 * 512 = 1048576 bytes sector size (logical/physical): 512 bytes / 512 bytes 1/0 size (ninimum/optimal): 512 bytes / 512 bytes | pisk identifier: exoseaease Device Boo ‘start End Blocks Id System eev/sdal = 2 201, 204800 83. Linux Partition 1 does not end on cylinder boundary. t /dev/sda2 202 8201 8192000 =83 Linux | Partition 2 does not end on cylinder boundary. t feev/sda3 8202-12201. 4096000 83 Linux Partition 3 does not end on cylinder boundary. ( sdev/sdas 12202 30720 © 18963456 «5 Extended Partition 4 does not end on cylinder boundary. ‘/dev/sdas ‘12264 15203 3672608 «= 83) Linux t Hev/sda6 15265 17294 _ 2008080 82 Linux swap / Solaris © ¥ [rootektets vesktopiif parted] Cc Model: viware Virtual disk (s¢s1) Disk /dev/sda: 32.268 C Sector size (logical/physical) : 5128/5128 : Partition Table: msdos v Number Start End Size Type _—Fiile system Flags eG 1 149kKB 221MB = 210MB° primary = ext4 boot 2 2 211NB-8599MB 8389MB primary —exte e 3 2599MB 12.868 4294M8 primary exta o 4 12.8GB 32.2GB 19.468 extended \ 5 12,898 15.968 31463 logical exts Me 6 ‘15.968 18.0GB 2097MB logical lLinux-swap(v1) G Note: Observe in the above picture thatthe device name is /dev/sda . B G Page 59 of 274 www.kerrneltech.com & Partition inistration using fdisk To enter into disk utility, the syntaxis ‘HEdisk Hidisk /dev/sda ve) [ TrootORtcls Desktop]# Fisk 7dev7sdal * WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command ‘c') and change display units to sectors (command ‘u*}. Command (m for hewp){ a] Command action ‘toggle.a bootable flag edit bsd disklabel toggle the dos compatibility flag delete a partition List known partition types print this menu add a new partition create a new empty DOS partition table print the partition table quit without saving changes create a new empty Sun disklabel change a partition’s system id change display/entry units verify the partition table } . write table to disk and exit a extra functionality (experts only) xE

You might also like