Linux redhat final


Published on

Published in: Education, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Linux redhat final

  1. 1. LINUX Redhat Version – 9 (Short Notes) Prepared by: CH. BASHIR AHMAD Computer Section, CMA(ISOs), Rawalpindi
  2. 2. Prepared by: CH. BASHIR AHMAD1 LINUX Redhat Ver.9 Windows = Drive based Linux = Directory/Folder based Linux is a Opens Source Kernal = Used for control Hardware & communication with users through shell. It is a core of the operating system. Type of Accounts: 1. System Accounts = ( root, bin, daemon) created by OS. 2. Regular or Custom Accounts = created by Administrator Shells = It is interface for the user to reach kernal. There are two types of Shells. 1. GUI = Graphic user interface 2. CLI = Command Line Interface (CUI). Limitations: Desktops = 256 CLIs = 06 Partitions: Auto or Disk Druid (Recommended) Compulsory Partion: '/' root SWAP (two partitions if manual) /boot /home ((five partitions if Auto installation) /var Size of root partition = 500 MB (min) min. 1 GB recommended. SWAP partition = RAM X 2 (Minimum) Boot loader: LILO, GRUB (Recommended) Paths: Relative path: Absolute path: File System: ext2 = FAT 16 ext3 = FAT 32 (NTFS) Hidden files/Folders: = Files or folder's name start with period(.) are hidden files or folders. Files extension .RPM = is indication of installable / executable files (RPM means RedHat Package Manager) Batch Files: = Make files with any commands, assign full permission and move to( /usr / local/bin ) folder for execution. Time based execution: = crontab -e file is used for the purpose.
  3. 3. Prepared by: CH. BASHIR AHMAD2 The LINUX FILE System: The LINUX is built around the concept of a file system, which is used to store all of the information that constitutes the long-term state of the system. This state includes the operating system kernel itself, the executable files for the commands supported by the OS, configuration infor, temp work files, user data, and various special files that are used to give controlled access to system hardware and operating system functions. LINUX file system belongs to one of four types of files: 1. ORDINARY files: These type of files contain text, data or program information. These files can not contain other files or directories. LINUX filenames are not broken into a name part and an extension part (although extensions are still used only for classification of files). Except special characters there can be up to 256 characters long. 2. DIRECTORIES files: Directories are used to store files and other sub-directories. 3. DEVICES files: LINUX treats with devices as ordinary files instead of drives. There are two types of devices in LINUX. 1. Block-Oriented Devices: which transfer data in blocks(e.g. hard disks, CDs etc) 2. Character-Oriented Devices: which transfer data byte-by-byte basis (e.g modems and dumb terminals) 4. LINKS: Hard-Link = Link to a file is indistinguishable from the file itself. Soft-Link = Provide an indirect pointer or shortcut to a file. Directory structure of Linux System: /root = home directory of root(administrator) /boot = Booting and startup information. /var = Holding variable files (e.g LOG files) /dev = Device information and drivers etc. /bin = User based bin files (e.g. EXE files related users based software) /sbin = System based bin files (OS's files) /lib = Link files about user based EXE files (dll etc related to user bin) /home = contain separate folders for each users. /temp = contain files (temp) accessible to all users. /lost&found= holding accidentally corrupted files. /etc = configurations files of HW and Software (Most important directory) Minimum Hardware requirement for installation of Linux: Processor = P-I with 133 Mhz Ram = 08 MB for CLI and 16MB for GUI HDD = 02 GB for CLI and 03 GB for GUI CD = 8 x INSTALLATION OF LINUX REDHAT VER.9.
  4. 4. Prepared by: CH. BASHIR AHMAD3 For Installation of Linux. (Redhat on 3 CDs, or Fedora (a new version of Linux ) on 4 CDs is required) 1. Insert Linux CD-1 (bootable) 2. Select GUI or CLI mode (CLI is advised) Type = Linux Text (press Enter) 3. Type of installation: (1.Desktop 2.Client/ws 3.Server 4.Custom) Select Custom. 4. Auto partitioning or Manual (Disk Druid) Select Manual (Disk Druid) partition. 5. Firewall: (Monitor traffic for viruses etc.) Select Disabled Option. 7. Mode selection: GUI or CLI Select CLI mode (which can be switched to GUI mode). 8. Network option: 1. DHCP 2. Manual IP Select Manual IP 9. Computer/Host name:Should be in small letter (due to case sen.) 10. Partitioning:(compulsory) 1. Root partition 2. Swap partition Min. Swap(RAM/virtual) must be RAM x 2 Max 2GB for internet server etc. File system of SWAP is swap. File system of ext2 = FAT16 File system of ext3 = FAT32 (compulsory) Type ‘ / ‘ for Root Size in MB, 4000 MB (4 GB) Type nothing for 2nd partition (Not applicable) File Sys = SWAP # Size in MB 1000 MB (1 GB) 6. 1. Selection of OS. 2. Reset Logon password Boot Loader: 1. GRUB Loader 3. LILO boot (Un Secure) 4. No boot Select GRUB option Leave Blank for Boot Loader Config. Use GRUB Password Boot Loader Password: redhat Confirm. redhat [ ] DOS = /dev/hda1 [*] RedHat Linux = /dev/hda8 (select/mark)
  5. 5. Prepared by: CH. BASHIR AHMAD4 [ ] F2 for selection of options /hda Master Boot Record (MBR) /dev/hda8 = First selection of boot partition. 7. Network configuration: [ ] use boot /dhcp [*] Active on boot.(select/mark) IP = Netmask = Host name = ws4 (any user’s defined computer name) 8. Security Level= Select (NO Firewall) No Additional Languages. 9. Clock. GMT = Select Asia/Karachi. 10. Root password = linux9 (must be different from GRUB pass) Confirm = linux9 11. Authentication option = simply OK 12. Packages Selection: [*] Admin Tools [*] DNS Name Server [*] Developing Tools (for database etc) [*] Editors [*] FTP Server [*] GNOM Desktop [*] Graphic Internet [*] Graphics [*] KDE Desktop Environment [*] Mail Server [*] Network Services [*] Office/Production [*] Printing Support [*] SQL Database Server [*] Server Config. Tools [*] Sound and Video [*] System Tools [*] Text Based Internet [*] WEB Server [*] Windows File Server [*] X-Software Development [*] X-Window System OK 13. Log File / install/log will be created on root partition. - Graphic Card Detection is processed.
  6. 6. Prepared by: CH. BASHIR AHMAD5 LINUX COMMANDS: Working in CLI mode. USER LOGIN: [root@ws4root] # (This is Linux Prompt) [user ] [Host] [Present] [name] [name] [working] [directory] [root@ws4root] # = '#' sign indicate that logged in have Administrator's rights. [root@ws4imran] $ = '$' sign indicate that logged in have User's right VIEW DIRECTORY CONTENTS: 1 - ls (list) list of all file and directory will be listed like DIR Command. All files/directories will be displayed in different colour. Blue = Directory White = Files Green = EXE files ls (all files) ls filename.ext(specific file) ls abc*.txt (all files start with abc and having any extension) ls .txt (* matches all character) ls book?.* (? matches one character) ls | more (only down scroll) ls | less (up & down scroll) ls * (not all files but files having asterisk in their names) ls ? -do- question mark ls ) -do- bracket ls -a (all files including hidden) hidden files and folders names start with dot (.) ls -lh displays files/folders with complete info. e.g. size etc. ls –F File type, add a symbol at the end of each file. / indicate a directory, @ indicate symbolic link to another file, * indicate a executable file. ls –r reverse. Lists the contents of the directory from back to front. Ls -R recursive. This option lists the contents of all directories below the current directory recursively. Ls –S Size, Sort files by size. ls -l show detailed information of files/folders including permission etc. example mention below: -rw-r--r-- 1 root root 10048 Nov 23:00:35 abc.txt (common file) drwxr-xr-x 3 root root 4096 Dec 23:00:35 xyz (folder/directory) -rwxrwxrwx 3 imran imran 10048 Nov 23:00:35 editor (executable file) first - means a common file first d means this is a folder/directory first l means this is a link file.
  7. 7. Prepared by: CH. BASHIR AHMAD6 2. dir (display files in width wise all in white colour without distinction between files and folders etc.) 3. clear (to clear screen like cls in DOS) 4. touch (to create a zero byte file.) touch abc.txt to create hidden file = touch .abc.txt (start with dot) 5. mkdir (to make a folder/directory) = mkdir xyz to create hidden folder = mkdir .xyz (start with dot) 6. logout (for logout from current session) or Ctrl+d 7. cd to change directory cd abc (change to abc directory/folder) cd / (come out from any depth of sub-directories to root) cd .. (come out one step back/up) cd ../..(come out two step up) cd ~ (return to your login directory) cd ~otheruser (take you to other’s login directory, if you are permitted) cd /home (take you to your home directory) cd /root (login to root directory, if you are permitted) 8. pwd (to display present working directory) 9. cp (for copy file/files and folder) cp –i (confirm overwritten ? ) cp -f (forcefully, do not display overwrite message) cp -v (verbose, display copying each file in progress) cp -fv (both switches together can be given.) cp -r abc xyz (abc folder will be copied in xyz folder including all files and sub folders/sub-directories.) cp -r abc/* xyz (copy all contents of abc folder in xyz folder, but not abc itself) cp -rfv abc/*.doc xyz (copy all files having .doc extension from abc to xyz folder) 10. rm (for Removing of files and folders) rm –i (confirm deletion ? ) rm abc.txt (delete a single file) rm -f abc.txt (delete file without confirmation) rm -r (delete a folder) rm -r xyz (remove xyz folder) rm -rf xyz (delete xyz folder along with its files and sub-folders without confirmation)
  8. 8. Prepared by: CH. BASHIR AHMAD7 11. mv (move/rename a file/folder) mv –I (confirm overwritten ?) mv –f (forcefully, do not display overwrite message) mv –v (display progress) mv /abc/abc.txt /123/ (move file abc.txt from abc folder to 123 folder) mv /abc/abc.txt /123/xyz.doc (during move assign new name/rename) 12. find (to find a file/files) find | -name "*.txt" (find all files having txt extension) find | -name "a*.d*" (find all files start with word a) 12-a file (is used to display kind of file ) file abc.txt (will display ASCII Text) 13. locate (also used to locate/find a file/folder) 14. cat (is stand for concatenate/join the contents of different files) cat (to create / read / append / merge files) cat 123.txt (contents of 123.txt file will be displayed at once not page wise) cat 123.txt | less (display contents up and down ward page wise. The contents can be viewed by using up and down arrow) cat > xyz.doc (create xyz.doc file, now type any text/data and press Ctrl+D for save) cat abc.txt 123.doc (1. contents of abc.txt will be copied in 123.doc 2. Original data of 123.doc will be deleted. 3. 123.doc will be created auto if not already exists.) cat >> abc.txt (new typed data will be saved at the end of the file, any existing data will not be lost) cat abc.txt >> xyz.doc (contents of abc.txt will be appended at the end of contents of xyz.doc) 15. more (view contents of files page wise only down ward scrolling allow) more abc.txt 16. less (view contents of files page wise up and down ward scrolling allow) less abc.txt 17. head (to view top ten lines of file by default) head abc.txt head -20 abc.txt (to view required top 20 of lines) 18. tail (to view last 10 ten lines of file by default) tail abc.txt tail -30 abc.txt (to view required last 30 lines) 19. grep (to locate a line having required text from file) grep Govt. abc.txt (find the line having word Govt. from abc.txt file) grep Govt. abc.txt | lpr (search for particular file having required text and then result saved as a file or sent to a printer)
  9. 9. Prepared by: CH. BASHIR AHMAD8 20. ps (to display front end processing) ps -aux (to display front/back end processing) ps -aux | grep xinetd (display all process contained xinetd) 21. alias c = "clear" (assign clear command to c, now press c for clear screen instead of clear command) alias abc = "vi /etc/passwd" (instead of typing a long command, just type abc & press enter to edit passwd file) NOTE: These aliases are temporary until rebooting the computer. For making permanent alias type these lines in /root/.bashrc file. e.g vi /root/.bashrc (press enter) and type under mentioned lines: alias c = "clrar" alias b = "reboot" Save and exit from file. NOTE: These aliases are permanent for that user, not for all users USER (CREATION/DELETION/MODIFICATION): 22. useradd imran (create a new user imran, useradd command will process four tasks: 1. create new user 2. assign id to user (id starts by 500, less than 500 is reserved) 3. assign group to user (by default his own name) 3. assign shell to user 4. create home folder for user. (by default create folder by user’s own name) Same home directory can be assigned to different/multiple users. useradd -u 600 imran (create user with custom user id i.e. 600 instead of by default) useradd -g sales imran (assign custom prim. group sales instead of by default of his own name) useradd -d /opt/tech imran (assign home folder 'tech' instead of /home/imran by default) useradd -s /bin/csh imran (assign C shell instead of bash Shell) useradd -c "Sales Dept" imran (assign comments to user) (or all above examples with one command) useradd -u 600 -g sales -d /opt/tech -s /bin/csh -c "Sales Dept" imran (press enter)
  10. 10. Prepared by: CH. BASHIR AHMAD9 23. usermod (for modification of user name) usermod -l imr imran (rename user imran to imr) 24. userdel (for deletion of user) userdel imran (delete user imran but do not delete imran's home folder) userdel -r imran (delete user imran and also his home folder etc.) 25. passwd imran (to assign or change a password) NOTE: 1. Password is compulsory for all users by default. 2. User cannot log on without assigning a password by default. 3. But it can be done by changing /etc/passwd file. (remove x and save file, now user can log on without password) passwd username (assigning password) passwd imran password imrbsr re-type imrbsr OK 26. man (man command stands for Manual, it is used for display the detail of any command) man ls (display complete help of ls command) 26-a. rpm (is used to install different software, installable files have .rpm extension) example: rpm -ivh /mnt/cdrom/rhl-gsg-en-9.noarch.rpm 27. su (command is used to work as root (superuser) temporarily, when you type su your logon by type root’s password then the prompt change to # (superuser) instead of $(common user). When you finished working type exit to return to your original status ) 28. lpr (is used to print a file) lpr filename.ext 29. lpq (is used to view the printing jobs) lpq active root 389 abc.txt (in this case 389 is the print job) 30. lprm (is used to cancel the print job) lprm 389 31. clear (is used to clear the terminal window) 32. reset (is used to reset the terminal windows, it means that restore terminal window, which was cleared by clear command)
  11. 11. Prepared by: CH. BASHIR AHMAD10 33. startx (is used to switch to graphical mode) or type OR init 5 (and press enter to enter the graphical mode) 34. Ctr + Function Key (Ctrl+F2 or F3 and so on to switching between desktops) (Ctrl+F2 switch to Desktop2, and Ctrl+F3 for Desktop3) TEXT EDITOR ( VI ). VI editor is used to create/edit/display a text based files. VI normally open a file in normal mode, it mean that file can only be viewed, but can not edited. To add a text in the file press [I] for (Insert Mode): Now it will be possible to make any changes in the file. Pres ESC to exit insert mode. To exit VI press [:] colon, this is VI command mode, now press [q] for quiting with out save changes. To save changes press [:] the press [w] and the press [q] to save changes and quit. If you accidentally made changes to a file and you want to exit vi without saving the changes, type [:] and then type [q] followed by [!], which exits without saving changes. To search a specific word e.g linux in a file type /linux and press enter. For more information about VI editor type: man vi ( is used to display help of vi ) vi filename (open an existing files, or create a new file if already not present) Reading PDFs files. xpdf (is a built in application to read PDFs ‘Portable Document Format’ files) For more information about xpdf application type: man xpdef (display complete help of xpdef command) DRIVES: /dev/fd0 refers to first diskette /dev/fd1 refers to second diskette and so on. /dev/cdrom refers to first CD-ROM /dev/lp0 refers to first parallel printer /dev/usb/lp0 refers to first USB printer /dev/hda0 refers to hard disk /dev/hda1 refers to second hard disk
  12. 12. Prepared by: CH. BASHIR AHMAD11 FLOPPY DRIVES: mke2fs (is used to create a Linux ext2 file system on a floppy/hard disk) On Linux system, example: /sbin/mke2fs /dev/fd0 Formatting Floppy drives: gfloppy (command is used to format a floppy/diskette) example: /usr/bin/gfloppy Using Floppy drives: mount (prepare to using floppy) example: mount /mnt/floppy/ using floppy: cd /mnt/floppy/ umount (is used to spare floppy) example: umount /mnt/floppy/ CD-ROMs mount (prepare to using CD) example: mount /mnt/cdrom using floppy: cd /mnt/cdrom umount (is used to spare CD) example: umount /mnt/cdrom/ CD Creator: Using X-CD-Roast: X-CD-Roast is a graphical application for duplicating and creating CDROMs. X-CD-Roast automates the process of burning CD-Rs and CD-RWs and is highly configurable to many CD copying or duplicating needs. Example: /usr/bin/xcdroast Using mkisofs The mkisofs utility creates ISO9660 image files that can be written to a CD-R(W). The images created by mkisofs can include all types of files. It is most useful for archival and file backup purposes. Suppose you wish to backup a directory called /home/joeuser/, but exclude the subdirectory /home/joeuser/junk/ because it contains unnecessary files. You want to create an ISO image called backup.iso and write it to CD-R(W) so that you can use it on your Red Hat Linux PC at work and your Windows laptop for trips. This can be done with mkisofs by running the following command: mkisofs -o backup.iso -x /home/joeuser/junk/ -J -R -A -V -v /home/joeuser/
  13. 13. Prepared by: CH. BASHIR AHMAD12 Option Function -o Specifies an output file name of the ISO image. -J Generates Joliet naming records; useful if the CD is used in Windows environments. -R Generates Rock Ridge (RR) naming records to preserve filename length and casing, especially for UNIX/Linux environments. -A Sets an Application ID ó a text string that will be written into the volume header of the image which can be useful to determine what applications are on the CD. -V Sets a Volume ID__ a name that is assigned to it if the image is burned, and the disc is mounted in Solaris and Windows environments. -v Sets verbose execution, which is useful for viewing the status of the image as it is being made. -x Excludes any directory immediately following this option; this option can be repeated. (for example, ... -x /home/joe/trash –x /home/joe/delete ...). USING CDRECORD The cdrecord utility writes audio, data, and mixed-mode (a combination of audio, video, and/or data) CD-ROMs using options to configure several aspects of the write process, including speed, device, and data settings. To use cdrecord, you must first establish the device address of your CD-R(W) device by running the following command as root at a shell prompt: cdrecord –scanbus: This command shows all CD-R(W) devices on your computer. It is important to remember the device address of the device used to write your CD. The following is an example output from running cdrecord -scanbus. Cdrecord 1.8 (i686-pc-linux-gnu) Copyright (C) 1995-2000 Jorg Schilling Using libscg version 'schily-0.1' scsibus0: 0,0,0 0) * 0,1,0 1) * 0,2,0 2) * 0,3,0 3) 'HP ' 'CD-Writer+ 9200 ' '1.0c' Removable CD-ROM 0,4,0 4) * 0,5,0 5) * 0,6,0 6) * 0,7,0 7) * To write the backup file image created with mkisofs in the previous section, switch to the root user and type the following at a shell prompt: cdrecord -v -eject speed=4 dev=0,3,0 backup.iso The command sets the write speed (4), the device address (0,3,0), and sets write output (verbose [-v]), which is useful for tracking the status of the write process. The obeject argument ejects the CDROM after the write process is complete. The same command can also be used for burning ISO image files downloaded from the Internet, such as Red Hat Linux ISO images. You can use cdrecord to blank CD-RW discs for reuse by typing the following: cdrecord --dev=0,3,0 --blank=fast
  14. 14. Prepared by: CH. BASHIR AHMAD13 Using Multiple Commands: Linux allow you to enter multiple command at one time. Each command will separate with semicolon. For example: mkdir testdir/; mv abc.txt testdir/ Ownership and Permissions: The Security of Linux is very strong. It you try to logon to root directory, you will see the following message: cd / root bash: /root: Permission denied All files and directories are “owned” by the user who created them. Owner of the file or directory can allow other users to access them. Reading, writing and executing are thee main setting in permission. For example: Ls –l (the following list will be displayed) drwxr-xr-x 56 root root 4096 Sep 8 23:35 . drwxr-xr-x 56 root root 4096 Sep 8 23:35 .. -rw-r—r-- 1 root root 15228 Aug 5 06:14 test.cfg -rw-r—r-- 1 root root 5228 Aug 5 06:14 test-data.cfg -rw-r—r-- 1 root root 2562 Aug 5 06:14 abc.txt drwxr-xr-x 4 root root 4096 Sep 8 19:58 newtext.txt The result of ls –l command is consist of following information about files/directories: Column Displayed values Description First drwxr-xr-x Permission Second 56,1 or any value User ID Third Root User name Forth Root Group name Fifth 4096 or size of file Size of Directory or File (4096 in case of Folder) Sixth Sep 8 23:35 Date and time of creation/up-dation of file/folder Seventh test.cfg File or Directory/folder name The detailed explanation of Columns: - (- - -) (- - -) (- - -) | | | | type owner group others There are ten slots are in the column, explain below: First slot shows kind of file ( - means normal file, d means folder, l means symbolic link) Beyond the first slot, in each of three slots can have: (r = read, w = write, x = execution, if it is a program or directory) Second three slots have (rwx means = read, write & execute) permission for owner Third three slots have (rwx means = read, write & execute) permission for group Forth three slots have (rwx means = read, write & execute) permission for other users
  15. 15. Prepared by: CH. BASHIR AHMAD14 Changing the permissions: chmod (command is used to change/assign the permission) For example there is a file look like below: -rw-rw-r-- 1 root root 2562 Aug 5 06:14 abc.txt In above example the owner and group have read and write permission(rw-), but other user have only read permission (r--). Now you want to permit other user to also write in the file and save it. Type this command: chmod o+w abc.txt | | others write permission Now you will see: -rw-rw-rw- 1 root root 2562 Aug 5 06:14 abc.txt Permissions can be provoked by using this command. chmod go-rw abc (provoke permission of read and write from group and users) -rw- - - - - - - 1 root root 2562 Aug 5 06:14 abc.txt Identities: (u = user/owner, g = group, o = others or a = all (u, g & o) Action: (+ = Add, - = subtract or = makes it the only permission) Remove all permission from all on the file abc.txt, type the following command. chmod a – rwx abc.txt Remove execution permission on folder named ‘bkup’ chmod a – x bkup Now try to change the directory backup. cd bkup/ bash: bkup: Permission denied. By adding – R (change permission for entire directory tree) Changing permission with numbers: Permission setting can be permitted by using numbers. (read =4, write=2, execute=1, 0=no permission)
  16. 16. Prepared by: CH. BASHIR AHMAD15 The detailed explanation of Columns: - (rw-) (rw-) (r- -) | | | 4+2+0 4+2+0 4+0+0 The total number of user is (4+2=6), and the group is (4+2=6) and the other have (4+0=4) So the value permission is 664. Now try to provoke the permission of write from group, means subtract 2 from group value i.e. 6-2=4, now the value will be 4 instead of 6. type the following command: chmod 644 abc.txt - (rw-) (r- -) (r- -) | | | 4+2+0 4+0+0 4+0+0 Here is a list of some common settings, numerical values and their meanings: -rw------- (600) Only the owner has read and write permissions. -rw-r--r-- (644) Only the owner has read and write permissions; the group and others have read only. -rwx------ (700) Only the owner has read, write, and execute permissions. -rwxr-xr-x (755) The owner has read, write, and execute permissions; the group and others have only read and execute. -rwx--x--x (711) The owner has read, write, and execute permissions; the group and others have only execute. -rw-rw-rw- (666) Everyone can read and write to the file. (Be careful with these permissions.) -rwxrwxrwx (777) Everyone can read, write, and execute. (Again, this permissions setting can be hazardous.) Here are some common settings for directories: drwx------ (700) Only the user can read, write in this directory. drwxr-xr-x (755) Everyone can read the directory; users and groups have read and execute permissions.
  17. 17. Prepared by: CH. BASHIR AHMAD16 COMPRESSING THE FILES/FOLDERS: Linex have three powerful tools to compress the files and folders i.e gzip, bzip2 and zip utilities. The bzip2 compression tool is recommended because it provides the most compression and is used in most UNIX-like operating systems. The gzip compression tool can also be found on most UNIX like operating systems. If you need to transfer files between Linux and MS Windows, you should use zip because it is more compatible with the compression utilities on Windows. Compression Tool File Extension Un compression Tool gzip .gz gunzip bzip .bz2 bunzip2 zip .zip unzip Example of bzip2: You can use bzip2 to compress multiple files and directories at the same time by listing them with a space between each one: bzip2 filename.bz2 file1 file2 file3 /usr/work/school The above command compresses file1, file2, file3, and the contents of the /usr/work/school directory (assuming this directory exists) and places them in a file named filename.bz2. To expand the compressed file, type the following command: bunzip2 filename.bz2 The filename.bz2 is deleted and replaced with filename. Example of gzip: To use gzip to compress a file, type the following command at a shell prompt: gzip filename The file will be compressed and saved as filename.gz. gunzip filename.gz The filename.gz is deleted and replaced with filename. You can use gzip to compress multiple files and directories at the same time by listing them with a space between each one: gzip -r filename.gz file1 file2 file3 /usr/work/school The above command compresses file1, file2, file3, and the contents of the /usr/work/school directory (assuming this directory exists) and places them in a file named filename.gz.
  18. 18. Prepared by: CH. BASHIR AHMAD17 Example of zip: To compress a file with zip, type the following command: zip -r filesdir In this example, represents the file you are creating and filesdir represents the directory you want to put in the new zip file. The -r option specifies that you want to include all files contained in the filesdir directory recursively. To extract the contents of a zip file, type the following command: unzip You can use zip to compress multiple files and directories at the same time by listing them with a space between each one: zip -r file1 file2 file3 /usr/work/school The above command compresses file1, file2, file3, and the contents of the /usr/work/school directory (assuming this directory exists) and places them in a file named BACKING UP FILES/FOLDERS: tar utility: Some of the options used with the tar are: -c create a new archive. -f when used with the -c option, use the filename specified for the creation of the tar file. when used with the -x option, unarchive the specified file. -t show the list of files in the tar file. -v show the progress of the filesbeing archived. -x extract filesfrom an archive. -z compress the tar filewith gzip. -j compress the tar filewith bzip2. To create a tar _le, type: tar -cvf filename.tar directory/file In this example, filename.tar represents the file you are creating and directory/file represents the directory and file you want to put in the archived file. You can tar multiple files and directories at the same time by listing them with a space between each one: tar -cvf filename.tar /home/mine/work /home/mine/school The above command places all the files in the work and the school subdirectories of /home/mine in a new file called filename.tar in the current directory.
  19. 19. Prepared by: CH. BASHIR AHMAD18 To list the contents of a tar file, type: tar -tvf filename.tar To extract the contents of a tar file, type: tar -xvf filename.tar This command does not remove the tar file, but it places copies of its unarchived contents in the current working directory, preserving any directory structure that the archive file used. For example, if the tar file contains a file called bar.txt within a directory called data/, then extracting the archive file will result in the creation of the directory data/ in your current working directory with the file bar.txt inside of it. Remember, the tar command does not compress the files by default. To create a tarred and bzipped compressed file, use the -j option: tar -cjvf filename.tbz file tar files compressed with bzip2 are conventionally given the extension .tbz; however, sometimes users archive their files using the tar.bz2 extension. The above command creates an archive file and then compresses it as the file filename.tbz. If you uncompress the filename.tbz file with the bunzip2 command, the filename.tbz file is removed and replaced with filename.tar. You can also expand and unarchive a bzip tar file in one command: tar -xjvf filename.tbz To create a tarred and gzipped compressed file, use the -z option: tar -czvf filename.tgz file tar files compressed with gzip are conventionally given the extension .tgz. This command creates the archive file filename.tar and then compresses it as the file filename.tgz. (The file filename.tar is not saved.) If you uncompress the filename.tgz file with the gunzip command, the filename.tgz file is removed and replaced with filename.tar. You can expand a gzip tar file in one command: tar -xzvf filename.tgz
  20. 20. Prepared by: CH. BASHIR AHMAD19 EDITING PATH: Start a text editor, such as gedit or vi, at a shell prompt. You can open the file called .bash_profile by typing the following: gedit .bash_profile You will see a PATH statement, similar to the one shown below. PATH=$PATH:$HOME/bin:/usr/local/bin: To the end of this statement, add $HOME/imran as shown below: PATH=$PATH:$HOME/bin:/usr/local/bin/:$HOME/imran: Save the file and exit the text editor. You can then make the changes to .bash_profile take effect immediately by typing the following command: source .bash_profile By adding paths to your .bash_profile, you can place utilities and programs in your path and be able to execute them without having to type ./ in front of the command.
  21. 21. Prepared by: CH. BASHIR AHMAD20 ACCESSING THE WINDOWS (WIN98) PARTITION: Create a directory in which windows information can be accessed. mkdir /mnt/windows Before you can access the partition, you will need to mount it in the directory you just created. As root, type the following command at a shell prompt (where /dev/hda1 is the Windows partition you found via Hardware Browser): mount -t vfat /dev/hda1 /mnt/windows You may then logout of root user mode and access your Windows data by changing into the mounted Windows partition: cd /mnt/windows To automatically mount a Windows partition every time you boot your Red Hat Linux system, you must modify the /etc/fstab file, which configures all file systems and disk device mounting options. At a shell prompt, su to root, following the above example. Next, open the /etc/fstab in a text editor by typing (for example): gedit /etc/fstab Add the following on a new line (replacing /dev/hda1 with the Windows partition you found via Hardware Browser): /dev/hda1 /mnt/windows vfat auto,umask=0 0 0 Save the file and exit your text editor. The next time the system is rebooted, the /etc/fstab file is read, and the Windows partition is automatically mounted in the directory /mnt/windows. To access the partition at a shell prompt, type the command cd /mnt/windows. To navigate through directories or files with spaces, surround the name of the directory or file with quotation marks, as in ls "Program Files".
  22. 22. Prepared by: CH. BASHIR AHMAD21 FORGOTTEN PASSWORD You can log in using single-user mode and create a new root password. To enter single-user mode, reboot your computer. If you use the default boot loader, GRUB, you can enter single user mode by performing the following: 1. At the boot loader menu, type [e] to enter into editing mode. 2. You will be presented with a boot entry listing. Look for the line that looks similar to the following: kernel /vmlinuz-2.4.18-0.4 ro root=/dev/hda2 Press the arrow key until this line is highlighted and press [e]. 3. Press the Spacebar once to add a blank space, then add the word single to tell GRUB to boot into single-user Linux mode. Press [Enter] to make the editing change take effect. 4. You will be brought back to the edit mode screen. From here, press [b] and GRUB will boot single-user Linux mode. After it finishes loading, you will be presented with a shell prompt similar to the following: sh-2.05# 5. You can now change the root password by typing bash# passwd root You will be asked to re-type the password for verification. Once you are finished, the password will be changed. You can then reboot by typing reboot at the prompt; then you can log in to root as you normally would.
  23. 23. Prepared by: CH. BASHIR AHMAD22 CHANGING CLI TO GRAPHIC MODE PERMANENT: Type the following command to amend the inittab file. Vi /etc/inittab The following information will display in editor’s windows; # Default run level. The run levels used by RHS are: # 0 - halt (Do NOT set init default to this) # 1 - Single user mode # 2 - Multi user, without NFS (The same as 3, if you do not have networking) # 3 - Full multi user mode # 4 - unused # 5 - XII # 6 - reboot (Do NOT set init default to this) # Id: 3: initdefault: . Amend carefully the line id:3:initdefault: to id:5:initdefault: save the file and reboot the computer, now the computer directly start with graphic mode. Name, description and Usage of Linux Files: .bash_history This file is used to record the each and every command/information typed on Linux prompt, which can be read in number of ways e.g. vi, cat, more, less etc. By default this file stores last 500 commands typed at the shell prompt. history | grep sneak (search previously typed command having word sneak within history file. It is something like DOSKEY command) Another time-saving tool is known as command completion. If you type part of a file, command, or pathname and then press the [Tab] key, .bash will present you with either the remaining portion of the file/path, or a beep. If you get a beep, just press [Tab] again to obtain a list of the files/paths that match what has been typed so far. For example: type up, press the [Tab] key twice and you will see a list of possible completions, including updatedb and uptime etc. and If you type upd and press Tab twice, you will see only updatedb. /etc/inittab Information regarding booting of computer. LOGGING OUT Logout OR Ctrl+D (for logout ) power off (for shutting down the computer) halt (virtually shutdown monitor)
  24. 24. SWITCHING BETWEEN DIFFERENT DESKTOPS: Ctrl+(right/left arrows) for switch different desktops. COMPARISON BETWEEN DOS AND LINUX: Prepared by: CH. BASHIR AHMAD23
  25. 25. SHORTCUT KEYS: power off Shutdown the computer. CTRL+ALT+BKSPACE Close the graphical desktop and return to logon screen, use only in case of normal exit is not working. CTRL+ALT+DEL Shutdown & reboot the system, use only in case of normal reboot/shutdown is not working. CTRL+ALT+FN Ctrl+Alt+F1 to F6 keys are used to switching between different shells and F7 is used for Graphical Desktop. ALT+TAB Switch between different open softwares. CTRL+D or logout Logout (and close) shell prompt. This is equal to EXIT. CTRL+I Clear the terminal like clear command. CTRL+U Clear the current line while working in terminal TAB Command Auto complete. reset Refresh the shell prompt screen. Prepared by: CH. BASHIR AHMAD24
  26. 26. Prepared by: CH. BASHIR AHMAD25 REMOTE CONFIGURATION: (logon to other computer) telnet telnet provide an insecure mechanism for logging into remote machines. All data including user name and password are passed in unencrypted form. For this reason it should be avoided. telnet compname or IP address ssh ssh is a secure alternative for remote login to other computer. It provides secure encrypted communications between hosts. ssh IP of other Computer (another computer IP) ssh (must be IP instead of name) Password: linux9 (Logon Prompt of another computer will appear, other computer should also have Linux.) exit (command is used to return back from other computer) CONCEPT OF IPS: The IP address or IP no consists of four parts: Classes of IPs: (Range) From To Class A 1 126 Class B 128 191 Class C 192 223 Class D 224 239 Class E 240 254 IP 127 is used for loop back testing or using for Virtual Network Card, which is not physically present in computer for windows. (MS Loop Adaptor Class E is reserved. Class D is used for multiple networks: The Box-1 (Ist three digits) indicates the Class of Networking. If the number in Box-1 is (from 128-191), it is a Class B network.
  27. 27. Prepared by: CH. BASHIR AHMAD26 In the small networking the Network ID will be the same for all network and Host ID will be different for each computer. Box1 Box2 Box3 Box4 Class-C N N N H Class-B N N H H Class-A N H H H In the above table the Class A IP address, the numbers would present “network, local, local, local” and Calss C present “network. network. network. local”. The range of Class A is much bigger then Class B or C. The total numbers of computer can be attached with the networking class wise stated below:- Computers Class-C 255 (255) Class-B 65025 (255 X 255) Class-A 16581375 (255 X 255 X 255) Subnet mask is mentioned below Class wise. Class-C Class-B 255.255. 0.0 Class-A 255. 0. 0.0 GATEWAY: is a network point that acts as an entrance to another network. CHANGING IP ADDRESS: setup (press enter, the following lines will appear) Network Configuration: (YES) IP address: (new IP) Net mask : Save the file, to take effect the changes, the following command is needed. service network restart (or reboot system to use new IP) ifconfig (now the new IP will appear) NETWORKING Configuration IPs, S.Masks : Enabling/Disbling Lan Card Netconfig is used to display: IP= . . . . S.Mask=. . . . .Default Gateway=. . . .Primary Name Server…. PING ( is use to check connectivity with other computer.) ping
  28. 28. Prepared by: CH. BASHIR AHMAD27 To use other computer name instead of IP, the following line should be added in following file. vi /etc/hosts add this line in file. ws7 (other computer’s name, instead of IP) save the file. Now the computer name “ws7” can be used instead of IP. ping ws7 To display IP address, submask and gateway address type: cat /etc/sysconfig/network-scripts/ifcfg-eth0 cat /etc/sysconfig/network (hotname or network IP) ASSIGNING TEMPORARY IP TO CURRENT COMPUTER. ifconfig etho netmask Enable or Disable networking: ifconfig eth0 down (Lan card is inactive/disable) OR service network stop ifconfig eth0 up (Lan card is active/enable) OR service network restart
  29. 29. Prepared by: CH. BASHIR AHMAD28 MODEM installation: The requirement of Linux is “Hardware Modem” instead of Win Modem/Software Modem. Hardware Modem is installed on COM1 or COM2 i.e. Physical Port for hardware modem. COM3, COM4 and COM5 etc are used for Win Modem/ Software modem. From Graphic Desktop select: System Setting -> Network -> New Modem -> Forward (checking modem) Select /dev/ttys0 (COM1) Baud Rate: 57600 (Speed) Volume: ON / OFF Select Povider: Phone:___UserID___Password___-> (Forward) Activate Modem (PPPoE) from Network. (Point to Point Protocol over Ethernet) Now Modem is installed, Mozila (i.e. browser) can be used to access Internet. SOUND CARD CONFIGURATION: If sound card is not plug and play and unable configured automatically, it can be configured manually by editing the file /etc/modules.conf, the following lines should be added, for example: alias sound sb alias midi opl3 options opl3 io=0x388 options sb io=0x220 irq=7 dma=0,1 mpu_io=0x300
  30. 30. Prepared by: CH. BASHIR AHMAD29 DHCP (Dynamic Host Configuration Protocol)configuration: DHCP (Dynamic Host Configuration Protocol): The DHCP service enables the residential gateway or the Internet Connection Sharing (ICS) host computer to assign IP addresses to client computers automatically. By default, when a residential gateway or ICS is installed, the DHCP service begins supplying addresses to computers on the network. Your Internet Service Provider (ISP) might use a DHCP service to assign your computer an IP address when you connect to the Internet. This is commonly referred to as a dynamic IP address. Each time your computer connects to the Internet, a different but unique number might be assigned to it. DHCP is recommended for ISP etc, whereas, for small network or fixed numbers of computer, Static IPs will be better. The DHCP is not installed by default, it is placed on 2nd CD of Linux. Install DHCP. Mount the CD in /mnt/cdrom rmp -i DHCP –3 (if not already installed) To activate DHCP copy the dhcpd.conf file to /etc/ folder: cp /usr/share/doc/dhcp-3.opl1/dhcpd.conf.sample /etc/dhcpd.conf vi /etc/dhcpd.conf LINE-4 Insert these lines: (network id) (subnet mask) “LAB.Com” (domain name or workgroup) “LAB.Com” Server IP (Dynamic range of IPs) :wq! (save file and exit) Now use the following steps: setup (press enter) Server should be set on STATIC IP and Client should be DHCP service network start service DHCP start To check the status of server type: Service dhcpd status
  31. 31. Prepared by: CH. BASHIR AHMAD30 SERVERs: DNS Server: The DNS server is very important to use different servers via DNS server. It converts IPs address to Computer name and vice versa. Steps to configure DNS Server are stated below: STEP-1: vi /etc/named.conf Amend line 26. Zone “localhost” IN (in place of localhost type Zone “” IN Line-32 give network ID in reverse order; 0.168.192 :wq! (save file and exit) STEP-2: cd /var/named vi /var/named/ (forward lookup zone) $ORIGIN domain name. (type in place of domain) Line-11 ID IN A (Local server host) ws2 ID IN A ftp ID IN CNAME ws2 www ID IN CNAME ws2 :wq! (save file and exit) NOTE: Different computer name/address can be typed in case of different computers are used for different purpose i.e. www and ftp and so. STEP-3: vi /etc/named/named.local Line-2 (type in place of localhost) Line-8 (domain name) type in place of localhost IN NS localhost. (No need of change) Add or modify these lines. 2 IN PTR ( 2 IN PTR ws2 :wq! (save file and exit)
  32. 32. Prepared by: CH. BASHIR AHMAD31 STEP-4: vi /etc/resolv.conf (this is a blank file) add these line in it. namedserver (local host) domain :wq! (save file and exit) service named start (this service cannot restart) To check the configuration of server, the following checks are required: nslookup (command is used to check configuration) check-1 > ws2 (press enter) Server: Address: # 53 Name: Address: Check-2 > (press enter) Server: Address: # 53 Name: Address: Check-3 > www (press enter) Server: Address: # 53 Name: Address: Check-4 > ftp (press enter) Server: Address: # 53 Name: Address: The above mentioned results should be displayed and verify their configuration.
  33. 33. Prepared by: CH. BASHIR AHMAD32 Now the server can be accessed by using these commands. (Access comp. by using IP) (By comp. name instead of IP) (Access by using comp. name) (By using IP instead of name) The following files will be used for configuration of DNS Server: vi /etc/named.conf vi /var/named/ vi /var/named/named.local vi /etc/resolve.conf service named start (For activation of DNS Server) Separate Computer for each server is necessary for large users, however, one computer can be used to create different server on it for small or limited users. In case of separate computer, IP address of each computer will be differed from each other but the gateway address will be the same. By using single computer for all servers, the IP address and Gateway will be the same.
  34. 34. Prepared by: CH. BASHIR AHMAD33 SAMBA Server: The following steps are required to create SAMBA Server. Step-1: Create Folder in ‘/’ root partition. e.g ‘testdata’. mkdir testdata chmod 777 testdata (assign max. permission) vi /etc/samba/smb.conf (add few line for sharing data) workgroup = LAB (running workgroup) (Go to end of file & add these lines) [mytestdata] (User defined sharing string, which will be displayed on window client) Path = /testdata (folder name) Writable = YES (to break read only attribute). Optional ValidUsers = user1 user2 (user list that can access) Optional Logfile = /var/log/samba/sm.log (History File) Optional Hostsall = 192.168.1. space 192.168.2. space (allow restricted hosted) :wq! (save file and exit) Step-2: (Create samba user) adduser bashir ID bashir (display ID bashir) smbadduser bashir :505 e.g. (create Samba User) password bashir (password for user) Password confirm: (again password) Step-3: service smb start (or restart)
  35. 35. Prepared by: CH. BASHIR AHMAD34 Step-4: Now go to Windows based network computer: Select Start -> Run (type linux computer’s IP e.g.) (press enter) Logon screen of Linux Computer will be appeared: User ID: bashir User Password: ****** After verifying the password, the two folders will be displayed: Shared folder i.e. ‘mytestdata’ User’s personal folder ‘bashir’ Now the folders from samba server side are enable to store/retrieve data.
  36. 36. Prepared by: CH. BASHIR AHMAD35 FTP Server: The File Transfer Protocol Server is called FTP Server. The DNS Server must be configured and started before using FTP Server. The under mentioned step are being made to configure FTP Server: Step-1: Copy some files in the /var/ftp/pub/ , every file or folder in the place are shared. Now configure the FTP server configuration file. Step-2: vi /vsftpd/vsftpd.conf Line-7 Anonymous enable = YES (enable and allow other users) Line-10 Local enable = NO (Local user do not allow) Line-26 Anon_mkdir_write_enable = YES (Allow to create folder) Line-36 Connect_from_post_20 = YES (in case of more load) Line-52 Idle_Session_timout = 600 :wq! (save file and exit) Step-3: useradd abcd password abcd Step-4: (Start/restart the FTP Service) service vsftpd start Step-5: FTP Server is ready to use, go to Windows bases computer and open Internet Explorer type the following address: ftp://abcd@
  37. 37. Prepared by: CH. BASHIR AHMAD36 NFS Server: (Network File Server, ”Linux to Linux”): The NFS Server (Network File Server) is a Linux to Linux sharing connection. It is used to transfer files from Linux Server to Linux Client. Following configuration is to needed to be configured NFS Server: Step-1: Server ends: mkdir datafile (make folder on root directory ) vi /etc/exports(this is blank file,add following line) /datafile (rw) (make datafile read & write) :wq! (save file and exit) Step-2: service NFS start (Start/restart NFS Service) Step-3: Client ends: mount :/datafile /mnt/ (access to server for using files copy to and from)
  38. 38. Prepared by: CH. BASHIR AHMAD37 HTTP or WEB or APACHE Server: The Hyper Text Transfer Protocol Server (HTTP) is also called WEB or APACHE Server. The DNS Server must be configured and started before using WEB Server. The under mentioned steps are being made to configure HTTP Server: Step-1: Copy some HTML page in to /var/www/html folder (index.html or default.html should be there or any html file can be used as default html) vi /etc/httpd/conf/httpd.conf (open file for amendment) line-66 enable for scorboard. Line-125 maximum-clients = 150 (limit of clients can be connected) Line-259 ServerAdmin.root@localhost (replace with OPTIONAL Line-273 ServerName (V-Important/compulsory) Line-408 Directoryindex…. (add (anypage.html)at the end of line, if default page is other than index.html) :wq! (save file and exit) Step-2: service httpd start (Start HTTPD Service) Step-3: Now on windows based computer, type: or http://IP Address of web server(display default html page) The following files will be used for configuration of WEB Server: /var/www/html/index.html /etc/httpd/conf/httpd.conf
  39. 39. Prepared by: CH. BASHIR AHMAD38 SQUID or PROXY Server: This server is used for high performance proxy caching server for web clients and internet sharing. Step-1: vi /etc/squid/squid.conf line-53 http_port 3128 (replace 80 with 3128) line-666 cache_dir ufs/var/squid 100.16.256 (enable line only) add following line: line-1732 acl askaria src / (anyname) (host IP) (submask) http-access allow askaria (allow or deny access) (or deny) line-1923 cache-mgr (already # none) line-1955 visible_hostname (servername) :wq! (save file and exit) Step-2: service squid start (Start SQUID Service) Step-5: On windows side set LAN Setting: Port: 80 ******************* Different IPs will be assigned to different Servers: e.g, DNS Server FTP Server HTTP Server MAIL Server AUTOMATIC STARTING OF SERVICE: To start any service automatically type: setup (and select system services then mark [*] required service start automatic (autostart).
  40. 40. Prepared by: CH. BASHIR AHMAD39 SERVER NAMEs and their related FILES & SERVICES: Names of different SERVERS and their related FILES and SERVICEs are stated below: Server Name: Configuration File name & Service name SAMBA Server /etc/samba/smb.conf SERVICE smb NFS (Linux to Linux) /etc/exports (blank file) SERVICE nfs DHCP Server /etc/dhcpd.conf SERVICE dhcpd DNS Server /etc/resolv.conf /etc/named.conf /var/ma,ed/named.local /var/naed/ SERVICE named FTP Server (DNS required) /etc/vsftpd/vsftpd.conf /var/ftp/pub (shared folder) SERVER vsftpd WEB Server (DNS required) /etc/httpd/conf/httpd.conf /var/www/html/index.html(default page) SERVICE httpd MAIL Server (DNS required) /etc/mail/ SERVICE sendmail SQUID/PROXY Server /etc/squid/squid.conf SERVICE squid