Kuk Linux 2023
Q6(a) :- Write the commands of vi-editor for deleting character and word, copy single lines and three lines, paste, cursor navigation and save.
The vi Editor:
The vi editor is a powerful and widely-used text editor available on most Unix-like operating systems, including Linux. It is a modal editor, meaning it operates in different modes, each designed for specific types of tasks such as text entry, command execution, and text manipulation. The vi editor is known for its efficiency and is often preferred by experienced programmers and system administrators.
History
- Origins: The
vieditor was originally created by Bill Joy in 1976 for the Unix operating system. It was derived from an earlier editor callededand its visual mode extensionex. - Vim: An enhanced version of
vicalled Vim (Vi IMproved) was released by Bram Moolenaar in 1991. Vim includes many additional features such as syntax highlighting, extensive plugin support, and better configuration options, while maintaining compatibility withvi.
vi.Deleting Characters and Words
- Delete a single character:
x: Deletes the character under the cursor.
- Delete a single word:
dw: Deletes from the cursor position to the end of the word.
Copying Lines
- Copy a single line:
yyorY: Yanks (copies) the current line.
- Copy three lines:
3yy: Yanks (copies) three lines starting from the current line.
Pasting
- Paste the copied text:
p: Pastes the copied text after the cursor position.P: Pastes the copied text before the cursor position.
Cursor Navigation
- Move left:
h: Moves the cursor one character to the left.
- Move right:
l: Moves the cursor one character to the right.
- Move up:
k: Moves the cursor one line up.
- Move down:
j: Moves the cursor one line down.
- Move to the beginning of the line:
0: Moves the cursor to the beginning of the current line.
- Move to the end of the line:
$: Moves the cursor to the end of the current line.
- Move to the beginning of the file:
gg: Moves the cursor to the beginning of the file.
- Move to the end of the file:
G: Moves the cursor to the end of the file.
- Move to a specific line number:
:n: Moves the cursor to line numbern.
Saving
- Save the file:
:w: Writes (saves) the file.
- Save and exit:
:wqorZZ: Writes (saves) the file and exitsvi.
- Exit without saving:
:q!: Exitsviwithout saving changes.
Q6(b) :- Create makefile to execute and delete atleast two .c files.
du and df Commands in Linux
The du (disk usage) and df (disk free) commands are used to display disk usage statistics in Unix-like operating systems. Here’s a detailed explanation of each command, their formats, and usage with examples.du Command
The du command summarizes disk usage of each file and directory recursively. It provides an estimate of the file space usage.
- Provides detailed information on disk space used by files and directories.
- Can display results in a summarized or detailed format.
- Allows control over depth of directory traversal.
Basic Format
du [options] [file|directory]
Common Options and Their Uses
-h: Human-readable format (e.g., 1K, 234M, 2G)
This command displays the disk usage of the specified directory in a human-readable format.
2. -s: Summarize, display only the total for each argument
This command provides a summary of the total disk usage of the specified directory.
3. -a: Display disk usage for all files, not just directories
du -a /path/to/directory
This command displays the disk usage for all files and directories recursively.
4. --max-depth=N: Limit the output to directories up to a specified depth
du –mx-depth=1 /path/to/directory
This command displays the disk usage of the directory and its immediate subdirectories.
Examples
Display Disk Usage in Human-Readable Format:
du -h /home/user
This command displays the disk usage of the
/home/userdirectory in a human-readable format.2. Summarize Disk Usage:
/var/log directory.
df Command
The df command displays the amount of disk space available on the file system containing each file name argument.
- Offers a quick overview of disk space availability on file systems.
- Can display file system types and inode information.
- Allows filtering by file system type.
Basic Format
Common Options and Their Uses
-h: Human-readable format (e.g., 1K, 234M, 2G)
This command displays the disk space usage in a human-readable format for all mounted file systems.
2. -T: Print file system type
This command displays the disk space usage along with the file system type.
3. -i: Inodes information
This command shows the number of inodes used and available on each file system.
4. -t: Limit listing to file systems of a specified type
This command displays the disk space usage for file systems of type ext4 only.
Examples
Display Disk Space Along with File System Type:
This command displays the disk space usage along with the file system type in a human-readable format.
