Unit V
Unit V
Managing Files and Directories : Create and edit text files, Search for files,
Perform operations on files and directories, Process text files, Manipulate file
output
Managing Kernel Modules : Explore the linux kernel, Install and configure kernel
modules, Monitor kernel modules,
Managing the Linux Boot Process : Configure linux boot components, Configure GRUB2
Create and Edit Text Files
• TEXT EDITORS: A text editor is an application that enables you
to view, create, or modify the contents of text files.
• Vim
• Nano
vim
• There will also be times when you don't know the exact location
of files created by the system, applications, or other users.
THE locate COMMAND
• The locate command performs a quick search for any
specified string in file names and paths stored in the mlocate
database.
• If locate command is not working, then needs to update the db used
by locate command.
• sudo updatedb
locate COMMAND OPTIONS
THE find COMMAND
• The find command enables you to search a specific location
for files and directories that adhere to some search criteria.
• These commands are useful when you only need to see the beginning
or the end of a file.
head
• displays the first 10 lines
tail
• displays the last 10 lines
THE cp COMMAND
• The cp command enables you to copy and then paste a file or
directory.
• The initial object is left where it is, but an exact duplicate of that
object is created at the destination you specify.
• When you copy directories, you must specify the -R option to
copy the specified directory recursively.
THE mv COMMAND
• The mv command moves files and directories to other
locations.
• The rmdir directory is used to remove directories, but only those that
are empty (i.e., contain no files or subdirectories).
• In order to delete a with actual contents, you must use the rm -R
command.
Process Text Files
• THE echo COMMAND
The echo command is used to display a line of text on the
terminal.
• You can also use the echo command to write text to a file by
providing the string after the echo command and redirecting to
the file.
• The echo command can overwrite the content in the file by
redirecting and not appending.
• You can supply various format characters within the text you
want to output, using a backslash (\) to indicate when they are
being used.
THE tr COMMAND
• The tr command is used to translate a string of characters.
• 1c1 means that line 1 in the first file needs to be changed to match line
number 1 in the second file.
THE awk COMMAND
• The awk command performs pattern matching on files.
THE sed COMMAND
• The sed or stream editor command is a program that you can
use to modify text files according to various parameters. The
sed command can also be used for global search and replace
actions.
• Hard and symbolic links are a feature of the file system and are common in most file
systems supported by Linux. The ext2, ext3, ext4, and XFS file systems all support hard
and symbolic links.
• A hard link is a reference to another file; it enables the file's data to have more than
one name in different locations in the same file system. Applications treat a hard link
as a real file. If the original file is deleted after a hard link is created, all its contents will
still be available in the linked file. This is because the inode of a hard link is the same as
its target; in other words, it points to the same object on the file system. Hard links
cannot be created between two directories, nor can they be created between two files
in different file systems.
• A symbolic link is a reference to a file or directory that can span
multiple file systems.
If the original file or directory is deleted after a symbolic link is
created, then the original content is lost.
• This is because the inode of a symbolic link is different than its
target; in other words, it points to a different object on the file
system.
• A symbolic link is also known as a soft link.
• A link in UNIX is a pointer to a file.
• Like pointers in any programming languages, links in UNIX are pointers
pointing to a file or a directory.
• Creating links is a kind of shortcuts to access a file.
• Links allow more than one file name to refer to the same file,
elsewhere.
• There are two types of links :
1.Soft Link or Symbolic links
2.Hard Links
• These links behave differently when the source of the link (what is
being linked to) is moved or removed.
• Symbolic links are not updated (they merely contain a string which is the path
name of its target);
• hard links always refer to the source, even if moved or removed.
• For example, if we have a file a.txt.
• If we create a hard link to the file and then delete the file, we can still
access the file using hard link.
• But if we create a soft link of the file and then delete the file, we can’t
access the file through soft link and soft link becomes dangling.
Manipulate File Output
• TEXT STREAMS: A text stream is a sequence of one or more
lines of text that applications can leverage to read from or write
to a particular device or system component.
• Standard input, or stdin, is a text stream that acts as the source
for command input.
Standard input for the Linux command-line is usually generated
from the keyboard. In
the case of the GUI, the standard input can also come from the
mouse.
• Standard output, or stdout, is a text stream that acts as the
destination for command
output. By default, standard output from a Linux command is
directed to the CLI.
• REDIRECTION OPERATORS
There are several operators that are used to redirect input or
output.
PIPING
• Piping is the process of combining the standard I/O streams of
commands. It uses the
standard output of one command as the standard input for
another command. The
output format of the first command should be compatible with
the format that the
second command works with. The pipe operator (|) can be
used with most commands
in Linux.
Display the top 5 files/directories according to their size
in the current working directory
THE xargs COMMAND (extended
arguments)
• The xargs command reads from standard input and executes
a command for each
argument provided.
• System Call
Interface (SCI): Handles system calls sent from user
applications to the kernel.
• Process
management: Handles different processes by allocating
separate execution
space on the processor and ensuring that the running of one
process does not interfere with other processes.
Memory Management
• Manages the computer's memory, which is one of the complex
tasks performed by the kernel. Like processor sharing, the
system's memory also needs to be shared among different user
space resources.
The kernel maps or allocates the available memory to
applications or programs on request and frees the memory
automatically when the execution of the programs is complete,
so that it can be allocated to other programs.
• File system
management:
Manages the filesystem, which involves storing, organizing, and
tracking files and data on a computer.
• Device
management: Manages devices by controlling device access
and interfacing
between user applications and hardware devices of the
computer.
Install and Configure Kernel Modules
• A kernel module is a system-level object that extends the functionality of the kernel.
It
can be dynamically loaded into the kernel or unloaded from the kernel when required.
It enables the kernel to update or recompile itself without requiring the system to
reboot.
• In this, you'll verify that the modules you installed were actually
loaded into the kernel, and that any configurations you made
were implemented properly.
THE /proc/ DIRECTORY
• The /proc/ directory is a virtual file system (VFS) that
provides significant information about the kernel's running
process.
THE /proc/version FILE
• The /proc/version file specifies several points of
information about the Linux kernel:
10. The user enters a user name and password to log in to the system.
• 11. The system authenticates the user. If the user is valid, then various profile files are
executed.
•
12. The shell is started and the system is ready for the user to work on.
KERNEL PANIC
Kernel panic is a mechanism by which the system detects there
has been a fatal error and responds to it. A fatal error typically
results in the system becoming unstable or
totally unusable. Software that handles kernel panics will display
an error message to the user and dump the current state of
kernel memory to a storage device for later debugging.
Depending on how the system is configured, the panic handler
will either reboot the system automatically, or wait for the user to
do so.
Configure GRUB 2
• GNU GRUB:
The GNU GRand Unified Bootloader (GNU GRUB) is a boot
loader developed by the
GNU Project that became popular on Unix-like systems. It
enables users to choose
which operating system or kernel version to boot in a multi-
platform environment.
GRUB 2 IMPROVEMENTS
• GRUB 2 is more than simply a newer version of GRUB; it is a
complete redesign and
rewrite of the GRUB system. GRUB 2 offers administrators
more control over the boot
process, boot devices, and boot behavior.
GRUB 2 INSTALLATION
• The grub2-install command is used to install the GRUB 2
boot loader on a
storage device. It copies GRUB 2 files into the /boot/grub2
directory and, on some
platforms, installs GRUB 2 into the boot sector. However,
grub2-install applies
to BIOS systems, not UEFI. To install GRUB 2 on a UEFI
system, use a package manager
to install the grub2-efi package. Installing this package will
copy GRUB 2 files onto
the EFI system partition (ESP) in the /boot/efi directory.
THE grub.cfg FILE
• The grub.cfg file is the main configuration file for the GRUB
2 boot loader. On BIOS
systems, it is located in the /boot/grub2/ directory. On UEFI
systems, it is located
in the /boot/efi/EFI/<distro>/ directory.
THE /etc/grub.d/ DIRECTORY
• The /etc/grub.d/ directory contains scripts that are used to
build the main
grub.cfg file.
THE /etc/default/grub FILE
• The /etc/default/grub file contains GRUB 2 display menu
settings that are
read by the /etc/grub.d/ scripts and built into the
grub.cfg file. It enables you to change options such as how
many seconds GRUB 2 will wait before
automatically selecting the default boot option.
THE grub2-mkconfig COMMAND
• The grub2-mkconfig command generates a new grub.cfg
configuration file,
and is used to update an existing grub.cfg file.
•ADDITIONAL READING IS
STRONGLY RECOMMENDED