LINUX Redhat: Version - 9

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

LINUX Redhat

Version 9
(Short Notes)

Prepared by:

CH. BASHIR AHMAD Computer Section, CMA(ISOs), Rawalpindi

LINUX Redhat Ver.9


Windows Linux = = Drive based 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. 1. System Accounts = ( root, bin, daemon) created by OS. 2. Regular or Custom Accounts = created by Administrator 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). Desktops = 256 CLIs = 06 Auto or Disk Druid (Recommended) Compulsory Partion: '/' root SWAP (two partitions if manual) /boot /home ((five partitions if Auto installation) /var = 500 MB (min) min. 1 GB recommended. SWAP partition = RAM X 2 (Minimum)

Type of Accounts:

Shells

Limitations: Partitions:

Size of root partition

Boot loader: Paths:

LILO, GRUB (Recommended) Relative path: Absolute path: ext2 ext3 = = FAT 16 FAT 32 (NTFS)

File System:

Hidden files/Folders: = Files extension .RPM = Batch Files: =

Time based execution: =

Files or folder's name start with period(.) are hidden files or folders. is indication of installable / executable files (RPM means RedHat Package Manager) Make files with any commands, assign full permission and move to( /usr / local/bin ) folder for execution. crontab -e file is used for the purpose.

Prepared by: CH. BASHIR AHMAD

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: 3. DEVICES files: Directories are used to store files and other sub-directories.

LINUX treats with devices as ordinary files instead of drives. There are two types of devices in LINUX. which transfer data in blocks(e.g. hard disks, CDs etc)

1.

Block-Oriented Devices:

2.

Character-Oriented Devices: which transfer data byte-by-byte basis (e.g modems and dumb terminals) Hard-Link Soft-Link = = Link to a file is indistinguishable from the file itself. Provide an indirect pointer or shortcut to a file.

4. LINKS:

Directory structure of Linux System: /root /boot /var /dev /bin home directory of root(administrator) Booting and startup information. Holding variable files (e.g LOG files) Device information and drivers etc. 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 = 8x INSTALLATION OF LINUX REDHAT VER.9. 2
Prepared by: CH. BASHIR AHMAD

= = = = =

For Installation of Linux. (Redhat on 3 CDs, or Fedora (a new version of Linux ) on 4 CDs is required) 1. 2. Insert Linux CD-1 (bootable) 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. Auto partitioning or Manual (Disk Druid) Select Manual (Disk Druid) partition. Firewall: (Monitor traffic for viruses etc.) Select Disabled Option. Mode selection: GUI or CLI Select CLI mode (which can be switched to GUI mode). Network option: 1. DHCP 2. Manual IP Select Manual IP Computer/Host name: Should be in small letter (due to case sen.) 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) 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) 3
Prepared by: CH. BASHIR AHMAD

4.

5.

7.

8. 9. 10.

6.

[ ] 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 = 200.200.200.6 Netmask = 255.255.255.0 Host name = ws4 (any users defined computer name) Security Level = Select (NO Firewall) No Additional Languages. Clock. GMT = Select Asia/Karachi. Root password = Confirm = linux9 (must be different from GRUB pass) linux9 simply OK

8.

9. 10.

11. 12.

Authentication option =

13.

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 Log File / install/log will be created on root partition. Graphic Card Detection is processed.

Prepared by: CH. BASHIR AHMAD

LINUX COMMANDS:
Working in CLI mode. USER LOGIN:

[root@ws4root] #
[user ] [name] [Host] [Present] [name] [working] [directory]

(This is Linux Prompt)

[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 \? -doquestion mark ls \) -dobracket 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. 5
Prepared by: CH. BASHIR AHMAD

2.

dir

(display files in width wise all in white colour without distinction between files and folders etc.)

3. 4.

clear (to clear screen like cls in DOS) touch (to create a zero byte file.)
to create hidden file = touch abc.txt touch abc.txt (start with dot) mkdir xyz mkdir xyz (start with dot)

5.

mkdir

(to make a folder/directory) = to create hidden folder =

6.

logout
or

(for logout from current session)

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 others 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. 9.

pwd (to display present working directory) 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) rm
rm i rm abc.txt rm -f abc.txt rm -r rm -r xyz rm -rf xyz (for Removing of files and folders) (confirm deletion ? ) (delete a single file) (delete file without confirmation) (delete a folder) (remove xyz folder) (delete xyz folder along with its files and sub-folders without confirmation)

10.

Prepared by: CH. BASHIR AHMAD

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)
(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.

find

12-a

file

(is used to display kind of file ) (will display ASCII Text) (also used to locate/find a file/folder) (is stand for concatenate/join the contents of different files)

file abc.txt 13. 14.

locate cat

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
more abc.txt

(view contents of files page wise only down ward scrolling allow)

16.

less
less abc.txt

(view contents of files page wise up and down ward scrolling allow)

17.

head
head abc.txt head -20 abc.txt

(to view top ten lines of file by default) (to view required top 20 of lines) (to view last 10 ten lines of file by default)

18.

tail
tail abc.txt tail -30 abc.txt

19.

(to view required last 30 lines) 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) 7
Prepared by: CH. BASHIR AHMAD

20.

(to display front end processing) ps -aux (to display front/back end processing) ps -aux | grep xinetd (display all process contained xinetd)

ps

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 users 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) (assign home folder 'tech' instead of /home/imran by default) (assign C shell instead of bash Shell) (assign comments to user)

useradd -d /opt/tech imran useradd -s /bin/csh imran

useradd -c "Sales Dept" imran

(or all above examples with one command) useradd -u 600 -g sales -d /opt/tech -s /bin/csh -c "Sales Dept" imran (press enter)

Prepared by: CH. BASHIR AHMAD

23.

usermod (for modification of user name)


usermod -l imr imran (rename user imran to imr)

24.

userdel
userdel imran userdel -r imran

(for deletion of user) (delete user imran but do not delete imran's home folder) (delete user imran and also his home folder etc.) (to assign or change a password)

25.

passwd imran
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) (assigning password)

passwd username passwd imran password re-type 26.

imrbsr imrbsr

OK

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: 27. rpm -ivh /mnt/cdrom/rhl-gsg-en-9.noarch.rpm

su

(command is used to work as root (superuser) temporarily, when you type su your logon by type roots password then the prompt change to # (superuser) instead of $(common user). When you finished working type exit to return to your original status ) (is used to print a file) lpr filename.ext

28.

lpr

29.

lpq

(is used to view the printing jobs)

lpq
active root 389 abc.txt (in this case 389 is the print job) 30. 31. 32.

lprm (is used to cancel the print job)


lprm 389 clear (is used to clear the terminal window)

reset (is used to reset the terminal windows, it means that restore terminal
window, which was cleared by clear command) 9
Prepared by: CH. BASHIR AHMAD

33.

startx
OR

(is used to switch to graphical mode) or type (and press enter to enter the graphical mode)

init 5
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 vi filename 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 DRIVES: /dev/fd0 /dev/fd1 /dev/cdrom /dev/lp0 /dev/usb/lp0 /dev/hda0 /dev/hda1 refers to first diskette refers to second diskette and so on. refers to first CD-ROM refers to first parallel printer refers to first USB printer refers to hard disk refers to second hard disk (display complete help of xpdef command) ( is used to display help of vi ) (open an existing files, or create a new file if already not present)

10

Prepared by: CH. BASHIR AHMAD

FLOPPY DRIVES:

mke2fs

(is used to create a Linux ext2 file system on a floppy/hard disk) On Linux system,

example: Formatting Floppy drives:

/sbin/mke2fs /dev/fd0

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: CD-ROMs umount /mnt/floppy/

mount

(prepare to using CD) example: mount /mnt/cdrom using floppy: cd /mnt/cdrom (is used to spare CD) example: umount /mnt/cdrom/

umount

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/ 11
Prepared by: CH. BASHIR AHMAD

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


12
Prepared by: CH. BASHIR AHMAD

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 drwxr-xr-x 56 root root 4096 Sep -rw-rr-1 root root 15228 Aug -rw-rr-1 root root 5228 Aug -rw-rr-1 root root 2562 Aug drwxr-xr-x 4 root root 4096 Sep

8 8 5 5 5 8

23:35 23:35 06:14 06:14 06:14 19:58

. ..
test.cfg test-data.cfg abc.txt 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 13
Prepared by: CH. BASHIR AHMAD

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
Identities: Action:

root

2562 Aug 5 06:14

abc.txt

(u = user/owner, g = group, o = others or a = all (u, g & o) (+ = 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)

14

Prepared by: CH. BASHIR AHMAD

The detailed explanation of Columns:

(rw-)
| 4+2+0

(rw-)
| 4+2+0

(r- -)
| 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-)
| 4+2+0

(r- -)
| 4+0+0

(r- -)
| 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.

15

Prepared by: CH. BASHIR AHMAD

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 gzip bzip zip 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: File Extension .gz .bz2 .zip Un compression Tool gunzip bunzip2 unzip

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.

16

Prepared by: CH. BASHIR AHMAD

Example of zip: To compress a file with zip, type the following command:

zip -r filename.zip filesdir


In this example, filename.zip 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 filename.zip
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 filename.zip 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.zip.

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. 17
Prepared by: CH. BASHIR AHMAD

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

18

Prepared by: CH. BASHIR AHMAD

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.

19

Prepared by: CH. BASHIR AHMAD

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".

20

Prepared by: CH. BASHIR AHMAD

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. 2. At the boot loader menu, type [e] to enter into editing mode. 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. 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:

4.

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.

21

Prepared by: CH. BASHIR AHMAD

CHANGING CLI TO GRAPHIC MODE PERMANENT: Type the following command to amend the inittab file.

Vi /etc/inittab
The following information will display in editors windows; # Default run level. The run levels used by RHS are: # 0halt (Do NOT set init default to this) # 1Single user mode # 2Multi user, without NFS (The same as 3, if you do not have networking) # 3Full multi user mode # 4unused # 5XII # 6reboot (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 power off halt

(for logout )

(for shutting down the computer) (virtually shutdown monitor) 22


Prepared by: CH. BASHIR AHMAD

SWITCHING BETWEEN DIFFERENT DESKTOPS:


Ctrl+(right/left arrows) for switch different desktops. COMPARISON BETWEEN DOS AND LINUX:

23

Prepared by: CH. BASHIR AHMAD

SHORTCUT KEYS:
power off
CTRL+ALT+BKSPACE Shutdown the computer. Close the graphical desktop and return to logon screen, use only in case of normal exit is not working. Shutdown & reboot the system, use only in case of normal reboot/shutdown is not working. Ctrl+Alt+F1 to F6 keys are used to switching between different shells and F7 is used for Graphical Desktop. Switch between different open softwares. Logout (and close) shell prompt. This is equal to EXIT. Clear the terminal like clear command. Clear the current line while working in terminal Command Auto complete. Refresh the shell prompt screen.

CTRL+ALT+DEL

CTRL+ALT+FN

ALT+TAB CTRL+D or logout CTRL+I CTRL+U TAB

reset

24

Prepared by: CH. BASHIR AHMAD

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 ssh 192.168.0.15 Password: linux9 (Logon Prompt of another computer will appear, other computer should also have Linux.) (another computer IP)

(must be IP instead of name)

exit

(command is used to return back from other computer)

CONCEPT OF IPS:
The IP address or IP no consists of four parts: 000.000.000.000 Classes of IPs: (Range) From To 1 126 128 191 192 223 224 239 240 254

Class A Class B Class C Class D Class E

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 127.0.0.1)

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.

25

Prepared by: CH. BASHIR AHMAD

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 Class-B N N H Class-A N H H

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 255 65025 16581375

Class-C Class-B Class-A

(255) (255 X 255) (255 X 255 X 255)

Subnet mask is mentioned below Class wise. Class-C Class-B Class-A 255.255.255.0 255.255. 0.0 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: 192.168.0.99 (new IP) Net mask : 255.255.255.0 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 192.168.0.15
26
Prepared by: CH. BASHIR AHMAD

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. 192.168.0.15 ws7 (other computers 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 200.200.200.44 netmask 255.255.255.0


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

27

Prepared by: CH. BASHIR AHMAD

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 Baud Rate: (COM1) 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

28

Prepared by: CH. BASHIR AHMAD

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 vi /etc/dhcpd.conf LINE-4 Insert these lines: (network id) (subnet mask) 255.255.255.0 LAB.Com (domain name or workgroup) LAB.Com Server IP 200.200.200.50 (Dynamic range of IPs) 200.200.200.1 200.200.200.40 :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

/etc/dhcpd.conf

service network start service DHCP start


To check the status of server type:

Service dhcpd status

29

Prepared by: CH. BASHIR AHMAD

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 anyname.com) Zone anyname.com 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/localhost.zone (forward lookup zone) $ORIGIN domain name. (type anyname.com in place of domain) Line-11 ID ws2 ID ftp ID www ID IN IN IN IN A 192.168.0.10 A 192.168.0.10 CNAME ws2 CNAME ws2 (Local server host)

: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 localhost.root.domain.name (type anyname.com in place of localhost) Line-8 localhost.com (domain name) type anyname.com in place of localhost IN NS localhost. (No need of change) Add or modify these lines. 2 IN PTR domain.com. (anyname.com) 2 IN PTR ws2 :wq! (save file and exit) 30
Prepared by: CH. BASHIR AHMAD

STEP-4:
vi /etc/resolv.conf (this is a blank file) add these line in it. namedserver 192.168.0.10 (local host) domain anyname.com. :wq! (save file and exit) service named start (this service cannot restart)

To check the configuration of server, the following checks are required: nslookup check-1 > ws2 Server: Address: Name: Address: Check-2 (press enter) 127.0.0.2 127.0.0.1 # 53 anyname.com 192.168.0.10 (command is used to check configuration)

> 192.168.0.10
Server: Address: Name: Address: Check-3

(press enter) 127.0.0.2 127.0.0.1 # 53 anyname.com 192.168.0.10

> www
Server: Address: Name: Address: Check-4

(press enter) 127.0.0.2 127.0.0.1 # 53 anyname.com 192.168.0.10

> ftp
Server: Address: Name: Address:

(press enter) 127.0.0.2 127.0.0.1 # 53 anyname.com 192.168.0.10

The above mentioned results should be displayed and verify their configuration.

31

Prepared by: CH. BASHIR AHMAD

Now the server can be accessed by using these commands. ftp://192.168.0.10 (Access comp. by using IP) ftp://anyname.com (By comp. name instead of IP) http://www.anyname.com http://192.168.0.10 (Access by using comp. name) (By using IP instead of name)

The following files will be used for configuration of DNS Server: vi vi vi vi /etc/named.conf /var/named/localhost.zone /var/named/named.local /etc/resolve.conf (For activation of DNS Server)

service named start

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.

32

Prepared by: CH. BASHIR AHMAD

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) (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) [mytestdata]

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)

33

Prepared by: CH. BASHIR AHMAD

Step-4:
Now go to Windows based network computer: Select Start -> Run (type linux computers IP e.g.) \\192.168.0.10 (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 Users personal folder bashir Now the folders from samba server side are enable to store/retrieve data.

34

Prepared by: CH. BASHIR AHMAD

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@192.168.0.10

35

Prepared by: CH. BASHIR AHMAD

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 192.168.0.10 :/datafile /mnt/ (access to server for using files copy to and from)

36

Prepared by: CH. BASHIR AHMAD

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 Line-125 Line-259 Line-273 Line-408 enable for scorboard. maximum-clients = 150 (limit of clients can be connected) ServerAdmin.root@localhost (replace with 123.123.com) OPTIONAL ServerName www.satcom.com:80 (V-Important/compulsory) 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: http://www.satcom.com 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

37

Prepared by: CH. BASHIR AHMAD

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 192.168.0.1 / 255.255.255.0 (anyname) (host IP) (submask) http-access allow askaria (allow or deny access) (or deny) line-1923 cache-mgr 123@123.com (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: 192.168.0.1 Port: 80 *******************

Different IPs will be assigned to different Servers: e.g,


DNS Server 192.168.0.1 FTP Server 192.168.0.2 HTTP Server 192.168.0.3 MAIL Server 192.168.0.4

AUTOMATIC STARTING OF SERVICE:


To start any service automatically type:

setup (and select system services then mark [*] required service start automatic (autostart).

38

Prepared by: CH. BASHIR AHMAD

SERVER NAMEs and their related FILES & SERVICES:


Names of different SERVERS and their related FILES and SERVICEs are stated below: Server Name: SAMBA Server Configuration File name & Service name /etc/samba/smb.conf SERVICE smb /etc/exports (blank file) SERVICE nfs /etc/dhcpd.conf SERVICE dhcpd /etc/resolv.conf /etc/named.conf /var/ma,ed/named.local /var/naed/localhost.zone SERVICE named /etc/vsftpd/vsftpd.conf /var/ftp/pub (shared folder) SERVER vsftpd /etc/httpd/conf/httpd.conf /var/www/html/index.html(default page) SERVICE httpd /etc/mail/sendfile.cf SERVICE sendmail /etc/squid/squid.conf SERVICE squid

NFS (Linux to Linux)

DHCP Server

DNS Server

FTP Server (DNS required)

WEB Server (DNS required)

MAIL Server (DNS required)

SQUID/PROXY Server

39

Prepared by: CH. BASHIR AHMAD

You might also like