0% found this document useful (0 votes)
28 views34 pages

Linux Unit 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views34 pages

Linux Unit 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Unit 2

What is the VI editor?


The VI editor is the most popular and classic text editor in the Linux
family.
Below, are some reasons which make it a widely used editor –

1) It is available in almost all Linux Distributions


2) It works the same across different platforms and Distributions
3) It is user-friendly. Hence, millions of Linux users love it and use it for
their editing needs

There are advanced versions of the vi editor available, and the most
popular one is VIM which is Vi Improved. Some of the other ones are
Elvis, Nvi, Nano, and Vile. It is wise to learn vi because it is feature-rich
and offers endless possibilities to edit a file.
VI’s operation modes
They can be divided into two main parts.
*Command mode
*Insert mode
Command mode:
• The vi editor opens in this mode, and it only understands
commands
• In this mode, you can, move the cursor and cut, copy, paste the text
• This mode also saves the changes you have made to the file
• Commands are case sensitive. You should use the right letter case.
Insert mode:
• This mode is for inserting text in the file.
• You can switch to the Insert mode from the command mode by
pressing 'i' on the keyboard
• Once you are in Insert mode, any key would be taken as an input for
the file on which you are currently working.
• To return to the command mode and save the changes you have
made you need to press the Esc key
Starting the vi editor

Syntax :

vi <filename_NEW> or <filename_EXISTING>

And if you specify an existing file, then the editor would open it for you
to edit. Else, you can create a new file.

Note:
• You should be in the "command mode" to execute these
commands. VI editor is case-sensitive so make sure you type the
commands in the right letter-case.
• Make sure you press the right command otherwise you will end up
making undesirable changes to the file. You can also enter the insert
mode by pressing a, A, o, as required.
Moving within a file
•k - Move cursor up one line
•j - Move cursor down one line
•h - Move cursor left one character
•l - Move cursor right one character
•w - Move to the next word
•b - Move to the previous word
•$ - To the end of line
•0 - To the starting of line
•) - To the next sentence
•( - To the previous sentence
•} - To the next paragrah
•{ - To the previous paragrah

You need to be in the command mode to move within a file. The


default keys for navigation are mentioned below else; You can also
use the arrow keys on the keyboard.
Ctrl + F Scroll forward one screen
Ctrl + B Scroll backward one screen
Ctrl + D Scroll forward one-half screen
Ctrl + U Scroll backward one-half screen
G Go t the end of the file
10G Go to line 10

Inserting Text into file

i Before the character cursor


I At the beginning of the line
a After the cursor
A To the end of the line
o On a new line below cursor
O On a new line above cursor
R Overwrite existing text
Deleting Text from buffer area
dw From the cursor to the end of the word
3dw The words following the cursor
d$ From the cursor to the end of the line
d0 From the cursor to the beginning of the word
d] From the cursor to the end of a paragraph
dd The line n which the cursor rests
4dd The current line and the following lines
x The character under the cursor
X The character t the left of the cursor
u Undo unwanted changes
Saving and Closing the file
•Shift+zz - Save the file and quit
•:w - Save the file but keep it open
•:q - Quit without saving
•:wq - Save the file and quit
You should be in the command mode to exit the editor and save
changes to the file.
VI Editing commands
•i - Insert at cursor (goes into insert mode)
•a - Write after cursor (goes into insert mode)
•A - Write at the end of line (goes into insert mode)
•ESC -Terminate insert mode
•u - Undo last change
•U - Undo all changes to the entire line
•o - Open a new line (goes into insert mode)
•dd - Delete line
•3dd - Delete 3 lines.
•D - Delete contents of line after the cursor
•C - Delete contents of a line after the cursor and insert new
text. Press ESC key to end insertion.
•dw - Delete word
•4dw - Delete 4 words
•cw - Change word
•x - Delete character at the cursor
•r - Replace character
Hooking up Hardware Devices

1. How to work with floppy


2. Format a DOS floppy
3. Locate System Information
4. Backup Configuration Files
Working with Floppy

Mounting the Hardware Devices

Supermount feature supports Automatic Mounting of H/w


Devices. By this facility we can use the device directly.

Device Windows Linux Device File

Floppy A: /mnt/floppy /dev/fd0


CD-ROM E: / F: /mnt/cdrom /dev/hdb
To check Supermount facility in your system view /proc/mount
Cat /proc/mount
Content of this file if it support Supermount

Use mount command to to Display the mounted fileystem


Type mount command on the command line
Mounting a Floppy Disk
1. Type dmesg | less and press Enter. This will print
Floppy drive : fd0 is 1.44M -> for floppy drive
hdb: ATAPI 24x CD_ROM for CD-ROM drive
Place the floppy Disk on the floppy drive
2. Mount the drive
mount /dev/fd0 mnt/floppy
mount /dev/hbd /mnt/cdrom

3. Now we can use the floppy any way we want


If we want to copy some file
cp filename /mnt/floppy
4. After finishing the work unmount the drive
unmount dev/fd0
5. Take the floppy out of the drive
Using mtools package
Using mtools we don’t need to mount a floppy.

The fllowing list contains mtool commands

1. mdir -> to list the contents of floppy dis

2. mcopy -> To copy a file t and frm flopy disk.

3. mrem -> To rename a file located in floppy disk

4. mattrib -> To change the file attribute.

5. mformat -> To frmat a floppy disk


Formatting a Floppy Disk
1. Place the floppy disk in the floppy drive.

2. Type mformat a:

If error message is displayed 2 -> heads


We need to type 80 -> tracks
mformat -s 18 -h 2 –t 80 a: 18 -> sectors

3. Type mlabel a: ‘description’


eg) mlabel a: ‘myfolder’
‘myfolder’ will be printed as a label

4. Type mcopy filename a:(change to the directory where the file is


stored )
mcopy a:filename
Gathering important information
1. Log in as a superuser .
Type su
2. Vi -R /var/log/messages

•The -R option opens the file in read-only mode using the Vi text editor.
•/var/log/messages is a system log file that contains messages from various
system services and applications.
•Displays information such as system startup messages, hardware
events, and software errors.
•Essential for monitoring system issues.
•Provides insights into system events and activities over time.
•Useful for troubleshooting errors and identifying security breaches.
•Allows users to review historical system logs for analysis and reporting.

Type :q to quit the text editor


Type su Username to return to your user account
5. Vi –R /proc/cpuinfo CPU type and speed info.

•The -R option opens the file in read-only mode in the Vi text


editor.
•/proc/cpuinfo is a pseudo-file that provides detailed
information about the system's CPU.
•Displays CPU architecture, model, vendor, and family.
•Includes details such as CPU clock speed, cache size, and
features.
•Essential for identifying the CPU type and its capabilities.
•Helpful for system administrators and users for system
optimization and troubleshooting.
•CPU speed information can be crucial for understanding system
performance and compatibility with software applications.
6. Vi –R /proc/meminfo Total RAM, used memory.

• The -R option opens the file in read-only mode using the Vi text
editor.
•/proc/meminfo is a virtual file that provides detailed information
about the system's memory usage and statistics.
•Displays total available memory, free memory, and used memory.
•Includes information on memory usage by buffers and cache.
•Essential for monitoring system memory usage and diagnosing
performance issues.
•Helpful for system administrators and users to optimize memory
allocation and troubleshoot memory-related problems.
7. Vi –R /proc/mounts filesystems that are mounted.

•The -R option opens the file in read-only mode using the


Vi text editor.
•/proc/mounts is a virtual file that provides real-time
information about currently mounted filesystems.
•Displays a list of all mounted filesystems on the system.
•Includes details such as the filesystem type, mount
point, and mount options.
•Essential for understanding the current filesystem
configuration of the system.
•Helpful for system administrators and users to manage
and troubleshoot filesystem-related issues.
•Allows users to verify whether filesystems are mounted
correctly and review their options.
5. Vi –R /proc/ioport

•The -R option opens the file in read-only mode using the Vi


text editor.
•/proc/ioport is a virtual file that provides information
about input/output (I/O) port addresses.
•Displays details about I/O port ranges and their
corresponding devices.
•Essential for understanding the hardware configuration of
the system.
•Allows users to review the allocation of I/O addresses to
devices.
Vi –R /proc/interrupts

•The -R option opens the file in read-only mode using the Vi


text editor.
•/proc/interrupts is a virtual file that provides real-time
information about system interrupts.
•Displays details about interrupt request (IRQ) usage by
devices.
•Each line represents a specific IRQ and the devices using it.
•Helps monitor interrupt usage for optimizing system
performance.
•Allows users to identify devices causing high interrupt
activity.
Vi –R /proc/dma

•The -R option opens the file in read-only mode using the


Vi text editor.
•/proc/dma is a virtual file that provides information
about Direct Memory Access (DMA) channels.
•Displays details about DMA channels and their status.
•Essential for troubleshooting DMA-related issues.
•Helps in understanding memory transfer operations.
•Provides insights into DMA channel allocations and
usage.
•Useful for diagnosing and resolving DMA conflicts.

At a time we can open several files but can view only one file.
Type :next to go to the next file
Backing Up and Restoring the File System

Steps:

1. Develop a Backup Plan

2. Backup files to floppy disks

3. Compress file to save space

4. Create an Archive file


Develop a Backup plan
1. Make a list of files and directories that need to be backed
up
Eg) Configuration files which is found in /etc directories
and /usr/lib
2. Find a few tools to use when backing up and archiving file
and directories.
3. Decide how often the system and individual files need to
be backed up.
4. Select a storage media that will be used to store the file.
5. Find a safe place to store the files.
Simple back up method Is to copy the files into floppy disk
For that need to mount the floppy disk and use
cp command to copy the files
Save the Disk space using gzip
1. Compress the file using gzip command
Syntax: gzip filename
eg)gzip v file1.txt
compressed file is stored with an extention of .gz
2. Compress multiple files using gzip command
Syntax: gzip filename1 filename2 filename3
eg)gzip file1.txt file2.txt file3.txt
compressed multiple files and is stored with an extention of .gz
3. Compress multiple files with same extension using gzip command
Syntax: gzip filename1.extension
eg)gzip *.txt
compressed multiple files and is stored with an extention of .gz
4. To read Compressed file use zcat command
Syntax: zcat filename.txt.gz
eg)gzip file1.txt.gz
compressed file is stored with an extention of .gz
5. To uncompress the file use gunzip command
Syntax : gunzip filename
gunzip file1.pcx.gz

6. To compress everyfile in a directory.


Syntax: gzip –r directorypath
eg) gzip –rv /home/rusty/corresp

7. To uncompress every file in a directory


Syntax: gunzip –r directorypath
eg) gunzip –r /home/rusty/corresp
Archiving your home directory
1.Use tar command to archive files in to floppy disk
Syntax: tar cvfm /dev/fd0 /home/username

2. To restore the archive to your home directory


tar xvfm /dev/fd0

•-c − This creates an archive file.


•-x − The option extracts the archive file.
•-f − Specifies the filename of the archive file.
•-v − This prints verbose information for any tar operation.
•-t − This lists all the files inside an archive file.
•-u − This archives a file and then adds it to an existing archive file.
•-r − This updates a file or directory located inside a .tar file
•-z − Creates a tar file using gzip compression
•-j − Create an archive file using the bzip2 compression
•-W − The -w option verifies an archive file.
Introduction to Daemons:
•Daemons are background processes that operate
without direct user interaction.
•They perform various system tasks or provide services
continuously.
•Examples include printing daemons, network
daemons, and system monitoring daemons.
•Daemons typically start when the system boots and
run until the system shuts down.
•They play a crucial role in the background operation of
an operating system.
•Daemons often have names ending in "d".
What is the lpd Daemon?
•The lpd daemon stands for Line Printer Daemon.
•It is a core component of the printing subsystem in
Linux-like operating systems.
•lpd manages print queues and spools print jobs for
efficient printing.
•It ensures that print jobs are processed in the order
they were received.
•lpd communicates with printers to send print jobs and
manage printing resources.
•It is essential for network printing, allowing printing to
remote printers.
Print Spooling:
•lpd queues print jobs until the printer is ready to
process them.
•This allows users to submit multiple print jobs
without waiting for each to finish.
•Print spooling ensures that print jobs are processed in
the order they were received.
•It prevents printing bottlenecks by allowing the
printer to handle jobs at its own pace.
•Print spooling improves system performance by
decoupling printing from user processes.
•Users can monitor the status of their print jobs in the
print queue.
Printer Communication:
•lpd communicates with printers to send print jobs
for processing.
•It handles the details of printer communication,
such as data transmission and printer commands.
•lpd ensures that print jobs are formatted correctly
for the printer's capabilities.
•It manages printer resources, such as paper trays
and toner levels.
•lpd monitors printer status to detect errors or issues
during printing.
•It coordinates with the printer to ensure that print
jobs are completed successfully.
Error Handling:
•lpd monitors the status of printers and detects
printing errors.
•It logs errors, such as paper jams or communication
failures, for troubleshooting.
•Users and administrators are notified of printing
errors so they can take action.
•lpd may attempt to retry printing failed jobs after
resolving the underlying issue.
•Error handling ensures that printing problems are
identified and addressed promptly.
•It helps maintain the reliability and availability of
printing services.
Configuration Management:
•Administrators can configure lpd to control various
aspects of printing.
•This includes printer access permissions, print job
priorities, and printer-specific settings.
•Configuration management allows for customization
of printing services to meet specific requirements.
•Administrators can monitor printing activity and
performance using configuration settings.
•lpd provides centralized management of printing
resources for ease of administration.
The spool directory
1.Submitting a print job: When you send a file to be printed, the print command or
application places it in the spool directory.
2.Queuing: The print spooler organizes print jobs in the spool directory in the order
they were received. This ensures that print jobs are processed in a fair and orderly
manner.
3.Processing: When the printer is ready, it retrieves print jobs from the spool directory
and begins printing them. The print spooler manages this process, ensuring that the
printer receives the correct data and that multiple print jobs don't interfere with each
other.
4.Status tracking: The spool directory also stores information about the status of each
print job, such as whether it's waiting to be printed, currently printing, or completed.
This allows users to monitor the progress of their print jobs and helps administrators
troubleshoot any printing issues.
5.Error handling: If a print job encounters an error during processing, such as a paper
jam or communication problem with the printer, the print spooler will typically move
the job to a special error directory within the spool directory. This allows
administrators to easily identify and resolve printing problems without disrupting
other print jobs.
Overall, the spool directory plays a central role in the printing process in Linux by
acting as a temporary storage location for print jobs, managing their processing and
status, and facilitating error handling and troubleshooting.

You might also like